From c6daf1f567e1258f5c9303561f85779b045f626f Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Fri, 24 Jan 2014 09:48:26 -0800 Subject: [PATCH] Re-implement iOS 6 media controls toggle on iOS 7. --- CydgetLoader.mm | 27 +++++++++++++++++++++++++-- LockScreen.mm | 20 ++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/CydgetLoader.mm b/CydgetLoader.mm index a06d860..0ffa2c1 100644 --- a/CydgetLoader.mm +++ b/CydgetLoader.mm @@ -60,6 +60,10 @@ MSInitialize { } } +@interface SBLockScreenViewController : UIViewController +- (void) _toggleMediaControls; +@end + static bool menu_; static _H settings_; @@ -163,14 +167,33 @@ MSInstanceMessageHook1(void, SpringBoard, handleKeyEvent, GSEventRef, event) { return MSSuperCall(event); } +bool media_; + +MSInstanceMessageHook0(void, SBLockScreenViewController, _toggleMediaControls) { + if (!media_) + MSOldCall(); +} + +MSInstanceMessageHook0(BOOL, SBLockScreenViewController, handleMenuButtonDoubleTap) { + menu_ = false; + BOOL value(MSOldCall()); + if (kCFCoreFoundationVersionNumber >= 800) + [self _toggleMediaControls]; + return value; +} + MSInstanceMessageHook0(BOOL, SBLockScreenManager, handleMenuButtonTap) { - if (!MSOldCall() && menu_) { + media_ = true; + BOOL value(MSOldCall()); + media_ = false; + + if (!value && menu_) { [[cydgets_ objectAtIndex:active_] disableCydget]; active_ = (active_ + 1) % [cydgets_ count]; [[cydgets_ objectAtIndex:active_] enableCydget]; } - return YES; + return value; } void Activate_() { diff --git a/LockScreen.mm b/LockScreen.mm index 4c8f190..90da329 100644 --- a/LockScreen.mm +++ b/LockScreen.mm @@ -127,6 +127,16 @@ typedef uint16_t UChar; - (void) _setZoomScale:(float)scale duration:(double)duration; @end +@interface SBLockScreenViewController : UIViewController +- (BOOL) isShowingMediaControls; +- (void) _setMediaControlsVisible:(BOOL)visible; +@end + +@interface SBLockScreenManager : NSObject ++ (SBLockScreenManager *) sharedInstance; +- (SBLockScreenViewController *) lockScreenViewController; +@end + @protocol CydgetController - (NSDictionary *) currentConfiguration; - (NSString *) currentPath; @@ -282,6 +292,7 @@ static float CYScrollViewDecelerationRateNormal; @end MSClassHook(UIApplication) +MSClassHook(SBLockScreenManager) MSInstanceMessageHook1(void, UIApplication, openURL, NSURL *, url) { [self applicationOpenURL:url]; @@ -1207,6 +1218,15 @@ static void $UIWebViewWebViewDelegate$webView$didClearWindowObject$forFrame$(UIW return YES; }*/ +- (BOOL) handleMenuButtonDoubleTap { + if (kCFCoreFoundationVersionNumber >= 800) { + SBLockScreenViewController *controller([[$SBLockScreenManager sharedInstance] lockScreenViewController]); + [controller _setMediaControlsVisible:![controller isShowingMediaControls]]; + } + + return [super handleMenuButtonDoubleTap]; +} + @end MSClassHook(WebView) -- 2.45.2