Show notifications even when the app is focused

It's a little icky to be taking over global state (NSUserNotificationCenter's
delegate) like this, but until we have evidence that it gets in someone's way
it's the pragmatic thing to do.
This commit is contained in:
Adam Roben 2013-03-28 18:08:34 -04:00
parent 651ab18a21
commit 08f393437e
2 changed files with 21 additions and 2 deletions

View file

@ -3,7 +3,9 @@
#import "browser/notification_presenter.h"
#import "base/compiler_specific.h"
#import "base/memory/scoped_nsobject.h"
@class BRYUserNotificationCenterDelegate;
namespace brightray {
@ -16,6 +18,9 @@ class NotificationPresenterMac : public NotificationPresenter {
const content::ShowDesktopNotificationHostMsgParams&,
int render_process_id,
int render_view_id) OVERRIDE;
private:
scoped_nsobject<BRYUserNotificationCenterDelegate> delegate_;
};
}

View file

@ -6,13 +6,18 @@
#import <Foundation/Foundation.h>
@interface BRYUserNotificationCenterDelegate : NSObject <NSUserNotificationCenterDelegate>
@end
namespace brightray {
NotificationPresenter* NotificationPresenter::Create() {
return new NotificationPresenterMac;
}
NotificationPresenterMac::NotificationPresenterMac() {
NotificationPresenterMac::NotificationPresenterMac()
: delegate_([[BRYUserNotificationCenterDelegate alloc] init]) {
NSUserNotificationCenter.defaultUserNotificationCenter.delegate = delegate_;
}
NotificationPresenterMac::~NotificationPresenterMac() {
@ -37,3 +42,12 @@ void NotificationPresenterMac::ShowNotification(
}
}
@implementation BRYUserNotificationCenterDelegate
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification {
// Display notifications even if the app is active.
return YES;
}
@end