From 08f393437e0d3050881144bbb8adc8a2e6bf4bc8 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 28 Mar 2013 18:08:34 -0400 Subject: [PATCH] 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. --- brightray/browser/notification_presenter_mac.h | 7 ++++++- brightray/browser/notification_presenter_mac.mm | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/brightray/browser/notification_presenter_mac.h b/brightray/browser/notification_presenter_mac.h index 3334c5f3c6b7..77da8cf0766c 100644 --- a/brightray/browser/notification_presenter_mac.h +++ b/brightray/browser/notification_presenter_mac.h @@ -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 delegate_; }; } diff --git a/brightray/browser/notification_presenter_mac.mm b/brightray/browser/notification_presenter_mac.mm index 2b07ae906273..dc914bb9352b 100644 --- a/brightray/browser/notification_presenter_mac.mm +++ b/brightray/browser/notification_presenter_mac.mm @@ -6,13 +6,18 @@ #import +@interface BRYUserNotificationCenterDelegate : NSObject +@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