[vlc-commits] osx_notifications: Use active state notifications for compatibility with OS X <10.10

Marvin Scholz git at videolan.org
Fri Oct 23 12:53:42 CEST 2015


vlc | branch: master | Marvin Scholz <epirat07 at gmail.com> | Fri Oct 23 12:13:23 2015 +0200| [80cada9e776c3ef0339c1f2c424b4322f84cdfa1] | committer: Felix Paul Kühne

osx_notifications: Use active state notifications for compatibility with OS X <10.10

This restores the code that used notifications to determine the app state.
Additionally the inital state is not active, as we get a notification if the
app switches to active after opening.

Signed-off-by: Felix Paul Kühne <fkuehne at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=80cada9e776c3ef0339c1f2c424b4322f84cdfa1
---

 modules/notify/osx_notifications.m |   26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/modules/notify/osx_notifications.m b/modules/notify/osx_notifications.m
index 20f7d07..914787d 100644
--- a/modules/notify/osx_notifications.m
+++ b/modules/notify/osx_notifications.m
@@ -86,6 +86,7 @@
     NSString *notificationType;
     NSMutableDictionary *registrationDictionary;
     id lastNotification;
+    bool isInForeground;
     intf_thread_t *interfaceThread;
 }
 
@@ -283,6 +284,21 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
     if( !( self = [super init] ) )
         return nil;
 
+    @autoreleasepool {
+        // Subscribe to notifications to determine if VLC is in foreground or not
+        [[NSNotificationCenter defaultCenter] addObserver:self
+                                                 selector:@selector(applicationActiveChange:)
+                                                     name:NSApplicationDidBecomeActiveNotification
+                                                   object:nil];
+
+        [[NSNotificationCenter defaultCenter] addObserver:self
+                                                 selector:@selector(applicationActiveChange:)
+                                                     name:NSApplicationDidResignActiveNotification
+                                                   object:nil];
+    }
+    // Start in background
+    isInForeground = NO;
+
     applicationName = nil;
     notificationType = nil;
     registrationDictionary = nil;
@@ -301,6 +317,7 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
              removeDeliveredNotification:(NSUserNotification *)lastNotification];
             [lastNotification release];
         }
+        [[NSNotificationCenter defaultCenter] removeObserver:self];
     }
 #endif
 
@@ -340,7 +357,7 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
 {
     @autoreleasepool {
         // Do not notify if in foreground
-        if ([NSApplication sharedApplication].active)
+        if (isInForeground)
             return;
 
         // Init Cover
@@ -436,6 +453,13 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
     return applicationName;
 }
 
+- (void)applicationActiveChange:(NSNotification *)n {
+    if (n.name == NSApplicationDidBecomeActiveNotification)
+        isInForeground = YES;
+    else if (n.name == NSApplicationDidResignActiveNotification)
+        isInForeground = NO;
+}
+
 #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
 - (void)userNotificationCenter:(NSUserNotificationCenter *)center
        didActivateNotification:(NSUserNotification *)notification



More information about the vlc-commits mailing list