mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-17 12:02:48 +01:00
Use notification center on OS X when available.
This commit is contained in:
parent
0fae2e1ae1
commit
340e6dabce
@ -23,14 +23,20 @@ class PlatformInterface;
|
||||
}
|
||||
|
||||
- (id) initWithHandler: (PlatformInterface*)handler;
|
||||
|
||||
// NSApplicationDelegate
|
||||
- (BOOL) applicationShouldHandleReopen: (NSApplication*)app hasVisibleWindows:(BOOL)flag;
|
||||
- (NSMenu*) applicationDockMenu: (NSApplication*)sender;
|
||||
- (void)applicationDidFinishLaunching:(NSNotification*)aNotification;
|
||||
- (NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication*)sender;
|
||||
|
||||
// NSUserNotificationCenterDelegate
|
||||
- (BOOL) userNotificationCenter: (id)center
|
||||
shouldPresentNotification: (id)notification;
|
||||
|
||||
- (void) setDockMenu: (NSMenu*)menu;
|
||||
- (MacGlobalShortcutBackend*) shortcut_handler;
|
||||
- (void) setShortcutHandler: (MacGlobalShortcutBackend*)backend;
|
||||
- (void)applicationDidFinishLaunching:(NSNotification*)aNotification;
|
||||
- (NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication*)sender;
|
||||
- (void) mediaKeyTap: (SPMediaKeyTap*)keyTap receivedMediaKeyEvent:(NSEvent*)event;
|
||||
@end
|
||||
|
||||
|
@ -200,6 +200,12 @@ static BreakpadRef InitBreakpad() {
|
||||
#endif
|
||||
return NSTerminateNow;
|
||||
}
|
||||
|
||||
- (BOOL) userNotificationCenter: (id)center shouldPresentNotification: (id)notification {
|
||||
// Always show notifications, even if Clementine is in the foreground.
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation MacApplication
|
||||
@ -232,6 +238,12 @@ static BreakpadRef InitBreakpad() {
|
||||
// this makes sure the delegate's shortcut_handler is set
|
||||
[delegate_ setShortcutHandler:shortcut_handler_];
|
||||
[self setDelegate:delegate_];
|
||||
|
||||
Class notification_center_class = NSClassFromString(@"NSUserNotificationCenter");
|
||||
if (notification_center_class) {
|
||||
id notification_center = [notification_center_class defaultUserNotificationCenter];
|
||||
[notification_center setDelegate: delegate_];
|
||||
}
|
||||
}
|
||||
|
||||
-(void) sendEvent: (NSEvent*)event {
|
||||
|
@ -25,6 +25,7 @@
|
||||
#import <GrowlApplicationBridge.h>
|
||||
|
||||
#include "core/scoped_nsautorelease_pool.h"
|
||||
#include "core/scoped_nsobject.h"
|
||||
|
||||
@interface GrowlInterface :NSObject <GrowlApplicationBridgeDelegate> {
|
||||
}
|
||||
@ -137,8 +138,37 @@ bool OSD::SupportsTrayPopups() {
|
||||
return false;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
bool NotificationCenterSupported() {
|
||||
return NSClassFromString(@"NSUserNotificationCenter");
|
||||
}
|
||||
|
||||
void SendNotificationCenterMessage(NSString* title, NSString* subtitle) {
|
||||
Class clazz = NSClassFromString(@"NSUserNotificationCenter");
|
||||
id notification_center = [clazz defaultUserNotificationCenter];
|
||||
|
||||
Class user_notification_class = NSClassFromString(@"NSUserNotification");
|
||||
id notification = [[user_notification_class alloc] init];
|
||||
[notification setTitle: title];
|
||||
[notification setSubtitle: subtitle];
|
||||
|
||||
[notification_center deliverNotification: notification];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OSD::ShowMessageNative(const QString& summary, const QString& message,
|
||||
const QString& icon, const QImage& image) {
|
||||
Q_UNUSED(icon);
|
||||
|
||||
if (NotificationCenterSupported()) {
|
||||
scoped_nsobject<NSString> mac_message(
|
||||
[[NSString alloc] initWithUTF8String:message.toUtf8().constData()]);
|
||||
scoped_nsobject<NSString> mac_summary(
|
||||
[[NSString alloc] initWithUTF8String:summary.toUtf8().constData()]);
|
||||
SendNotificationCenterMessage(mac_summary.get(), mac_message.get());
|
||||
} else {
|
||||
wrapper_->ShowMessage(summary, message, image);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user