Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit aa20924

Browse files
authored
Add logic for loading different application path (#608)
1 parent 7573fad commit aa20924

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

src/android/CodePush.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ private void navigateToLocalDeploymentIfExists() {
420420
CodePushPackageMetadata deployedPackageMetadata = this.codePushPackageManager.getCurrentPackageMetadata();
421421
if (deployedPackageMetadata != null && deployedPackageMetadata.localPath != null) {
422422
File startPage = this.getStartPageForPackage(deployedPackageMetadata.localPath);
423-
if (startPage != null) {
423+
if (startPage != null && this.isMainBundleActivity()) {
424424
/* file exists */
425425
try {
426426
navigateToFile(startPage);
@@ -431,6 +431,12 @@ private void navigateToLocalDeploymentIfExists() {
431431
}
432432
}
433433

434+
private boolean isMainBundleActivity() {
435+
final String activityPackage = this.cordova.getActivity().getClass().getPackage().getName();
436+
final String contextPackage = this.cordova.getContext().getPackageName();
437+
return contextPackage.contains(activityPackage);
438+
}
439+
434440
private boolean execPreInstall(CordovaArgs args, CallbackContext callbackContext) {
435441
/* check if package is valid */
436442
try {

src/ios/CDVWKWebViewEngine+CodePush.m

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#if defined(__has_include)
22
#if __has_include("CDVWKWebViewEngine.h")
33

4+
#import <Cordova/NSDictionary+CordovaPreferences.h>
45
#import "CDVWKWebViewEngine.h"
56
#import "CodePush.h"
67

@@ -16,6 +17,11 @@ - (id)loadRequest:(NSURLRequest *)request {
1617
lastLoadedURL = request.URL.absoluteString;
1718
NSURL *readAccessURL;
1819

20+
NSURL* bundleURL = [[NSBundle mainBundle] bundleURL];
21+
if (![lastLoadedURL containsString:bundleURL.path] && ![lastLoadedURL containsString:IdentifierCodePushPath]) {
22+
return [self loadPluginRequest:request];
23+
}
24+
1925
if (request.URL.isFileURL) {
2026
// All file URL requests should be handled with the setServerBasePath in case if it is Ionic app.
2127
if ([CodePush hasIonicWebViewEngine: self]) {
@@ -47,6 +53,36 @@ - (id)loadRequest:(NSURLRequest *)request {
4753
}
4854
}
4955

56+
- (id)loadPluginRequest:(NSURLRequest *)request {
57+
if (request.URL.fileURL) {
58+
NSDictionary* settings = self.commandDelegate.settings;
59+
NSString *bind = [settings cordovaSettingForKey:@"Hostname"];
60+
if(bind == nil){
61+
bind = @"localhost";
62+
}
63+
NSString *scheme = [settings cordovaSettingForKey:@"iosScheme"];
64+
if(scheme == nil || [scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https"] || [scheme isEqualToString:@"file"]){
65+
scheme = @"ionic";
66+
}
67+
NSString *CDV_LOCAL_SERVER = [NSString stringWithFormat:@"%@://%@", scheme, bind];
68+
69+
NSURL* startURL = [NSURL URLWithString:((CDVViewController *)self.viewController).startPage];
70+
NSString* startFilePath = [self.commandDelegate pathForResource:[startURL path]];
71+
NSURL *url = [[NSURL URLWithString:CDV_LOCAL_SERVER] URLByAppendingPathComponent:request.URL.path];
72+
if ([request.URL.path isEqualToString:startFilePath]) {
73+
url = [NSURL URLWithString:CDV_LOCAL_SERVER];
74+
}
75+
if(request.URL.query) {
76+
url = [NSURL URLWithString:[@"?" stringByAppendingString:request.URL.query] relativeToURL:url];
77+
}
78+
if(request.URL.fragment) {
79+
url = [NSURL URLWithString:[@"#" stringByAppendingString:request.URL.fragment] relativeToURL:url];
80+
}
81+
request = [NSURLRequest requestWithURL:url];
82+
}
83+
return [(WKWebView*)self.engineWebView loadRequest:request];
84+
}
85+
5086
#pragma clang diagnostic pop
5187

5288
// Fix bug related to unable WKWebView recovery after reinit with loaded codepush update

src/ios/CodePush.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,11 @@ - (void)clearDeploymentsIfBinaryUpdated {
341341
- (void)navigateToLocalDeploymentIfExists {
342342
CodePushPackageMetadata* deployedPackageMetadata = [CodePushPackageManager getCurrentPackageMetadata];
343343
if (deployedPackageMetadata && deployedPackageMetadata.localPath) {
344+
NSString* startPage = ((CDVViewController *)self.viewController).startPage;
345+
NSURL* URL = [self getStartPageURLForLocalPackage:deployedPackageMetadata.localPath];
346+
if (![URL.path containsString:startPage]) {
347+
return;
348+
}
344349
[self redirectStartPageToURL: deployedPackageMetadata.localPath];
345350
}
346351
}

0 commit comments

Comments
 (0)