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

Conversation

carlpoole
Copy link
Member

@carlpoole carlpoole commented Jun 6, 2022

This update to the recently introduced Route Processor feature allows the interface to also specify whether the returned file is file or an asset. This is helpful when discerning whether a bundled asset in the apk or web assets on disk should be used, for example in Live Updates in the Portals for Capacitor use case. This is a breaking change with little-to-no impact currently due to the development state of Portals for Capacitor.

Example use:

private RouteProcessor implementRouteProcessor() {
    return (basePath, path) -> {
        ProcessedRoute processedRoute = new ProcessedRoute();
        String shellAppName = portalsConfig.getShellApp().getName();

        LiveUpdateConfig shellLiveUpdateConfig = portalsConfig.getShellApp().getLiveUpdateConfig();
        File shellLiveUpdatePath = null;
        if (shellLiveUpdateConfig != null) {
            String shellAppId = shellLiveUpdateConfig.getAppId();
            if (shellAppId != null) {
                shellLiveUpdatePath = LiveUpdateManager.getLatestAppDirectory(CapacitorPortalsBridgeActivity.this, shellAppId);
            }
        }

        String[] pathParts = path.split("/");
        if (pathParts.length == 0) {
            if (shellLiveUpdatePath != null) {
                processedRoute.setPath(shellLiveUpdatePath + path);
                processedRoute.setAsset(false);
            } else {
                processedRoute.setPath(basePath + "/" + shellAppName + path);
                processedRoute.setAsset(true);
            }
        } else {
            PortalApp route = portalsConfig.getApps().get(pathParts[1]);

            if (route == null) {
                if (shellLiveUpdatePath != null) {
                    processedRoute.setPath(shellLiveUpdatePath + path);
                    processedRoute.setAsset(false);
                } else {
                    processedRoute.setPath(basePath + "/" + shellAppName + path);
                    processedRoute.setAsset(true);
                }
            } else {
                LiveUpdateConfig appLiveUpdateConfig = route.getLiveUpdateConfig();
                File appLiveUpdatePath = null;
                if (appLiveUpdateConfig != null) {
                    String appId = appLiveUpdateConfig.getAppId();
                    if (appId != null) {
                        appLiveUpdatePath = LiveUpdateManager.getLatestAppDirectory(CapacitorPortalsBridgeActivity.this, appId);
                    }
                }

                if (appLiveUpdatePath != null) {
                    processedRoute.setPath(appLiveUpdatePath + "/" + joinString(Arrays.copyOfRange(pathParts, 2, pathParts.length)));
                    processedRoute.setAsset(false);
                } else {
                    processedRoute.setPath(basePath + "/" + route.getName() + "/" + joinString(Arrays.copyOfRange(pathParts, 2, pathParts.length)));
                    processedRoute.setAsset(true);
                }
            }
        }

        return processedRoute;
    };
}

@carlpoole carlpoole self-assigned this Jun 6, 2022
@carlpoole carlpoole marked this pull request as ready for review June 6, 2022 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants