Skip to content

Commit

Permalink
osx_notifications: Show notification only if VLC in background, cleanup
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ePirat authored and jbkempf committed Oct 23, 2015
1 parent 1374755 commit a4baa14
Showing 1 changed file with 6 additions and 31 deletions.
37 changes: 6 additions & 31 deletions modules/notify/osx_notifications.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ @interface VLCGrowlDelegate : NSObject <GrowlApplicationBridgeDelegate>
NSString *notificationType;
NSMutableDictionary *registrationDictionary;
id lastNotification;
BOOL isInForeground;
intf_thread_t *interfaceThread;
}

Expand Down Expand Up @@ -289,21 +288,6 @@ - (id)initWithInterfaceThread:(intf_thread_t *)thread {
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;
}

Expand All @@ -317,7 +301,6 @@ - (void)dealloc
removeDeliveredNotification:(NSUserNotification *)lastNotification];
[lastNotification release];
}
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
#endif

Expand Down Expand Up @@ -356,6 +339,10 @@ - (void)notifyWithTitle:(const char *)title
andArtUrl:(const char *)url
{
@autoreleasepool {
// Do not notify if in foreground
if ([NSApplication sharedApplication].active)
return;

// Init Cover
NSData *coverImageData = nil;
NSImage *coverImage = nil;
Expand All @@ -375,6 +362,7 @@ - (void)notifyWithTitle:(const char *)title
} 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)
Expand Down Expand Up @@ -447,17 +435,11 @@ - (NSString *)applicationNameForGrowl
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));
}
Expand All @@ -474,12 +456,5 @@ - (void)userNotificationCenter:(NSUserNotificationCenter *)center
[notification retain];
lastNotification = notification;
}

- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
shouldPresentNotification:(NSUserNotification *)notification
{
// Show notifications regardless if App in foreground or background
return YES;
}
#endif
@end

0 comments on commit a4baa14

Please sign in to comment.