1
mirror of https://code.videolan.org/videolan/vlc synced 2024-07-21 07:24:15 +02:00

osx_notifications: Show notification only if VLC in background, cleanup

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.

Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
This commit is contained in:
Marvin Scholz 2015-10-22 18:18:51 +02:00 committed by Jean-Baptiste Kempf
parent 13747555fd
commit a4baa14604

View File

@ -86,7 +86,6 @@
NSString *notificationType; NSString *notificationType;
NSMutableDictionary *registrationDictionary; NSMutableDictionary *registrationDictionary;
id lastNotification; id lastNotification;
BOOL isInForeground;
intf_thread_t *interfaceThread; intf_thread_t *interfaceThread;
} }
@ -289,21 +288,6 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
registrationDictionary = nil; registrationDictionary = nil;
interfaceThread = thread; 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; return self;
} }
@ -317,7 +301,6 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
removeDeliveredNotification:(NSUserNotification *)lastNotification]; removeDeliveredNotification:(NSUserNotification *)lastNotification];
[lastNotification release]; [lastNotification release];
} }
[[NSNotificationCenter defaultCenter] removeObserver:self];
} }
#endif #endif
@ -356,6 +339,10 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
andArtUrl:(const char *)url andArtUrl:(const char *)url
{ {
@autoreleasepool { @autoreleasepool {
// Do not notify if in foreground
if ([NSApplication sharedApplication].active)
return;
// Init Cover // Init Cover
NSData *coverImageData = nil; NSData *coverImageData = nil;
NSImage *coverImage = nil; NSImage *coverImage = nil;
@ -375,6 +362,7 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
} else { } else {
// Without title, notification makes no sense, so return here // Without title, notification makes no sense, so return here
// title should never be empty, but better check than crash. // title should never be empty, but better check than crash.
[coverImage release];
return; return;
} }
if (artist) if (artist)
@ -447,17 +435,11 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
return applicationName; 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 #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
- (void)userNotificationCenter:(NSUserNotificationCenter *)center - (void)userNotificationCenter:(NSUserNotificationCenter *)center
didActivateNotification:(NSUserNotification *)notification didActivateNotification:(NSUserNotification *)notification
{ {
// Skip to next song
if (notification.activationType == NSUserNotificationActivationTypeActionButtonClicked) { if (notification.activationType == NSUserNotificationActivationTypeActionButtonClicked) {
playlist_Next(pl_Get(interfaceThread)); playlist_Next(pl_Get(interfaceThread));
} }
@ -474,12 +456,5 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
[notification retain]; [notification retain];
lastNotification = notification; lastNotification = notification;
} }
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
shouldPresentNotification:(NSUserNotification *)notification
{
// Show notifications regardless if App in foreground or background
return YES;
}
#endif #endif
@end @end