From 7d9e43da0793ef532c4829441cbc4693020692d3 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Fri, 24 Jan 2014 12:02:09 -0800 Subject: [PATCH] Add a setting to force Now Playing to the front. --- CydgetLoader.mm | 52 +++++++++++++++++++++++++++--- CydgetSettings.bundle/Cydget.plist | 24 ++++++++++++++ 2 files changed, 71 insertions(+), 5 deletions(-) diff --git a/CydgetLoader.mm b/CydgetLoader.mm index c73ae20..823cb27 100644 --- a/CydgetLoader.mm +++ b/CydgetLoader.mm @@ -60,16 +60,44 @@ MSInitialize { } } +@interface SBLockScreenNowPlayingPluginController : NSObject +- (BOOL) isNowPlayingPluginActive; +@end + @interface SBLockScreenViewController : UIViewController +- (SBLockScreenView *) lockScreenView; +- (BOOL) isShowingMediaControls; - (void) _toggleMediaControls; @end +@interface SBLockScreenManager : NSObject ++ (SBLockScreenManager *) sharedInstance; +- (SBLockScreenViewController *) lockScreenViewController; +@end + static bool menu_; static _H settings_; static _H cydgets_; static size_t active_; static unsigned online_; +static bool nowplaying_; + +static bool NowPlaying() { + if (kCFCoreFoundationVersionNumber < 800) + return false; + if (!nowplaying_) + return false; + + SBLockScreenViewController *controller([[$SBLockScreenManager sharedInstance] lockScreenViewController]); + if (controller != nil) { + SBLockScreenNowPlayingPluginController *now(MSHookIvar(controller, "_nowPlayingController")); + if (now != nil && [now isNowPlayingPluginActive]) + return true; + } + + return false; +} @interface CydgetController : NSObject { } @@ -188,7 +216,8 @@ MSInstanceMessageHook0(BOOL, SBLockScreenManager, handleMenuButtonTap) { media_ = false; if (!value && menu_) { - [[cydgets_ objectAtIndex:active_] disableCydget]; + if (active_ != _not(size_t)) + [[cydgets_ objectAtIndex:active_] disableCydget]; active_ = (active_ + 1) % [cydgets_ count]; [[cydgets_ objectAtIndex:active_] enableCydget]; // XXX: or siri doesn't disappear correctly @@ -200,7 +229,15 @@ MSInstanceMessageHook0(BOOL, SBLockScreenManager, handleMenuButtonTap) { void Activate_() { menu_ = false; - [[cydgets_ objectAtIndex:active_] enableCydget]; + if (NowPlaying()) { + for (active_ = 0; active_ != [cydgets_ count]; ++active_) + if ([[[cydgets_ objectAtIndex:active_] objectForKey:@"CYName"] isEqualToString:@"AwayView"]) + break; + if (active_ == [cydgets_ count]) + active_ = _not(size_t); + } + if (active_ != _not(size_t)) + [[cydgets_ objectAtIndex:active_] enableCydget]; } static void Undim_(SBAwayController *self) { @@ -226,7 +263,8 @@ MSInstanceMessageHook1(void, SBAwayController, undimScreen, BOOL, undim) { } static void Deactivate_() { - [[cydgets_ objectAtIndex:active_] disableCydget]; + if (active_ != _not(size_t)) + [[cydgets_ objectAtIndex:active_] disableCydget]; active_ = 0; } @@ -278,6 +316,8 @@ static void CydgetSetup() { NSString *plist([NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.Cydget.plist", NSHomeDirectory()]); settings_ = [NSMutableDictionary dictionaryWithContentsOfFile:plist] ?: [NSMutableDictionary dictionary]; + nowplaying_ = [[settings_ objectForKey:@"NowPlaying"] boolValue]; + NSArray *cydgets([settings_ objectForKey:@"LockCydgets"] ?: [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys: @"Welcome", @"Name", [NSNumber numberWithBool:YES], @"Active", nil ], [NSDictionary dictionaryWithObjectsAndKeys: @@ -287,8 +327,10 @@ static void CydgetSetup() { cydgets_ = [NSMutableArray arrayWithCapacity:4]; for (NSDictionary *cydget in cydgets) if ([[cydget objectForKey:@"Active"] boolValue]) { - NSString *path([NSString stringWithFormat:@"%@/%@.cydget/Info.plist", Cydgets_, [cydget objectForKey:@"Name"]]); + NSString *name([cydget objectForKey:@"Name"]); + NSString *path([NSString stringWithFormat:@"%@/%@.cydget/Info.plist", Cydgets_, name]); if (NSMutableDictionary *info = [NSMutableDictionary dictionaryWithContentsOfFile:path]) { + [info setObject:name forKey:@"CYName"]; [info setObject:path forKey:@"CYPath"]; [cydgets_ addObject:info]; } @@ -302,7 +344,7 @@ static void CydgetSetup() { MSInstanceMessageHook1(id, SBLockScreenView, initWithFrame, CGRect, frame) { self = MSOldCall(frame); CydgetSetup(); - [[cydgets_ objectAtIndex:active_] enableCydget]; + Activate_(); return self; } diff --git a/CydgetSettings.bundle/Cydget.plist b/CydgetSettings.bundle/Cydget.plist index c8b2e71..9c5c69f 100644 --- a/CydgetSettings.bundle/Cydget.plist +++ b/CydgetSettings.bundle/Cydget.plist @@ -50,6 +50,30 @@ + + cell + PSGroupCell + footerText + Force the AwayView (even if not selected) to the front of the order while the now playing controller is active + wb$filter + + 800 + + + + cell + PSSwitchCell + default + + key + NowPlaying + label + Now Playing + wb$filter + + 800 + + title Cydget -- 2.45.2