electron/shell/browser/notifications/mac/notification_presenter_mac.mm
trop[bot] 3a4edd7a2b
perf: cache whether or not ELECTRON_DEBUG_NOTIFICATIONS env var is set (#45162)
* perf: cache whether or not ELECTRON_DEBUG_NOTIFICATIONS env var is set

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* chore: remove unused #include

Co-authored-by: Charles Kerr <charles@charleskerr.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
2025-01-09 09:22:58 -06:00

52 lines
1.6 KiB
Text

// Copyright (c) 2015 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "base/logging.h"
#include "shell/browser/notifications/mac/notification_presenter_mac.h"
#include "shell/browser/notifications/mac/cocoa_notification.h"
#include "shell/browser/notifications/mac/notification_center_delegate.h"
namespace electron {
// static
std::unique_ptr<NotificationPresenter> NotificationPresenter::Create() {
return std::make_unique<NotificationPresenterMac>();
}
CocoaNotification* NotificationPresenterMac::GetNotification(
NSUserNotification* ns_notification) {
for (Notification* notification : notifications()) {
auto* native_notification = static_cast<CocoaNotification*>(notification);
if ([native_notification->notification().identifier
isEqual:ns_notification.identifier])
return native_notification;
}
if (electron::debug_notifications) {
LOG(INFO) << "Could not find notification for "
<< [ns_notification.identifier UTF8String];
}
return nullptr;
}
NotificationPresenterMac::NotificationPresenterMac()
: notification_center_delegate_(
[[NotificationCenterDelegate alloc] initWithPresenter:this]) {
NSUserNotificationCenter.defaultUserNotificationCenter.delegate =
notification_center_delegate_;
}
NotificationPresenterMac::~NotificationPresenterMac() {
NSUserNotificationCenter.defaultUserNotificationCenter.delegate = nil;
}
Notification* NotificationPresenterMac::CreateNotificationObject(
NotificationDelegate* delegate) {
return new CocoaNotification(delegate, this);
}
} // namespace electron