Skip to content

Commit

Permalink
Add a recovery mode to open settings if the app won't start
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed Jul 6, 2020
1 parent bee09ce commit e7d7f46
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 13 deletions.
1 change: 1 addition & 0 deletions app/AboutViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface AboutViewController : UITableViewController

@property BOOL includeDebugPanel;
@property BOOL recoveryMode;

@end

Expand Down
14 changes: 14 additions & 0 deletions app/AboutViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ - (void)awakeFromNib {
- (void)viewDidLoad {
[super viewDidLoad];
[self _updatePreferenceUI];
if (self.recoveryMode) {
self.includeDebugPanel = YES;
self.navigationItem.title = @"Recovery Mode";
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Exit"
style:UIBarButtonItemStyleDone
target:self
action:@selector(exitRecovery:)];
self.navigationItem.leftBarButtonItem = nil;
}
}

- (void)exitRecovery:(id)sender {
[NSUserDefaults.standardUserDefaults setBool:NO forKey:@"recovery"];
exit(0);
}

- (void)dealloc {
Expand Down
12 changes: 11 additions & 1 deletion app/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <arpa/inet.h>
#include <netdb.h>
#import <SystemConfiguration/SystemConfiguration.h>
#import "AboutViewController.h"
#import "AppDelegate.h"
#import "AppGroup.h"
#import "iOSFS.h"
Expand Down Expand Up @@ -208,7 +209,9 @@ - (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:
[defaults removeObjectForKey:kPreferenceLaunchCommandKey];
[defaults setBool:NO forKey:@"hail mary"];
}

if ([NSUserDefaults.standardUserDefaults boolForKey:@"recovery"])
return YES;

bootError = [self boot];
return YES;
}
Expand Down Expand Up @@ -243,6 +246,13 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

if (self.window != nil) {
// For iOS <13, where the app delegate owns the window instead of the scene
if ([NSUserDefaults.standardUserDefaults boolForKey:@"recovery"]) {
UINavigationController *vc = [[UIStoryboard storyboardWithName:@"About" bundle:nil] instantiateInitialViewController];
AboutViewController *avc = vc.topViewController;
avc.recoveryMode = YES;
self.window.rootViewController = vc;
return YES;
}
TerminalViewController *vc = (TerminalViewController *) self.window.rootViewController;
currentTerminalViewController = vc;
[vc startNewSession];
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions app/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
<key>UISceneDelegateClassName</key>
<string>SceneDelegate</string>
<key>UISceneConfigurationName</key>
<string>Terminal</string>
<string>Main App</string>
<key>UISceneStoryboardFile</key>
<string>Main</string>
<string>Terminal</string>
</dict>
</array>
</dict>
Expand All @@ -60,7 +60,7 @@
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<string>Terminal</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
Expand Down
9 changes: 9 additions & 0 deletions app/SceneDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

#import "SceneDelegate.h"
#import "AboutViewController.h"

TerminalViewController *currentTerminalViewController = NULL;

Expand All @@ -20,6 +21,14 @@ @interface SceneDelegate ()
@implementation SceneDelegate

- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
if ([NSUserDefaults.standardUserDefaults boolForKey:@"recovery"]) {
UINavigationController *vc = [[UIStoryboard storyboardWithName:@"About" bundle:nil] instantiateInitialViewController];
AboutViewController *avc = vc.topViewController;
avc.recoveryMode = YES;
self.window.rootViewController = vc;
return;
}

TerminalViewController *vc = (TerminalViewController *) self.window.rootViewController;
vc.sceneSession = session;
if (session.stateRestorationActivity == nil) {
Expand Down
6 changes: 3 additions & 3 deletions app/Settings.bundle/Root.plist
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
<key>Type</key>
<string>PSGroupSpecifier</string>
<key>FooterText</key>
<string>Danger zone: Only touch this if you know what you&apos;re doing but you messed up anyway</string>
<string>Opens the app straight to the settings menu. Useful if you changed anything there and need to change it back but the app won&apos;t start.</string>
</dict>
<dict>
<key>Type</key>
<string>PSToggleSwitchSpecifier</string>
<key>Title</key>
<string>Reset launch and boot commands</string>
<string>Recovery Mode</string>
<key>Key</key>
<string>hail mary</string>
<string>recovery</string>
<key>DefaultValue</key>
<false/>
</dict>
Expand Down
12 changes: 6 additions & 6 deletions iSH.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
BB78AB2B1FAD22440013E782 /* TerminalView.m in Sources */ = {isa = PBXBuildFile; fileRef = BB78AB2A1FAD22440013E782 /* TerminalView.m */; };
BB792B551F96D90D00FFB7A4 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = BB792B541F96D90D00FFB7A4 /* AppDelegate.m */; };
BB792B581F96D90D00FFB7A4 /* TerminalViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = BB792B571F96D90D00FFB7A4 /* TerminalViewController.m */; };
BB792B5B1F96D90D00FFB7A4 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BB792B591F96D90D00FFB7A4 /* Main.storyboard */; };
BB792B5B1F96D90D00FFB7A4 /* Terminal.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BB792B591F96D90D00FFB7A4 /* Terminal.storyboard */; };
BB792B5D1F96D90D00FFB7A4 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BB792B5C1F96D90D00FFB7A4 /* Assets.xcassets */; };
BB792B601F96D90D00FFB7A4 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BB792B5E1F96D90D00FFB7A4 /* LaunchScreen.storyboard */; };
BB792B631F96D90D00FFB7A4 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = BB792B621F96D90D00FFB7A4 /* main.m */; };
Expand Down Expand Up @@ -204,7 +204,7 @@
BB792B541F96D90D00FFB7A4 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
BB792B561F96D90D00FFB7A4 /* TerminalViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TerminalViewController.h; sourceTree = "<group>"; };
BB792B571F96D90D00FFB7A4 /* TerminalViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TerminalViewController.m; sourceTree = "<group>"; };
BB792B5A1F96D90D00FFB7A4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
BB792B5A1F96D90D00FFB7A4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Terminal.storyboard; sourceTree = "<group>"; };
BB792B5C1F96D90D00FFB7A4 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
BB792B5F1F96D90D00FFB7A4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
BB792B611F96D90D00FFB7A4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -501,7 +501,7 @@
BBCC9D952365430800424C83 /* SceneDelegate.m */,
BB792B561F96D90D00FFB7A4 /* TerminalViewController.h */,
BB792B571F96D90D00FFB7A4 /* TerminalViewController.m */,
BB792B591F96D90D00FFB7A4 /* Main.storyboard */,
BB792B591F96D90D00FFB7A4 /* Terminal.storyboard */,
BBFB557D21587B2B00DFE6DE /* Bar */,
BB78AB291FAD22440013E782 /* TerminalView.h */,
BB78AB2A1FAD22440013E782 /* TerminalView.m */,
Expand Down Expand Up @@ -976,7 +976,7 @@
BB792B601F96D90D00FFB7A4 /* LaunchScreen.storyboard in Resources */,
BBBF7B5C2415CDBB00EC4C14 /* Settings.bundle in Resources */,
BBBCE7E321D2F02200CA00B3 /* About.storyboard in Resources */,
BB792B5B1F96D90D00FFB7A4 /* Main.storyboard in Resources */,
BB792B5B1F96D90D00FFB7A4 /* Terminal.storyboard in Resources */,
BB2B4DAF231D998300CB578B /* term.html in Resources */,
BB10E5D0248DC21D009C7A74 /* Roots.storyboard in Resources */,
BBCE66E2249A807700F45269 /* alpine.tar.gz in Resources */,
Expand Down Expand Up @@ -1122,12 +1122,12 @@
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
BB792B591F96D90D00FFB7A4 /* Main.storyboard */ = {
BB792B591F96D90D00FFB7A4 /* Terminal.storyboard */ = {
isa = PBXVariantGroup;
children = (
BB792B5A1F96D90D00FFB7A4 /* Base */,
);
name = Main.storyboard;
name = Terminal.storyboard;
sourceTree = "<group>";
};
BB792B5E1F96D90D00FFB7A4 /* LaunchScreen.storyboard */ = {
Expand Down

0 comments on commit e7d7f46

Please sign in to comment.