From b5b5b330b2971b465f2add7bba4275e7ab32cc5b Mon Sep 17 00:00:00 2001 From: MidnightChip Date: Fri, 1 Mar 2019 22:39:44 -0700 Subject: [PATCH] Remap, blacklist, --- control | 2 +- preferences/HGPPreferenceController.m | 5 + .../Resources/base.lproj/statusBar.strings | 2 + .../Resources/en-GB.lproj/statusBar.strings | 2 + .../Resources/en.lproj/statusBar.strings | 2 + preferences/Resources/statusBar.plist | 11 + source/HGBlacklist+Remap.xm | 226 +----------------- source/HGStatusBar.xm | 32 ++- 8 files changed, 58 insertions(+), 224 deletions(-) diff --git a/control b/control index e560c9c..842eac4 100644 --- a/control +++ b/control @@ -2,7 +2,7 @@ Package: com.vitataf.homegesture Name: HomeGesture Pre-Depends: com.spark.libsparkapplist Depends: firmware (>= 11.0), mobilesubstrate, preferenceloader, com.creaturecoding.libcspreferences, com.creaturesurvive.libcscolorpicker, org.thebigboss.libcolorpicker -Version: 2.1.1 +Version: 2.1.2 Architecture: iphoneos-arm Description: Enable iPhone X home gesture on other devices. Maintainer: MidnightChips/PINPAL diff --git a/preferences/HGPPreferenceController.m b/preferences/HGPPreferenceController.m index 1c518f5..d3c4f2e 100644 --- a/preferences/HGPPreferenceController.m +++ b/preferences/HGPPreferenceController.m @@ -54,6 +54,11 @@ -(void)selectBlackList{ [self.navigationController pushViewController:s animated:YES]; self.navigationItem.hidesBackButton = FALSE; } +-(void)selectStatusBlacklist{ + SparkAppListTableViewController* s = [[SparkAppListTableViewController alloc] initWithIdentifier:@"com.midnight.homegesture.plist" andKey:@"statusBlack"]; + [self.navigationController pushViewController:s animated:YES]; + self.navigationItem.hidesBackButton = FALSE; +} @end @implementation HGPPreferenceController diff --git a/preferences/Resources/base.lproj/statusBar.strings b/preferences/Resources/base.lproj/statusBar.strings index 52c873e..5031b8d 100644 --- a/preferences/Resources/base.lproj/statusBar.strings +++ b/preferences/Resources/base.lproj/statusBar.strings @@ -11,4 +11,6 @@ "Show_Centre" = "Show the status bar in Control Centre"; "iPad_STYLE" = "iPad Style Status Bar"; "Mimic_iPad" = "Mimics iPad Status Bar, adds date (iOS 12+)"; + "Disable_IPX_IN_APPS" = "Disable the iPhone X Status bar in incompatible apps (iOS 12)"; + "Turn_ON_iPad_FallBack"= "You can also enable the iPad status bar for those apps as a fallback"; } \ No newline at end of file diff --git a/preferences/Resources/en-GB.lproj/statusBar.strings b/preferences/Resources/en-GB.lproj/statusBar.strings index f938aa1..1a56dc2 100644 --- a/preferences/Resources/en-GB.lproj/statusBar.strings +++ b/preferences/Resources/en-GB.lproj/statusBar.strings @@ -11,4 +11,6 @@ "Show_Centre" = "Show the status bar in Control Centre"; "iPad_STYLE" = "iPad Style Status Bar"; "Mimic_iPad" = "Mimics iPad Status Bar, adds date (iOS 12)"; + "Disable_IPX_IN_APPS" = "Disable the iPhone X Status bar in incompatible apps (iOS 12)"; + "Turn_ON_iPad_FallBack"= "You can also enable the iPad status bar for those apps as a fallback"; } diff --git a/preferences/Resources/en.lproj/statusBar.strings b/preferences/Resources/en.lproj/statusBar.strings index 091c89f..b630f83 100644 --- a/preferences/Resources/en.lproj/statusBar.strings +++ b/preferences/Resources/en.lproj/statusBar.strings @@ -11,4 +11,6 @@ "Show_Centre" = "Show the status bar in Control Center"; "iPad_STYLE" = "iPad Style Status Bar"; "Mimic_iPad" = "Mimics iPad Status Bar, adds date (iOS 12)"; + "Disable_IPX_IN_APPS" = "Disable the iPhone X Status bar in incompatible apps (iOS 12)"; + "Turn_ON_iPad_FallBack"= "You can also enable the iPad status bar for those apps as a fallback"; } diff --git a/preferences/Resources/statusBar.plist b/preferences/Resources/statusBar.plist index 2ecaf8b..81eb465 100644 --- a/preferences/Resources/statusBar.plist +++ b/preferences/Resources/statusBar.plist @@ -41,6 +41,17 @@ /Library/PreferenceBundles/HomeGesture.bundle + + cell + PSButtonCell + label + Disable_IPX_IN_APPS + sublabel + Turn_ON_iPad_FallBack + action + selectStatusBlacklist + + cell PSSwitchCell diff --git a/source/HGBlacklist+Remap.xm b/source/HGBlacklist+Remap.xm index ac6530d..ad0c172 100644 --- a/source/HGBlacklist+Remap.xm +++ b/source/HGBlacklist+Remap.xm @@ -1,245 +1,41 @@ #import "HomeGesture.h" -/*int applicationDidFinishLaunching; - -%group loadMe -static BOOL homeEnable = YES; -static BOOL rotateDisable = YES; -// Disable Gestures Switch -%hook SBHomeGestureSettings --(BOOL)isHomeGestureEnabled{ - if(![prefs boolForKey:@"disableGestures"]){ - NSString *currentApp; - SpringBoard *springBoard = (SpringBoard *)[UIApplication sharedApplication]; - SBApplication *frontApp = (SBApplication *)[springBoard _accessibilityFrontMostApplication]; - currentApp = [frontApp valueForKey:@"_bundleIdentifier"]; - if(homeEnable && rotateDisable && ![SparkAppList doesIdentifier:@"com.midnight.homegesture.plist" andKey:@"blackList" containBundleIdentifier:currentApp]){ - return YES; - }else{ - return NO; - } - }else{ - return NO; - } -} -%end - -// Disable Gestures (SpringBoard applicationDidFinishLaunching also used in Screenshot Remap!) -static NSString *currentApp; - -%hook SpringBoard --(void)applicationDidFinishLaunching:(id)application { - applicationDidFinishLaunching = 2; - %orig; - -// Disable Gestures When Keyboard is Visible - if([prefs boolForKey:@"stopKeyboard"]){ - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(keyboardDidShow:) - name:UIKeyboardDidShowNotification - object:nil]; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(keyboardDidHide:) - name:UIKeyboardDidHideNotification - object:nil]; - } - -// Disable Gestures in Blacklisted Apps - if ([prefs boolForKey:@"enableBlacklist"]){ - [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; - [[NSNotificationCenter defaultCenter] - addObserver:self selector:@selector(yourMethod:) - name:UIDeviceOrientationDidChangeNotification - object:[UIDevice currentDevice]]; - } -} - -%new --(void)keyboardDidShow:(NSNotification *)sender -{ - homeEnable = NO; -} - -%new --(void)keyboardDidHide:(NSNotification *)sender -{ - homeEnable = YES; -} - -%new --(void)yourMethod:(NSNotification *)sender { - UIDevice *currentDevice = sender.object; - if(currentDevice.orientation == UIDeviceOrientationPortrait) { - rotateDisable = YES; - } - if(currentDevice.orientation == UIDeviceOrientationLandscapeLeft) { - SpringBoard *springBoard = (SpringBoard *)[UIApplication sharedApplication]; - SBApplication *frontApp = (SBApplication *)[springBoard _accessibilityFrontMostApplication]; - currentApp = [frontApp valueForKey:@"_bundleIdentifier"]; - if([SparkAppList doesIdentifier:@"com.midnight.homegesture.plist" andKey:@"excludedApps" containBundleIdentifier:currentApp]){ - rotateDisable = NO; - } - } - if(currentDevice.orientation == UIDeviceOrientationLandscapeRight) { - SpringBoard *springBoard = (SpringBoard *)[UIApplication sharedApplication]; - SBApplication *frontApp = (SBApplication *)[springBoard _accessibilityFrontMostApplication]; - currentApp = [frontApp valueForKey:@"_bundleIdentifier"]; - if([SparkAppList doesIdentifier:@"com.midnight.homegesture.plist" andKey:@"excludedApps" containBundleIdentifier:currentApp]){ - rotateDisable = NO; - } - } - if(currentDevice.orientation == UIDeviceOrientationPortraitUpsideDown) { - rotateDisable = YES; - } -} -%end - -//Remap -// Screenshot Remap -%hook SBPressGestureRecognizer -- (void)setAllowedPressTypes:(NSArray *)arg1 { - NSArray * lockHome = @[@104, @101]; - NSArray * lockVol = @[@104, @102, @103]; - if ([arg1 isEqual:lockVol] && applicationDidFinishLaunching == 2 && [prefs boolForKey:@"remapScreen"]) { - %orig(lockHome); - applicationDidFinishLaunching--; - return; - } - %orig; -} -%end -%hook SBClickGestureRecognizer -- (void)addShortcutWithPressTypes:(id)arg1 { - if (applicationDidFinishLaunching == 1 && [prefs boolForKey:@"remapScreen"]) { - applicationDidFinishLaunching--; - return; - } - %orig; -} -%end -%end - -%group kickStart -%hook SpringBoard --(void)applicationDidFinishLaunching:(id)application { - %orig; - %init(loadMe) -} -%end -%end - -%ctor { - //NSString *bundleIdentifier = [NSBundle mainBundle].bundleIdentifier; - NSFileManager *fileManager = [NSFileManager defaultManager]; - if ([fileManager fileExistsAtPath:@"/var/mobile/Library/Preferences/HomeGesture/setup"]){ - %init(kickStart); - } -}*/ -/*static BOOL enableGesture(){ - NSLog(@"") - if([SparkAppList doesIdentifier:@"com.midnight.homegesture.plist" andKey:@"blackList" containBundleIdentifier:[[NSBundle mainBundle] bundleIdentifier]]){ - return NO; - }else{ - return YES; - } -}*/ -/*@interface PTSettings : NSObject -@end -@interface _UISettings : PTSettings -@end -@interface SBUISettings : _UISettings -@end -@interface SBHomeGestureSettings : SBUISettings --(void)setHomeGestureEnabled:(BOOL)arg1 ; -@end - -%hook SBHomeGestureSettings --(BOOL)isHomeGestureEnabled{ - //return enableGesture(); - NSLog(@"HOMEGESTURE SETTINGNOTIFS"); - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(keyboardDidShow:) - name:UIKeyboardDidShowNotification - object:nil]; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(keyboardDidHide:) - name:UIKeyboardDidHideNotification - object:nil]; - return %orig; - -} -%new --(void)keyboardDidShow:(NSNotification *)sender{ - NSLog(@"KEYBOARD UP"); - [self setHomeGestureEnabled:FALSE]; -} -%new --(void)keyboardDidHide:(NSNotification *)sender{ - NSLog(@"KEYBOARD DOWN"); - [self setHomeGestureEnabled:TRUE]; -} -%end */ -/*-(void)setHomeGestureEnabled:(BOOL)arg1{ - %orig(NO); -}*/ - -//%end -%group remap int applicationDidFinishLaunching; long _homeButtonTypeRemap = 1; - %hook SpringBoard - -(void)applicationDidFinishLaunching:(id)application { - applicationDidFinishLaunching = 2; - %orig; - } - %end - %hook SBPressGestureRecognizer - (void)setAllowedPressTypes:(NSArray *)arg1 { NSArray * lockHome = @[@104, @101]; NSArray * lockVol = @[@104, @102, @103]; - if ([arg1 isEqual:lockVol] && applicationDidFinishLaunching == 2) { + if ([arg1 isEqual:lockVol] && applicationDidFinishLaunching == 2 && [prefs boolForKey:@"remapScreen"]) { %orig(lockHome); applicationDidFinishLaunching--; return; - } + } %orig; } %end - %hook SBClickGestureRecognizer - (void)addShortcutWithPressTypes:(id)arg1 { - if (applicationDidFinishLaunching == 1) { + if (applicationDidFinishLaunching == 1 && [prefs boolForKey:@"remapScreen"]) { applicationDidFinishLaunching--; return; } %orig; } %end - %hook SBHomeHardwareButton - (id)initWithScreenshotGestureRecognizer:(id)arg1 homeButtonType:(long long)arg2 buttonActions:(id)arg3 gestureRecognizerConfiguration:(id)arg4 { - return %orig(arg1, _homeButtonTypeRemap, arg3, arg4); + if ([prefs boolForKey:@"remapScreen"]) { + return %orig(arg1, _homeButtonTypeRemap, arg3, arg4); + } + return %orig; } - (id)initWithScreenshotGestureRecognizer:(id)arg1 homeButtonType:(long long)arg2 { - return %orig(arg1, _homeButtonTypeRemap); -} -%end -%end - -%ctor{ - if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"12.0")){ - %init(remap) + if ([prefs boolForKey:@"remapScreen"]) { + return %orig(arg1, _homeButtonTypeRemap); } + return %orig; } - //NSString *bundleID = [NSBundle mainBundle].bundleIdentifier; - /*if([SparkAppList doesIdentifier:@"com.midnight.homegesture.plist" andKey:@"blackList" containBundleIdentifier:bundleID]){ - %init(stopGesture); - }*/ - //} - -//} +%end \ No newline at end of file diff --git a/source/HGStatusBar.xm b/source/HGStatusBar.xm index 671f402..8473150 100644 --- a/source/HGStatusBar.xm +++ b/source/HGStatusBar.xm @@ -1,4 +1,6 @@ #import "HomeGesture.h" +#define CURRENT_BUNDLE [NSBundle mainBundle].bundleIdentifier +#define IS_ALLOWED [SparkAppList doesIdentifier:@"com.midnight.homegesture.plist" andKey:@"statusBlack" containBundleIdentifier:CURRENT_BUNDLE] // Hide Carrier Text in Status Bar %hook UIStatusBarServiceItemView @@ -28,15 +30,15 @@ // iPhone X Status bar %hook UIStatusBar_Base + (BOOL)forceModern { - if([prefs boolForKey:@"statusBarX"]){ + if([prefs boolForKey:@"statusBarX"] && !IS_ALLOWED){ return [prefs boolForKey:@"statusBarX"]; }else{ return %orig; } } + (Class)_statusBarImplementationClass { - if([prefs boolForKey:@"statusBarX"]){ - return [prefs boolForKey:@"statusBarX"] ? NSClassFromString(@"UIStatusBar_Modern") : NSClassFromString(@"UIStatusBar"); + if([prefs boolForKey:@"statusBarX"] && !IS_ALLOWED){ + return NSClassFromString(@"UIStatusBar_Modern"); }else{ return %orig; } @@ -45,7 +47,9 @@ + (Class)_implementationClass { if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"12.0")) { - if([prefs boolForKey:@"statusBarX"] || [prefs boolForKey:@"statusBarPad"]){ + if([prefs boolForKey:@"statusBarX"] && !IS_ALLOWED){ + return NSClassFromString(@"UIStatusBar_Modern"); + }else if([prefs boolForKey:@"statusBarPad"]){ return NSClassFromString(@"UIStatusBar_Modern"); }else{ return %orig; @@ -56,8 +60,10 @@ } + (void)_setImplementationClass:(Class)arg1 { if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"12.0")) { - if([prefs boolForKey:@"statusBarX"] || [prefs boolForKey:@"statusBarPad"]){ + if([prefs boolForKey:@"statusBarX"] && !IS_ALLOWED){ %orig(NSClassFromString(@"UIStatusBar_Modern")); + }else if([prefs boolForKey:@"statusBarPad"]){ + %orig(NSClassFromString(@"UIStatusBar_Modern")); }else{ %orig; } @@ -72,7 +78,7 @@ %hook _UIStatusBar //TODO ONLY FOR SPLIT 58 + (double)heightForOrientation:(long long)arg1 { - if([prefs boolForKey:@"statusBarX"]){ + if([prefs boolForKey:@"statusBarX"] && !IS_ALLOWED ){ if (arg1 == 1 || arg1 == 2) { return %orig - 9; } else { @@ -87,8 +93,16 @@ %hook _UIStatusBarVisualProvider_iOS + (Class)class { + /*NSString *currentApp; + if (![CURRENT_BUNDLE isEqualToString:@"com.apple.springboard"]){ + SpringBoard *springBoard = (SpringBoard *)[UIApplication sharedApplication]; + SBApplication *frontApp = (SBApplication *)[springBoard _accessibilityFrontMostApplication]; + currentApp = [frontApp valueForKey:@"_bundleIdentifier"]; + }else{ + currentApp = CURRENT_BUNDLE; + }*/ if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"12.0")) { - if([prefs boolForKey:@"statusBarX"]){ + if([prefs boolForKey:@"statusBarX"] && !IS_ALLOWED){ return NSClassFromString(@"_UIStatusBarVisualProvider_Split58"); }else if([prefs boolForKey:@"statusBarPad"]){ return NSClassFromString(@"_UIStatusBarVisualProvider_Pad_ForcedCellular"); @@ -106,7 +120,9 @@ %hook UIStatusBarWindow + (void)setStatusBar:(Class)arg1 { if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"12.0")) { - if([prefs boolForKey:@"statusBarX"] || [prefs boolForKey:@"statusBarPad"]){ + if([prefs boolForKey:@"statusBarX"] && !IS_ALLOWED){ + %orig(NSClassFromString(@"UIStatusBar_Modern")); + }else if([prefs boolForKey:@"statusBarPad"]){ %orig(NSClassFromString(@"UIStatusBar_Modern")); }else{ %orig;