Skip to content

Commit

Permalink
Fix TweakLoader injecting all root subfolders (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduytran0 committed Aug 11, 2024
1 parent 30c9fd8 commit 206ebf1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
31 changes: 18 additions & 13 deletions TweakLoader/TweakLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@
}

static void showDlerrAlert(NSString *error) {
UIWindow *window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Failed to load tweaks" message:error preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
window.windowScene = nil;
}];
[alert addAction:okAction];
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Copy" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
UIPasteboard.generalPasteboard.string = error;
window.windowScene = nil;
}];
[alert addAction:cancelAction];
UIWindow *window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
window.rootViewController = [UIViewController new];
window.windowLevel = 1000;
window.windowScene = (id)UIApplication.sharedApplication.connectedScenes.anyObject;
Expand Down Expand Up @@ -67,18 +70,20 @@ static void TweakLoaderConstructor() {
}

// Load selected tweak folder, recursively
NSLog(@"Loading tweaks from the selected folder");
NSString *tweakFolderName = NSBundle.mainBundle.infoDictionary[@"LCTweakFolder"];
NSString *tweakFolder = [globalTweakFolder stringByAppendingPathComponent:tweakFolderName];
NSURL *tweakFolderURL = [NSURL fileURLWithPath:tweakFolder];
NSDirectoryEnumerator *directoryEnumerator = [NSFileManager.defaultManager enumeratorAtURL:tweakFolderURL includingPropertiesForKeys:@[] options:0 errorHandler:^BOOL(NSURL *url, NSError *error) {
NSLog(@"Error while enumerating tweak directory: %@", error);
return YES;
}];
for (NSURL *fileURL in directoryEnumerator) {
NSString *error = loadTweakAtURL(fileURL);
if (error) {
[errors addObject:error];
if (tweakFolderName.length > 0) {
NSLog(@"Loading tweaks from the selected folder");
NSString *tweakFolder = [globalTweakFolder stringByAppendingPathComponent:tweakFolderName];
NSURL *tweakFolderURL = [NSURL fileURLWithPath:tweakFolder];
NSDirectoryEnumerator *directoryEnumerator = [NSFileManager.defaultManager enumeratorAtURL:tweakFolderURL includingPropertiesForKeys:@[] options:0 errorHandler:^BOOL(NSURL *url, NSError *error) {
NSLog(@"Error while enumerating tweak directory: %@", error);
return YES;
}];
for (NSURL *fileURL in directoryEnumerator) {
NSString *error = loadTweakAtURL(fileURL);
if (error) {
[errors addObject:error];
}
}
}

Expand Down
7 changes: 5 additions & 2 deletions TweakLoader/UIKit+GuestHooks.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ void LCShowSwitchAppConfirmation(NSURL *url) {
}

NSString *message = [NSString stringWithFormat:@"%@\nAre you sure you want to switch app? Doing so will terminate this app.", url];
UIWindow *window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"LiveContainer" message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
[NSClassFromString(@"LCSharedUtils") launchToGuestAppWithURL:url];
window.windowScene = nil;
}];
[alert addAction:okAction];
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
window.windowScene = nil;
}];
[alert addAction:cancelAction];
UIWindow *window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
window.rootViewController = [UIViewController new];
window.windowLevel = UIApplication.sharedApplication.windows.lastObject.windowLevel + 1;
window.windowScene = (id)UIApplication.sharedApplication.connectedScenes.anyObject;
Expand Down

0 comments on commit 206ebf1

Please sign in to comment.