From 8dc50d755596a1b608cd5fcb7c7cec654b12891f Mon Sep 17 00:00:00 2001 From: Dhinak G <17605561+dhinakg@users.noreply.github.com> Date: Fri, 22 Dec 2023 00:08:23 -0500 Subject: [PATCH] Add reboot code --- TrollStore/TSApplicationsManager.m | 2 +- TrollStore/TSInstallationController.m | 1 + TrollStore/TSSettingsListController.h | 1 + TrollStore/TSSettingsListController.m | 60 +++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/TrollStore/TSApplicationsManager.m b/TrollStore/TSApplicationsManager.m index 5f504fc..5ce2010 100644 --- a/TrollStore/TSApplicationsManager.m +++ b/TrollStore/TSApplicationsManager.m @@ -75,7 +75,7 @@ extern NSUserDefaults* trollStoreUserDefaults(); errorDescription = @"The app you tried to install has the same identifier as a system app already installed on the device. The installation has been prevented to protect you from possible bootloops or other issues."; break; case 180: - errorDescription = @"The app was installed successfully, but requires developer mode to be enabled to run."; + errorDescription = @"The app was installed successfully, but requires developer mode to be enabled to run. After rebooting, select \"Turn On\" to enable developer mode."; break; case 181: errorDescription = @"Failed to enable developer mode."; diff --git a/TrollStore/TSInstallationController.m b/TrollStore/TSInstallationController.m index 5b2ad21..fef966b 100644 --- a/TrollStore/TSInstallationController.m +++ b/TrollStore/TSInstallationController.m @@ -63,6 +63,7 @@ extern NSUserDefaults* trollStoreUserDefaults(void); UIAlertAction* rebootAction = [UIAlertAction actionWithTitle:@"Reboot Now" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action) { if(completionBlock) completionBlock(YES, nil); + spawnRoot(rootHelperPath(), @[@"reboot"], nil, nil); }]; [rebootNotification addAction:rebootAction]; diff --git a/TrollStore/TSSettingsListController.h b/TrollStore/TSSettingsListController.h index fc573ee..9cc397e 100644 --- a/TrollStore/TSSettingsListController.h +++ b/TrollStore/TSSettingsListController.h @@ -5,5 +5,6 @@ PSSpecifier* _installPersistenceHelperSpecifier; NSString* _newerVersion; NSString* _newerLdidVersion; + BOOL _devModeEnabled; } @end \ No newline at end of file diff --git a/TrollStore/TSSettingsListController.m b/TrollStore/TSSettingsListController.m index 6a97299..6e46dd7 100644 --- a/TrollStore/TSSettingsListController.m +++ b/TrollStore/TSSettingsListController.m @@ -55,6 +55,15 @@ extern NSUserDefaults* trollStoreUserDefaults(void); } }); //} + + if (@available(iOS 16, *)) + { + _devModeEnabled = spawnRoot(rootHelperPath(), @[@"check-dev-mode"], nil, nil) == 0; + } + else + { + _devModeEnabled = YES; + } } - (NSMutableArray*)specifiers @@ -82,6 +91,26 @@ extern NSUserDefaults* trollStoreUserDefaults(void); [_specifiers addObject:updateTrollStoreSpecifier]; } + if(!_devModeEnabled) + { + PSSpecifier* enableDevModeGroupSpecifier = [PSSpecifier emptyGroupSpecifier]; + enableDevModeGroupSpecifier.name = @"Developer Mode"; + [enableDevModeGroupSpecifier setProperty:@"Some apps require developer mode enabled to launch. This requires a reboot to take effect." forKey:@"footerText"]; + [_specifiers addObject:enableDevModeGroupSpecifier]; + + PSSpecifier* enableDevModeSpecifier = [PSSpecifier preferenceSpecifierNamed:@"Enable Developer Mode" + target:self + set:nil + get:nil + detail:nil + cell:PSButtonCell + edit:nil]; + enableDevModeSpecifier.identifier = @"enableDevMode"; + [enableDevModeSpecifier setProperty:@YES forKey:@"enabled"]; + enableDevModeSpecifier.buttonAction = @selector(enableDevModePressed); + [_specifiers addObject:enableDevModeSpecifier]; + } + PSSpecifier* utilitiesGroupSpecifier = [PSSpecifier emptyGroupSpecifier]; utilitiesGroupSpecifier.name = @"Utilities"; [utilitiesGroupSpecifier setProperty:@"If an app does not immediately appear after installation, respring here and it should appear afterwards." forKey:@"footerText"]; @@ -369,6 +398,37 @@ extern NSUserDefaults* trollStoreUserDefaults(void); [TSInstallationController installLdid]; } +- (void)enableDevModePressed +{ + int ret = spawnRoot(rootHelperPath(), @[@"arm-dev-mode"], nil, nil); + + if (ret == 0) { + UIAlertController* rebootNotification = [UIAlertController alertControllerWithTitle:@"Reboot Required" + message:@"After rebooting, select \"Turn On\" to enable developer mode." + preferredStyle:UIAlertControllerStyleAlert + ]; + UIAlertAction* closeAction = [UIAlertAction actionWithTitle:@"Close" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action) + { + [self reloadSpecifiers]; + }]; + [rebootNotification addAction:closeAction]; + + UIAlertAction* rebootAction = [UIAlertAction actionWithTitle:@"Reboot Now" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action) + { + spawnRoot(rootHelperPath(), @[@"reboot"], nil, nil); + }]; + [rebootNotification addAction:rebootAction]; + + [TSPresentationDelegate presentViewController:rebootNotification animated:YES completion:nil]; + } else { + UIAlertController* errorAlert = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Error %d", ret] message:@"Failed to enable developer mode." preferredStyle:UIAlertControllerStyleAlert]; + UIAlertAction* closeAction = [UIAlertAction actionWithTitle:@"Close" style:UIAlertActionStyleDefault handler:nil]; + [errorAlert addAction:closeAction]; + + [TSPresentationDelegate presentViewController:errorAlert animated:YES completion:nil]; + } +} + - (void)installPersistenceHelperPressed { NSMutableArray* appCandidates = [NSMutableArray new];