From 60a6b2b0c38e8ea54a0d47735b1a7ec18d2460c4 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Tue, 5 Jan 2016 13:32:46 +0100 Subject: [PATCH] OS X: Also show desktop notifications when app is active --- src/gui/systray.mm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/gui/systray.mm b/src/gui/systray.mm index fea8db13d..ea30a3864 100644 --- a/src/gui/systray.mm +++ b/src/gui/systray.mm @@ -2,6 +2,19 @@ #include #import +@interface NotificationCenterDelegate : NSObject +@end +@implementation NotificationCenterDelegate +// Always show, even if app is active at the moment. +- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center + shouldPresentNotification:(NSUserNotification *)notification +{ + Q_UNUSED(center); + Q_UNUSED(notification); + return YES; +} +@end + namespace OCC { bool canOsXSendUserNotification() @@ -15,6 +28,12 @@ void sendOsXUserNotification(const QString &title, const QString &message) Class cuserNotificationCenter = NSClassFromString(@"NSUserNotificationCenter"); id userNotificationCenter = [cuserNotificationCenter defaultUserNotificationCenter]; + static dispatch_once_t once; + dispatch_once(&once, ^{ + id delegate = [[NotificationCenterDelegate alloc] init]; + [userNotificationCenter setDelegate:delegate]; + }); + Class cuserNotification = NSClassFromString(@"NSUserNotification"); id notification = [[cuserNotification alloc] init]; [notification setTitle:[NSString stringWithUTF8String:title.toUtf8().data()]]; -- 2.30.2