electron/brightray/browser/mac/notification_presenter_mac.mm

43 lines
1.3 KiB
Text
Raw Normal View History

// 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
#include "browser/mac/notification_presenter_mac.h"
2015-12-24 13:55:18 +00:00
#include "browser/mac/cocoa_notification.h"
#include "browser/mac/notification_center_delegate.h"
2015-12-24 13:55:18 +00:00
namespace brightray {
// static
2015-12-24 13:55:18 +00:00
NotificationPresenter* NotificationPresenter::Create() {
return new NotificationPresenterMac;
}
CocoaNotification* NotificationPresenterMac::GetNotification(
NSUserNotification* ns_notification) {
for (Notification* notification : notifications()) {
auto native_notification = static_cast<CocoaNotification*>(notification);
if ([native_notification->notification() isEqual:ns_notification])
return native_notification;
}
return nullptr;
2015-12-24 13:55:18 +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
}
NotificationPresenterMac::~NotificationPresenterMac() {
NSUserNotificationCenter.defaultUserNotificationCenter.delegate = nil;
2015-12-24 13:55:18 +00:00
}
Notification* NotificationPresenterMac::CreateNotificationObject(NotificationDelegate* delegate) {
return new CocoaNotification(delegate, this);
}
2015-12-24 13:55:18 +00:00
} // namespace brightray