From 131967b3b9c2996c2f07aa528521c4dc399bfe17 Mon Sep 17 00:00:00 2001 From: Baraka Date: Thu, 22 Sep 2016 13:20:49 -0500 Subject: [PATCH 1/2] Adds a feature request for pausing currently playing music on screen lock This is a feature which can be viewed here: https://github.com/radiant-player/radiant-player-mac/issues/607 ![image](https://cloud.githubusercontent.com/assets/2947494/18604903/5b3 f8d0c-7c49-11e6-922f-ea938bccd843.png) Go to the Preferences -> General -> Check on Toggle current music play status You can test it in REAL time without having to reload the Radiant Player App; do control + shift + eject or press Login Window : ![image](https://cloud.githubusercontent.com/assets/2947494/18605340/e72 d72ec-7c54-11e6-8f59-cc0725e33519.png) Both will trigger the music to PAUSE and PLAY if there is any item that is playing of-course Screen Locked = PAUSE music Screen Unlocked = PLAY music and if you uncheck Toggle current music play status you will see it off added for users that don't want to use this option Default state is off --- radiant-player-mac/AppDelegate.m | 41 +++++ radiant-player-mac/Preferences.plist | 2 + .../PreferencesWindowController.xib | 141 +++++++----------- 3 files changed, 95 insertions(+), 89 deletions(-) diff --git a/radiant-player-mac/AppDelegate.m b/radiant-player-mac/AppDelegate.m index 3f0dbeee..a781a74d 100644 --- a/radiant-player-mac/AppDelegate.m +++ b/radiant-player-mac/AppDelegate.m @@ -70,6 +70,27 @@ - (void)receiveSleepNotification:(NSNotification*)notification [self playPause:self]; } +#pragma mark - screen locked/unlocked events + +- (void)RadiantScreenLocked { + + if ([defaults boolForKey:@"toggleMusicOnScreenLock"]) + { + if (currentPlaybackMode == MUSIC_PLAYING) { + [self playPause:self]; + } + } +} + +- (void)RadiantScreenUnlocked { + if ([defaults boolForKey:@"toggleMusicOnScreenLock"]) + { + if (currentPlaybackMode == MUSIC_PAUSED) { + [self playPause:self]; + } + } +} + /** * Application finished launching, we will register the event tap callback. */ @@ -254,6 +275,26 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification // Register for machine sleep notifications [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(receiveSleepNotification:) name:NSWorkspaceWillSleepNotification object:nil]; + + // Register screen locked/unlocked events + [[NSDistributedNotificationCenter defaultCenter] addObserver:self + selector:@selector(RadiantScreenLocked) + name:@"com.apple.screenIsLocked" + object:nil]; + + [[NSDistributedNotificationCenter defaultCenter] addObserver:self + selector:@selector(RadiantScreenUnlocked) + name:@"com.apple.screenIsUnlocked" + object:nil]; + + [[NSDistributedNotificationCenter defaultCenter] addObserver: self + selector: @selector(RadiantScreenLocked) + name: @"com.apple.sessionDidMoveOffConsole" + object: nil]; + [[NSDistributedNotificationCenter defaultCenter] addObserver: self + selector: @selector(RadiantScreenUnlocked) + name: @"com.apple.sessionDidMoveOnConsole" + object: nil]; } - (NSMutableDictionary *)styles diff --git a/radiant-player-mac/Preferences.plist b/radiant-player-mac/Preferences.plist index 9129904c..39c50979 100644 --- a/radiant-player-mac/Preferences.plist +++ b/radiant-player-mac/Preferences.plist @@ -56,5 +56,7 @@ WebKitDeveloperExtras + toggleMusicOnScreenLock + diff --git a/radiant-player-mac/Preferences/PreferencesWindowController.xib b/radiant-player-mac/Preferences/PreferencesWindowController.xib index e9d46034..238313bc 100644 --- a/radiant-player-mac/Preferences/PreferencesWindowController.xib +++ b/radiant-player-mac/Preferences/PreferencesWindowController.xib @@ -1,8 +1,8 @@ - + - + @@ -17,13 +17,12 @@ - + - + - @@ -31,9 +30,8 @@ - + - @@ -87,9 +82,8 @@ - + - @@ -122,9 +114,8 @@ - + - @@ -132,9 +123,8 @@ - + - @@ -142,9 +132,8 @@ - + - @@ -152,9 +141,8 @@ - + - @@ -162,9 +150,8 @@ - + - @@ -206,9 +191,8 @@ - + - @@ -229,9 +212,8 @@ + + + + + + Applying this will allow you to toggle the current music playing to be paused on a locked screen and plays back on a unlocked screen + + + + + + + + + + + + + + - @@ -268,7 +278,6 @@ - @@ -491,13 +485,11 @@ with moving the window or the player freezing - - @@ -507,7 +499,6 @@ with moving the window or the player freezing - + @@ -82,7 +82,7 @@ - + @@ -114,7 +114,7 @@ - + @@ -123,7 +123,7 @@ - + @@ -132,7 +132,7 @@ - + @@ -141,7 +141,7 @@ - + @@ -150,7 +150,7 @@ - + @@ -191,7 +191,7 @@ - + @@ -212,7 +212,7 @@ - + - + - Applying this will allow you to toggle the current music playing to be paused on a locked screen and plays back on a unlocked screen - + @@ -257,7 +256,7 @@ - +