Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): update support for Portals for Capacitor to include Live Updates #5660

Merged
merged 6 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 10 additions & 1 deletion cli/src/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down