diff --git a/android/capacitor/src/main/java/com/getcapacitor/ProcessedRoute.java b/android/capacitor/src/main/java/com/getcapacitor/ProcessedRoute.java new file mode 100644 index 0000000000..cf28e009c7 --- /dev/null +++ b/android/capacitor/src/main/java/com/getcapacitor/ProcessedRoute.java @@ -0,0 +1,28 @@ +package com.getcapacitor; + +/** + * An data class used in conjunction with RouteProcessor. + * + * @see com.getcapacitor.RouteProcessor + */ +public class ProcessedRoute { + + private String path; + private boolean isAsset; + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + public boolean isAsset() { + return isAsset; + } + + public void setAsset(boolean asset) { + isAsset = asset; + } +} diff --git a/android/capacitor/src/main/java/com/getcapacitor/RouteProcessor.java b/android/capacitor/src/main/java/com/getcapacitor/RouteProcessor.java index 077c20c6a7..670c8bc6bd 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/RouteProcessor.java +++ b/android/capacitor/src/main/java/com/getcapacitor/RouteProcessor.java @@ -4,5 +4,5 @@ * An interface used in the processing of routes */ public interface RouteProcessor { - String process(String path); + ProcessedRoute process(String basePath, String path); } diff --git a/android/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java b/android/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java index 36ddb6bb37..fb363bcafa 100755 --- a/android/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java +++ b/android/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java @@ -256,7 +256,9 @@ private WebResourceResponse handleLocalRequest(WebResourceRequest request, PathH try { String startPath = this.basePath + "/index.html"; if (bridge.getRouteProcessor() != null) { - startPath = this.basePath + bridge.getRouteProcessor().process("/index.html"); + ProcessedRoute processedRoute = bridge.getRouteProcessor().process(this.basePath, "/index.html"); + startPath = processedRoute.getPath(); + isAsset = processedRoute.isAsset(); } if (isAsset) { @@ -474,16 +476,21 @@ public InputStream handle(Uri url) { // Pass path to routeProcessor if present RouteProcessor routeProcessor = bridge.getRouteProcessor(); if (routeProcessor != null) { - path = bridge.getRouteProcessor().process(path); + ProcessedRoute processedRoute = bridge.getRouteProcessor().process("", path); + path = processedRoute.getPath(); + isAsset = processedRoute.isAsset(); } try { if (path.startsWith(capacitorContentStart)) { stream = protocolHandler.openContentUrl(url); - } else if (path.startsWith(capacitorFileStart) || !isAsset) { - if (!path.startsWith(capacitorFileStart)) { + } else if (path.startsWith(capacitorFileStart)) { + stream = protocolHandler.openFile(path); + } else if (!isAsset) { + if (routeProcessor == null) { path = basePath + url.getPath(); } + stream = protocolHandler.openFile(path); } else { stream = protocolHandler.openAsset(assetPath + path); diff --git a/cli/src/declarations.ts b/cli/src/declarations.ts index 0c12bbb761..9d79b2c317 100644 --- a/cli/src/declarations.ts +++ b/cli/src/declarations.ts @@ -485,9 +485,18 @@ export interface CapacitorConfig { export interface Portal { name: string; webDir: string; - appId?: string; + liveUpdateConfig?: LiveUpdateConfig; +} + +export interface LiveUpdateConfig { + appId: string; + channel: string; + autoUpdateMethod: AutoUpdateMethod; + maxVersions?: number; } +export type AutoUpdateMethod = 'none' | 'background'; + export interface PluginsConfig { /** * Plugin configuration by class name.