From 42f824b31f600f5c55fd429b7eaad7fcedba9187 Mon Sep 17 00:00:00 2001 From: ichitaso Date: Mon, 13 Aug 2018 00:50:13 +0900 Subject: [PATCH 1/2] Support iOS 11 Wi-Fi long press reference code: https://github.com/ioscreatix/WeatherVane --- Private.h | 4 +++ Tweak.xm | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- control | 2 +- 3 files changed, 97 insertions(+), 5 deletions(-) diff --git a/Private.h b/Private.h index 4b21b35..eb4e09f 100644 --- a/Private.h +++ b/Private.h @@ -72,4 +72,8 @@ extern "C" void *WiFiDeviceClientCopyCurrentNetwork(void *); @interface UIImage () + (instancetype)imageNamed:(NSString *)name inBundle:(NSBundle *)bundle; +@end + +@interface WPScanRequest : NSObject +- (void)setRssiThreshold:(NSNumber *)arg1; @end \ No newline at end of file diff --git a/Tweak.xm b/Tweak.xm index fa8848f..be0d6b8 100644 --- a/Tweak.xm +++ b/Tweak.xm @@ -10,6 +10,7 @@ #define CoreFoundationiOS7 847.20 #define CoreFoundationiOS10 1348.00 +#define CoreFoundationiOS11 1443.00 static BOOL shouldShowPicker = NO; @@ -88,8 +89,8 @@ static BOOL isLongHoldEnabled() return; } - //It does not work well on lock screen on iOS10. - if (kCFCoreFoundationVersionNumber >= CoreFoundationiOS10 && [[objc_getClass("SBUserAgent") sharedUserAgent] deviceIsLocked]) return; + //It does not work well on lock screen on iOS10 and iOS 11. + if (((kCFCoreFoundationVersionNumber >= CoreFoundationiOS10 && kCFCoreFoundationVersionNumber < CoreFoundationiOS11) && [[objc_getClass("SBUserAgent") sharedUserAgent] deviceIsLocked]) || (kCFCoreFoundationVersionNumber >= CoreFoundationiOS11 && [[objc_getClass("SBUserAgent") alloc] deviceIsLocked])) return; if (event) { @@ -269,10 +270,13 @@ static BOOL isLongHoldEnabled() - (void)scan { //Only on 7 and later - if (kCFCoreFoundationVersionNumber >= CoreFoundationiOS7) + if (kCFCoreFoundationVersionNumber >= CoreFoundationiOS7 && kCFCoreFoundationVersionNumber < CoreFoundationiOS11) { [[objc_getClass("WFWiFiManager") sharedInstance] setValue:[NSNumber numberWithInt:-130] forKey:@"_rssiThreshold"]; - } + } + else if (kCFCoreFoundationVersionNumber >= CoreFoundationiOS11) { + [[objc_getClass("WPScanRequest") alloc] setRssiThreshold:[NSNumber numberWithInt:-130]]; + } %orig; } @@ -490,6 +494,58 @@ static char wipiHoldGestureRecognizer; %end %end +@interface CCUIConnectivityWifiViewController : UIViewController +@property (nonatomic, retain) UILongPressGestureRecognizer *longPressRecognizer; +@property (nonatomic, retain) UIButton *button; +- (void)_wipi_longHoldAction; +@end + +%group ControlCenter11 +%hook CCUIConnectivityWifiViewController +%property (nonatomic, retain) UILongPressGestureRecognizer *longPressRecognizer; + +%new +- (void)longPressRecognized:(UILongPressGestureRecognizer *)sender { + if (sender.state == UIGestureRecognizerStateBegan) { + if ([self valueForKey:@"_parentViewController"]) { + if ([[self valueForKey:@"_parentViewController"] valueForKey:@"_expanded"]) { + if ([[[self valueForKey:@"_parentViewController"] valueForKey:@"_expanded"] boolValue] == YES) { + [self _wipi_longHoldAction]; + } + } + } + } +} + +- (id)init { + CCUIConnectivityWifiViewController *controller = %orig; + if (controller) { + controller.longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressRecognized:)]; + controller.longPressRecognizer.minimumPressDuration = 0.9; + } + return controller; + +} + +- (void)viewDidLoad { + %orig; + if (self.longPressRecognizer && self.button) { + [self.button addGestureRecognizer:self.longPressRecognizer]; + } +} + +%new +- (void)_wipi_longHoldAction +{ + if (isLongHoldEnabled()) + { + [[LAActivator sharedInstance] sendEvent:nil toListenerWithName:@"com.bensge.wipi"]; + } +} + +%end +%end + /* * Hook setup code */ @@ -568,6 +624,16 @@ void initFlipSwitch() %end %end +static BOOL didHook = NO; +static void notificationCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) { + if ([((__bridge NSDictionary *)userInfo)[NSLoadedClasses] containsObject:@"CCUIConnectivityAirDropViewController"]) { // The Network Bundle is Loaded + if (!didHook) { + didHook = YES; + %init(ControlCenter11); + } + } +} + /* * ------------- * | Constructor | @@ -591,6 +657,28 @@ void initFlipSwitch() %init(ControlCenter, BUTTONCLASS=(objc_getClass("SBControlCenterButton") ?: objc_getClass("CCUIControlCenterPushButton"))); } + BOOL shouldInit = NO; + if (!NSClassFromString(@"APTableCell")) { + NSString *fullPath = [NSString stringWithFormat:@"/System/Library/PreferenceBundles/AirPortSettings.bundle"]; + NSBundle *bundle; + bundle = [NSBundle bundleWithPath:fullPath]; + BOOL didLoad = [bundle load]; + if (didLoad) { + shouldInit = YES; + } + } else { + shouldInit = YES; + } + + if (shouldInit && kCFCoreFoundationVersionNumber >= CoreFoundationiOS11) + { + CFNotificationCenterAddObserver( + CFNotificationCenterGetLocalCenter(), NULL, + notificationCallback, + (CFStringRef)NSBundleDidLoadNotification, + NULL, CFNotificationSuspensionBehaviorCoalesce); + } + loadSettings(); } } \ No newline at end of file diff --git a/control b/control index 304e5b8..db4b10a 100644 --- a/control +++ b/control @@ -1,7 +1,7 @@ Package: com.bensge.wipi Name: WiPi Depends: firmware (>= 6.0), libactivator, mobilesubstrate, preferenceloader -Version: 1.5.1 +Version: 1.5.2 Architecture: iphoneos-arm Description: Activate system WiFi Picker with an Activator gesture, or by long-pressing the Control Center or FlipSwitch WiFi toggle. Automatically enables Wi-Fi if not enabled. Maintainer: bensge From 963cb599f8b883493802b41ae8abe75921a319b3 Mon Sep 17 00:00:00 2001 From: ichitaso Date: Mon, 13 Aug 2018 00:55:45 +0900 Subject: [PATCH 2/2] add 2018 --- Resources/WiPi.plist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/WiPi.plist b/Resources/WiPi.plist index 967ead0..cada157 100755 --- a/Resources/WiPi.plist +++ b/Resources/WiPi.plist @@ -50,7 +50,7 @@ cell PSGroupCell footerText - © 2013 - 2017 Bensge and contributors + © 2013 - 2018 Bensge and contributors title