Skip to content

Commit c4a8c00

Browse files
committed
Add recovery mode action
1 parent 2606640 commit c4a8c00

5 files changed

Lines changed: 54 additions & 2 deletions

File tree

app/AppDelegate.m

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
310310

311311
if (self.window != nil) {
312312
// For iOS <13, where the app delegate owns the window instead of the scene
313-
if ([NSUserDefaults.standardUserDefaults boolForKey:@"recovery"]) {
313+
UIApplicationShortcutItem *recoveryAction = [launchOptions valueForKey:UIApplicationLaunchOptionsShortcutItemKey]; // Came from Quick Action?
314+
if ([NSUserDefaults.standardUserDefaults boolForKey:@"recovery"] || [recoveryAction.type isEqualToString:@"recoveryQuickAction"]) {
314315
UINavigationController *vc = [[UIStoryboard storyboardWithName:@"About" bundle:nil] instantiateInitialViewController];
315316
AboutViewController *avc = (AboutViewController *) vc.topViewController;
316317
avc.recoveryMode = YES;
@@ -331,6 +332,15 @@ - (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<
331332
}
332333
}
333334

335+
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler { // Quick Action while running for iOS <13; AppDelegate owns the window
336+
if([shortcutItem.type isEqualToString:@"recoveryQuickAction"]) {
337+
UINavigationController *vc = [[UIStoryboard storyboardWithName:@"About" bundle:nil] instantiateInitialViewController];
338+
AboutViewController *avc = (AboutViewController *) vc.topViewController;
339+
avc.recoveryMode = YES;
340+
self.window.rootViewController = vc;
341+
}
342+
}
343+
334344
- (void)dealloc {
335345
if (self.reachability != NULL) {
336346
SCNetworkReachabilityUnscheduleFromRunLoop(self.reachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "sf_gearshape.svg",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
},
12+
"properties" : {
13+
"preserves-vector-representation" : true,
14+
"template-rendering-intent" : "template"
15+
}
16+
}
Lines changed: 1 addition & 0 deletions
Loading

app/Info.plist

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,21 @@
8282
<string>UIInterfaceOrientationLandscapeLeft</string>
8383
<string>UIInterfaceOrientationLandscapeRight</string>
8484
</array>
85+
<key>UIApplicationShortcutItems</key>
86+
<array>
87+
<dict>
88+
<key>UIApplicationShortcutItemIconFile</key>
89+
<string>Recover</string>
90+
<key>UIApplicationShortcutItemType</key>
91+
<string>recoveryQuickAction</string>
92+
<key>UIApplicationShortcutItemTitle</key>
93+
<string>Recovery Mode</string>
94+
<key>UIApplicationShortcutItemSubtitle</key>
95+
<string>Restart the app directly to settings</string>
96+
<key>UIApplicationShortcutItemIconSymbolName</key>
97+
<string>gearshape</string>
98+
</dict>
99+
</array>
85100
<key>fuc</key>
86101
<string>ICON_STUFF</string>
87102
</dict>

app/SceneDelegate.m

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ @interface SceneDelegate ()
2121
@implementation SceneDelegate
2222

2323
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
24-
if ([NSUserDefaults.standardUserDefaults boolForKey:@"recovery"]) {
24+
bool fromRecoveryAction = (connectionOptions.shortcutItem != NULL) ? [connectionOptions.shortcutItem.type isEqualToString:@"recoveryQuickAction"] : false; // Came from Quick Action?
25+
if ([NSUserDefaults.standardUserDefaults boolForKey:@"recovery"] || fromRecoveryAction) {
2526
UINavigationController *vc = [[UIStoryboard storyboardWithName:@"About" bundle:nil] instantiateInitialViewController];
2627
AboutViewController *avc = (AboutViewController *) vc.topViewController;
2728
avc.recoveryMode = YES;
@@ -65,4 +66,13 @@ - (void)sceneWillResignActive:(UIScene *)scene {
6566
}
6667
}
6768

69+
- (void)windowScene:(UIWindowScene *)windowScene performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler { // Quick Action while running for iOS >=13
70+
if([shortcutItem.type isEqualToString:@"recoveryQuickAction"]) {
71+
UINavigationController *vc = [[UIStoryboard storyboardWithName:@"About" bundle:nil] instantiateInitialViewController];
72+
AboutViewController *avc = (AboutViewController *) vc.topViewController;
73+
avc.recoveryMode = YES;
74+
self.window.rootViewController = vc;
75+
}
76+
}
77+
6878
@end

0 commit comments

Comments
 (0)