Skip to content

Commit

Permalink
fix some url handling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
hugeBlack committed Aug 20, 2024
1 parent 91529ad commit ef77c1a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
4 changes: 2 additions & 2 deletions LiveContainerUI/LCAppListViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,9 @@ - (void) openWebViewByURLString:(NSString*) urlString {
}

// use https for http and empty scheme
if([url.scheme length ] == 0 || [url.scheme isEqualToString:@"http"]) {
if([url.scheme length ] == 0) {
url.scheme = @"https";
} else if (![url.scheme isEqualToString: @"https"]){
} else if (![url.scheme isEqualToString: @"https"] && ![url.scheme isEqualToString: @"http"]){
[self launchAppByScheme:url apps:apps];
}
LCWebView *webViewController = [[LCWebView alloc] initWithURL:url.URL apps:apps];
Expand Down
40 changes: 29 additions & 11 deletions TweakLoader/UIKit+GuestHooks.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ - (void)hook__applicationOpenURLAction:(id)action payload:(NSDictionary *)payloa
// Ignore
return;
} else if ([url hasPrefix:@"livecontainer://open-web-page?"]) {
LCOpenWebPage(url);
// launch to UI and open web page
NSURLComponents* lcUrl = [NSURLComponents componentsWithString:url];
NSString* realUrlEncoded = lcUrl.queryItems[0].value;
if(!realUrlEncoded) return;
// Convert the base64 encoded url into String
NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:realUrlEncoded options:0];
NSString *decodedUrl = [[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding];
LCOpenWebPage(decodedUrl);
return;
} else if ([url hasPrefix:@"livecontainer://open-url"]) {
// pass url to guest app
NSURLComponents* lcUrl = [NSURLComponents componentsWithString:url];
Expand All @@ -79,13 +87,16 @@ - (void)hook__applicationOpenURLAction:(id)action payload:(NSDictionary *)payloa
newPayload[UIApplicationLaunchOptionsURLKey] = decodedUrl;
[self hook__applicationOpenURLAction:action payload:newPayload origin:origin];
return;
} else if (![url hasPrefix:@"livecontainer://livecontainer-launch?"]) {
// Not what we're looking for, pass it
[self hook__applicationOpenURLAction:action payload:payload origin:origin];
} else if ([url hasPrefix:@"livecontainer://livecontainer-launch?"]) {
if (![url hasSuffix:NSBundle.mainBundle.bundlePath.lastPathComponent]) {
LCShowSwitchAppConfirmation([NSURL URLWithString:url]);
}
return;
} else if (![url hasSuffix:NSBundle.mainBundle.bundlePath.lastPathComponent]) {
LCShowSwitchAppConfirmation([NSURL URLWithString:url]);
// Not what we're looking for, pass it

}
[self hook__applicationOpenURLAction:action payload:payload origin:origin];
return;
}
@end

Expand All @@ -109,16 +120,18 @@ - (void)hook_scene:(id)scene didReceiveActions:(NSSet *)actions fromTransitionCo
NSString *url = urlAction.url.absoluteString;
if ([url hasPrefix:@"livecontainer://livecontainer-relaunch"]) {
// Ignore
return;
} else if ([url hasPrefix:@"livecontainer://open-web-page?"]) {
NSURLComponents* lcUrl = [NSURLComponents componentsWithString:url];
NSString* realUrlEncoded = lcUrl.queryItems[0].value;
if(!realUrlEncoded) return;
// Convert the base64 encoded url into String
// launch to UI and open web page
NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:realUrlEncoded options:0];
NSString *decodedUrl = [[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding];
LCOpenWebPage(decodedUrl);
} else if (![url hasPrefix:@"livecontainer://livecontainer-launch?"]) {
// Not what we're looking for, pass it
return;
} else if ([url hasPrefix:@"livecontainer://open-url?"]) {
// Open guest app's URL scheme
NSURLComponents* lcUrl = [NSURLComponents componentsWithString:url];
NSString* realUrlEncoded = lcUrl.queryItems[0].value;
if(!realUrlEncoded) return;
Expand All @@ -132,8 +145,13 @@ - (void)hook_scene:(id)scene didReceiveActions:(NSSet *)actions fromTransitionCo
[newActions addObject:newUrlAction];
[self hook_scene:scene didReceiveActions:newActions fromTransitionContext:context];
return;
} else if (![url hasSuffix:NSBundle.mainBundle.bundlePath.lastPathComponent]) {
LCShowSwitchAppConfirmation(urlAction.url);
} else if ([url hasPrefix:@"livecontainer://livecontainer-launch?"]){
// If it's not current app, then switch
if (![url hasSuffix:NSBundle.mainBundle.bundlePath.lastPathComponent]) {
LCShowSwitchAppConfirmation(urlAction.url);
}
return;

}

NSMutableSet *newActions = actions.mutableCopy;
Expand Down

0 comments on commit ef77c1a

Please sign in to comment.