diff options
author | comex | 2015-07-13 16:03:02 -0400 |
---|---|---|
committer | comex | 2015-07-13 16:03:02 -0400 |
commit | aab864c54c8c313b0c499d5bd1218df5b60a0229 (patch) | |
tree | bccfce67146f7c6c20bcaef059085fa38923f8a5 /darwin-bootstrap/safemode-ui-hook.m | |
parent | ...this should have been committed (diff) | |
download | substitute-aab864c54c8c313b0c499d5bd1218df5b60a0229.tar.gz |
Hook up SafetyDance properly.
Not as a setup application anymore, since we don't want to disable the
rest of SpringBoard if you choose to continue in safe mode... doh...
Diffstat (limited to 'darwin-bootstrap/safemode-ui-hook.m')
-rw-r--r-- | darwin-bootstrap/safemode-ui-hook.m | 104 |
1 files changed, 44 insertions, 60 deletions
diff --git a/darwin-bootstrap/safemode-ui-hook.m b/darwin-bootstrap/safemode-ui-hook.m index 38b9fc8..a64f729 100644 --- a/darwin-bootstrap/safemode-ui-hook.m +++ b/darwin-bootstrap/safemode-ui-hook.m @@ -5,85 +5,72 @@ #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> -/* TODO: test what happens when both are required */ - -static bool g_did_say_in_setup_mode; -static bool g_did_exit_safety_dance; +Class SpringBoard, SBApplicationController; @interface _SBApplicationController - (id)applicationWithBundleIdentifier:(NSString *)identifier; + (instancetype)sharedInstanceIfExists; @end -@interface _SBSetupManager -- (bool)updateInSetupMode; -- (bool)_setInSetupMode:(bool)inSetupMode; -- (id)applicationWithBundleIdentifier:(NSString *)identifier; -@end - @interface _SpringBoard - (void)relaunchSpringBoard; @end -static id (*old_setupApplication)(id, SEL); -static id my_setupApplication(id self, SEL sel) { - if (g_did_say_in_setup_mode) { - id app = [self applicationWithBundleIdentifier:@"com.ex.SafetyDance"]; - if (app) { - /* definitely shouldn't be nil, given below check, but... */ - NSLog(@"=>%@", app); - return app; - } - } - return old_setupApplication(self, sel); -} +@interface _SBApplication +- (void)setFlag:(int64_t)flag forActivationSetting:(unsigned)setting; +- (BOOL)launchApplicationWithIdentifier:(NSString *)iden + suspended:(BOOL)suspended; +- (BOOL)isRunning; +- (void)activate; +@end -static bool (*old_updateInSetupMode)(id, SEL); -static bool my_updateInSetupMode(id self, SEL sel) { - bool should_say = !g_did_exit_safety_dance; - if (should_say) { - _SBApplicationController *controller = - [objc_getClass("SBApplicationController") sharedInstanceIfExists]; - if (!controller) { - NSLog(@"substitute safe mode: SBApplicationController missing..."); - should_say = false; - } else if (![controller - applicationWithBundleIdentifier:@"com.ex.SafetyDance"]) { - NSLog(@"substitute safe mode: SafetyDance app missing or unregistered"); - should_say = false; - } +void (*old_applicationDidFinishLaunching)(id, SEL, id); +static void my_applicationDidFinishLaunching(id self, SEL sel, id app) { + old_applicationDidFinishLaunching(self, sel, app); + id controller = [SBApplicationController sharedInstanceIfExists]; + if (!controller) { + NSLog(@"substitute safe mode: sharedInstanceIfExists => nil!"); + return; } - - if (should_say) { - /* take priority over real setup */ - g_did_say_in_setup_mode = true; - [self _setInSetupMode:true]; - return true; - } else { - g_did_say_in_setup_mode = false; - return old_updateInSetupMode(self, sel); + NSString *bundle_id = @"com.ex.SafetyDance"; + id sbapp = [controller applicationWithBundleIdentifier:bundle_id]; + if (!sbapp) { + NSLog(@"substitute safe mode: no app with bundle ID '%@' - installation messed up?", + bundle_id); + return; } + [sbapp setFlag:1 forActivationSetting:1]; /* noAnimate */ + /* [sbapp setFlag:1 forActivationSetting:5]; */ /* seo */ + [self launchApplicationWithIdentifier:bundle_id suspended:NO]; } -static bool (*old__handleSetupExited)(id, SEL, id); -static bool my__handleSetupExited(id self, SEL sel, id app) { - if (g_did_say_in_setup_mode) - g_did_exit_safety_dance = true; - return old__handleSetupExited(self, sel, app); +BOOL (*old_handleDoubleHeightStatusBarTap)(id, SEL, int64_t); +static BOOL my_handleDoubleHeightStatusBarTap(id self, SEL sel, int64_t number) { + if (number == 202) { + NSString *bundle_id = @"com.ex.SafetyDance"; + id controller = [SBApplicationController sharedInstanceIfExists]; + id sbapp = [controller applicationWithBundleIdentifier:bundle_id]; + if ([sbapp isRunning]) { + NSLog(@"activate!"); + [sbapp setFlag:1 forActivationSetting:20]; /* fromBanner */ + [self launchApplicationWithIdentifier:bundle_id suspended:NO]; + return YES; + } + } + return old_handleDoubleHeightStatusBarTap(self, sel, number); } __attribute__((constructor)) static void init() { #define GET(clsname) \ - Class clsname = objc_getClass(#clsname); \ + clsname = objc_getClass(#clsname); \ if (!clsname) { \ NSLog(@"substitute safe mode failed to find %s", #clsname); \ return; \ } + GET(SpringBoard); GET(SBApplicationController); - GET(SBSetupManager); - GET(SBWorkspace); int notify_token; uint32_t notify_status = notify_register_dispatch( @@ -104,11 +91,8 @@ static void init() { } \ } while(0) - /* note: any of these might fail, leaving the previous ones hooked */ - - HOOK(SBApplicationController, setupApplication, setupApplication); - HOOK(SBWorkspace, _handleSetupExited:, _handleSetupExited); - HOOK(SBSetupManager, updateInSetupMode, updateInSetupMode); - - + HOOK(SpringBoard, applicationDidFinishLaunching:, + applicationDidFinishLaunching); + HOOK(SpringBoard, handleDoubleHeightStatusBarTap:, + handleDoubleHeightStatusBarTap); } |