2015-12-24 13:55:18 +00:00
|
|
|
// Copyright (c) 2015 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2017-05-18 22:58:12 +00:00
|
|
|
#include "brightray/browser/mac/notification_center_delegate.h"
|
2015-12-24 13:55:18 +00:00
|
|
|
|
2017-05-18 22:58:12 +00:00
|
|
|
#include "brightray/browser/mac/cocoa_notification.h"
|
|
|
|
#include "brightray/browser/mac/notification_presenter_mac.h"
|
2015-12-24 13:55:18 +00:00
|
|
|
|
2015-12-25 02:16:07 +00:00
|
|
|
@implementation NotificationCenterDelegate
|
|
|
|
|
2018-04-20 18:47:04 +00:00
|
|
|
- (instancetype)initWithPresenter:
|
|
|
|
(brightray::NotificationPresenterMac*)presenter {
|
2015-12-25 02:16:07 +00:00
|
|
|
self = [super init];
|
|
|
|
if (!self)
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
presenter_ = presenter;
|
|
|
|
return self;
|
|
|
|
}
|
2015-12-24 13:55:18 +00:00
|
|
|
|
|
|
|
- (void)userNotificationCenter:(NSUserNotificationCenter*)center
|
|
|
|
didDeliverNotification:(NSUserNotification*)notif {
|
2018-04-17 22:41:47 +00:00
|
|
|
auto* notification = presenter_->GetNotification(notif);
|
2017-05-30 09:06:51 +00:00
|
|
|
if (notification)
|
2016-04-15 07:14:13 +00:00
|
|
|
notification->NotificationDisplayed();
|
2015-12-24 13:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)userNotificationCenter:(NSUserNotificationCenter*)center
|
2018-04-20 18:47:04 +00:00
|
|
|
didActivateNotification:(NSUserNotification*)notif {
|
2018-04-17 22:41:47 +00:00
|
|
|
auto* notification = presenter_->GetNotification(notif);
|
2017-12-13 18:31:59 +00:00
|
|
|
|
|
|
|
if (getenv("ELECTRON_DEBUG_NOTIFICATIONS")) {
|
2018-04-20 18:47:04 +00:00
|
|
|
LOG(INFO) << "Notification activated (" << [notif.identifier UTF8String]
|
|
|
|
<< ")";
|
2017-12-13 18:31:59 +00:00
|
|
|
}
|
|
|
|
|
2017-05-29 10:02:33 +00:00
|
|
|
if (notification) {
|
2018-04-20 18:47:04 +00:00
|
|
|
// Ref:
|
|
|
|
// https://developer.apple.com/documentation/foundation/nsusernotificationactivationtype?language=objc
|
|
|
|
if (notif.activationType ==
|
|
|
|
NSUserNotificationActivationTypeContentsClicked) {
|
2018-01-16 04:50:03 +00:00
|
|
|
notification->NotificationClicked();
|
2018-04-20 18:47:04 +00:00
|
|
|
} else if (notif.activationType ==
|
|
|
|
NSUserNotificationActivationTypeActionButtonClicked) {
|
2018-01-17 03:07:54 +00:00
|
|
|
notification->NotificationActivated();
|
2018-04-20 18:47:04 +00:00
|
|
|
} else if (notif.activationType ==
|
|
|
|
NSUserNotificationActivationTypeReplied) {
|
2018-01-16 04:50:03 +00:00
|
|
|
notification->NotificationReplied([notif.response.string UTF8String]);
|
2018-04-17 23:45:26 +00:00
|
|
|
} else {
|
2018-06-20 09:34:04 +00:00
|
|
|
if (@available(macOS 10.10, *)) {
|
|
|
|
if (notif.activationType ==
|
|
|
|
NSUserNotificationActivationTypeAdditionalActionClicked) {
|
|
|
|
notification->NotificationActivated(
|
|
|
|
[notif additionalActivationAction]);
|
|
|
|
}
|
2018-04-17 23:45:26 +00:00
|
|
|
}
|
2017-05-29 10:02:33 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-24 13:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center
|
|
|
|
shouldPresentNotification:(NSUserNotification*)notification {
|
|
|
|
// Display notifications even if the app is active.
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|