2015-12-25 02:16:07 +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.
|
2015-12-24 13:55:18 +00:00
|
|
|
|
2017-05-18 22:58:12 +00:00
|
|
|
#include "brightray/browser/mac/notification_presenter_mac.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_center_delegate.h"
|
2015-12-24 13:55:18 +00:00
|
|
|
|
|
|
|
namespace brightray {
|
|
|
|
|
2015-12-25 02:16:07 +00:00
|
|
|
// static
|
2015-12-24 13:55:18 +00:00
|
|
|
NotificationPresenter* NotificationPresenter::Create() {
|
|
|
|
return new NotificationPresenterMac;
|
|
|
|
}
|
|
|
|
|
2015-12-25 02:16:07 +00:00
|
|
|
CocoaNotification* NotificationPresenterMac::GetNotification(
|
|
|
|
NSUserNotification* ns_notification) {
|
|
|
|
for (Notification* notification : notifications()) {
|
2018-04-17 22:41:47 +00:00
|
|
|
auto* native_notification = static_cast<CocoaNotification*>(notification);
|
2017-10-07 03:45:46 +00:00
|
|
|
if ([native_notification->notification().identifier
|
|
|
|
isEqual:ns_notification.identifier])
|
2015-12-25 02:16:07 +00:00
|
|
|
return native_notification;
|
|
|
|
}
|
2017-12-13 18:31:59 +00:00
|
|
|
|
|
|
|
if (getenv("ELECTRON_DEBUG_NOTIFICATIONS")) {
|
2017-12-13 22:47:23 +00:00
|
|
|
LOG(INFO) << "Could not find notification for " << [ns_notification.identifier UTF8String];
|
2017-12-13 18:31:59 +00:00
|
|
|
}
|
|
|
|
|
2015-12-25 02:16:07 +00:00
|
|
|
return nullptr;
|
2015-12-24 13:55:18 +00:00
|
|
|
}
|
|
|
|
|
2015-12-25 02:16:07 +00:00
|
|
|
NotificationPresenterMac::NotificationPresenterMac()
|
|
|
|
: notification_center_delegate_(
|
|
|
|
[[NotificationCenterDelegate alloc] initWithPresenter:this]) {
|
|
|
|
NSUserNotificationCenter.defaultUserNotificationCenter.delegate =
|
|
|
|
notification_center_delegate_;
|
2015-12-24 13:55:18 +00:00
|
|
|
}
|
|
|
|
|
2015-12-25 02:16:07 +00:00
|
|
|
NotificationPresenterMac::~NotificationPresenterMac() {
|
|
|
|
NSUserNotificationCenter.defaultUserNotificationCenter.delegate = nil;
|
2015-12-24 13:55:18 +00:00
|
|
|
}
|
|
|
|
|
2017-04-03 08:38:21 +00:00
|
|
|
Notification* NotificationPresenterMac::CreateNotificationObject(
|
|
|
|
NotificationDelegate* delegate) {
|
2017-01-10 15:34:41 +00:00
|
|
|
return new CocoaNotification(delegate, this);
|
|
|
|
}
|
|
|
|
|
2015-12-24 13:55:18 +00:00
|
|
|
} // namespace brightray
|