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;
|
- (id) initWithHandler: (PlatformInterface*)handler;
|
||||||
|
|
||||||
// NSApplicationDelegate
|
// NSApplicationDelegate
|
||||||
- (BOOL) applicationShouldHandleReopen: (NSApplication*)app hasVisibleWindows:(BOOL)flag;
|
- (BOOL) applicationShouldHandleReopen: (NSApplication*)app hasVisibleWindows:(BOOL)flag;
|
||||||
- (NSMenu*) applicationDockMenu: (NSApplication*)sender;
|
- (NSMenu*) applicationDockMenu: (NSApplication*)sender;
|
||||||
|
- (void)applicationDidFinishLaunching:(NSNotification*)aNotification;
|
||||||
|
- (NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication*)sender;
|
||||||
|
|
||||||
|
// NSUserNotificationCenterDelegate
|
||||||
|
- (BOOL) userNotificationCenter: (id)center
|
||||||
|
shouldPresentNotification: (id)notification;
|
||||||
|
|
||||||
- (void) setDockMenu: (NSMenu*)menu;
|
- (void) setDockMenu: (NSMenu*)menu;
|
||||||
- (MacGlobalShortcutBackend*) shortcut_handler;
|
- (MacGlobalShortcutBackend*) shortcut_handler;
|
||||||
- (void) setShortcutHandler: (MacGlobalShortcutBackend*)backend;
|
- (void) setShortcutHandler: (MacGlobalShortcutBackend*)backend;
|
||||||
- (void)applicationDidFinishLaunching:(NSNotification*)aNotification;
|
|
||||||
- (NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication*)sender;
|
|
||||||
- (void) mediaKeyTap: (SPMediaKeyTap*)keyTap receivedMediaKeyEvent:(NSEvent*)event;
|
- (void) mediaKeyTap: (SPMediaKeyTap*)keyTap receivedMediaKeyEvent:(NSEvent*)event;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -200,6 +200,12 @@ static BreakpadRef InitBreakpad() {
|
|||||||
#endif
|
#endif
|
||||||
return NSTerminateNow;
|
return NSTerminateNow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL) userNotificationCenter: (id)center shouldPresentNotification: (id)notification {
|
||||||
|
// Always show notifications, even if Clementine is in the foreground.
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation MacApplication
|
@implementation MacApplication
|
||||||
@ -232,12 +238,18 @@ static BreakpadRef InitBreakpad() {
|
|||||||
// this makes sure the delegate's shortcut_handler is set
|
// this makes sure the delegate's shortcut_handler is set
|
||||||
[delegate_ setShortcutHandler:shortcut_handler_];
|
[delegate_ setShortcutHandler:shortcut_handler_];
|
||||||
[self setDelegate:delegate_];
|
[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 {
|
-(void) sendEvent: (NSEvent*)event {
|
||||||
// If event tap is not installed, handle events that reach the app instead
|
// If event tap is not installed, handle events that reach the app instead
|
||||||
BOOL shouldHandleMediaKeyEventLocally = ![SPMediaKeyTap usesGlobalMediaKeyTap];
|
BOOL shouldHandleMediaKeyEventLocally = ![SPMediaKeyTap usesGlobalMediaKeyTap];
|
||||||
|
|
||||||
if(shouldHandleMediaKeyEventLocally && [event type] == NSSystemDefined && [event subtype] == SPSystemDefinedEventMediaKeys) {
|
if(shouldHandleMediaKeyEventLocally && [event type] == NSSystemDefined && [event subtype] == SPSystemDefinedEventMediaKeys) {
|
||||||
[(id)[self delegate] mediaKeyTap: nil receivedMediaKeyEvent: event];
|
[(id)[self delegate] mediaKeyTap: nil receivedMediaKeyEvent: event];
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#import <GrowlApplicationBridge.h>
|
#import <GrowlApplicationBridge.h>
|
||||||
|
|
||||||
#include "core/scoped_nsautorelease_pool.h"
|
#include "core/scoped_nsautorelease_pool.h"
|
||||||
|
#include "core/scoped_nsobject.h"
|
||||||
|
|
||||||
@interface GrowlInterface :NSObject <GrowlApplicationBridgeDelegate> {
|
@interface GrowlInterface :NSObject <GrowlApplicationBridgeDelegate> {
|
||||||
}
|
}
|
||||||
@ -137,8 +138,37 @@ bool OSD::SupportsTrayPopups() {
|
|||||||
return false;
|
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,
|
void OSD::ShowMessageNative(const QString& summary, const QString& message,
|
||||||
const QString& icon, const QImage& image) {
|
const QString& icon, const QImage& image) {
|
||||||
Q_UNUSED(icon);
|
Q_UNUSED(icon);
|
||||||
wrapper_->ShowMessage(summary, message, image);
|
|
||||||
|
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