From ef77c1ab8d673157018ad3bedf543100fa4ebb02 Mon Sep 17 00:00:00 2001 From: Huge_Black Date: Tue, 20 Aug 2024 21:02:39 +0800 Subject: [PATCH] fix some url handling logic --- LiveContainerUI/LCAppListViewController.m | 4 +-- TweakLoader/UIKit+GuestHooks.m | 40 ++++++++++++++++------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/LiveContainerUI/LCAppListViewController.m b/LiveContainerUI/LCAppListViewController.m index 7ae26b7..50131ff 100644 --- a/LiveContainerUI/LCAppListViewController.m +++ b/LiveContainerUI/LCAppListViewController.m @@ -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]; diff --git a/TweakLoader/UIKit+GuestHooks.m b/TweakLoader/UIKit+GuestHooks.m index 110ebb4..7fd1875 100644 --- a/TweakLoader/UIKit+GuestHooks.m +++ b/TweakLoader/UIKit+GuestHooks.m @@ -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]; @@ -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 @@ -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; @@ -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;