[vlc-devel] [PATCH 2/3] osx_notifications: Show notification only if VLC in background, cleanup
epirat07 at gmail.com
epirat07 at gmail.com
Thu Oct 22 18:18:51 CEST 2015
From: Marvin Scholz <epirat07 at gmail.com>
This cleans up unnecessary code which could be replaced by a much simple
check to determine if VLC is in foreground or not.
Add a missing release.
---
modules/notify/osx_notifications.m | 37 ++++++-------------------------------
1 file changed, 6 insertions(+), 31 deletions(-)
diff --git a/modules/notify/osx_notifications.m b/modules/notify/osx_notifications.m
index 1ad7b42..7dc133d 100644
--- a/modules/notify/osx_notifications.m
+++ b/modules/notify/osx_notifications.m
@@ -74,7 +74,6 @@
NSString *notificationType;
NSMutableDictionary *registrationDictionary;
id lastNotification;
- BOOL isInForeground;
intf_thread_t *interfaceThread;
}
@@ -278,21 +277,6 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
registrationDictionary = nil;
interfaceThread = thread;
- // Assume we start in foreground
- isInForeground = YES;
-
- // Subscribe to notifications to determine if VLC is in foreground or not
- @autoreleasepool {
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(applicationActiveChange:)
- name:NSApplicationDidBecomeActiveNotification
- object:nil];
-
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(applicationActiveChange:)
- name:NSApplicationDidResignActiveNotification
- object:nil];
- }
return self;
}
@@ -306,7 +290,6 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
removeDeliveredNotification:(NSUserNotification *)lastNotification];
[lastNotification release];
}
- [[NSNotificationCenter defaultCenter] removeObserver:self];
}
#endif
@@ -345,6 +328,10 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
andArtUrl:(const char *)url
{
@autoreleasepool {
+ // Do not notify if in foreground
+ if ([NSApplication sharedApplication].active)
+ return;
+
// Init Cover
NSData *coverImageData = nil;
NSImage *coverImage = nil;
@@ -364,6 +351,7 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
} else {
// Without title, notification makes no sense, so return here
// title should never be empty, but better check than crash.
+ [coverImage release];
return;
}
if (artist)
@@ -436,17 +424,11 @@ 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
{
+ // Skip to next song
if (notification.activationType == NSUserNotificationActivationTypeActionButtonClicked) {
playlist_Next(pl_Get(interfaceThread));
}
@@ -463,12 +445,5 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
[notification retain];
lastNotification = notification;
}
-
-- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
- shouldPresentNotification:(NSUserNotification *)notification
-{
- // Show notifications regardless if App in foreground or background
- return YES;
-}
#endif
@end
--
2.2.1
More information about the vlc-devel
mailing list