Files
electron/shell/browser/notifications/mac/notification_presenter_mac.h
Developer-Ecosystem-Engineering d6fc627ba5 feat: replace deprecated NSUserNotifications with User Notifications (#47817)
* refactor: replace deprecated NSUserNotifications with User Notifications

Removes deprecated NSUserNotification API, now using User Notifications

It replaces API calls for generating, scheduling, and receiving native
macOS notifications with equivalent API calls from the new framework,
or functionally equivalent implementations.

To preserve the existing Notification module API, special handling was
required in certain cases:

  - Dynamically declared notification actions
    Typically, notification actions should be declared at app launch time
    when using the User Notifications framework. However, this isn’t
    compatible with Electron’s architecture. Instead, we dynamically
    declare new notifications actions when necessary and carefully manage
    the existing actions registered at runtime.

  - Localizations for ‘Reply’ and ‘Show’ labels
    New translation files are added and processed through GRIT to add
    localizations for “Reply” and “Show” button labels which were
    initially supplied by the NSUserNotification framework.

* Use NotificationImageRetainer pattern from //chrome

* build: fix lint

* build: update config to handle --translate-gender for pak files

* test: also sign on arm64

* fix: add error handling for scheduling notification

* docs: add details to breaking changes

* docs: clarify breaking change details

* docs: add details for notifications tutorial and API documentation

---------

Co-authored-by: Keeley Hammond <khammond@slack-corp.com>
2026-03-05 11:57:19 -08:00

45 lines
1.5 KiB
Objective-C

// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Copyright (c) 2013 Adam Roben <adam@roben.org>. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE-CHROMIUM file.
#ifndef ELECTRON_SHELL_BROWSER_NOTIFICATIONS_MAC_NOTIFICATION_PRESENTER_MAC_H_
#define ELECTRON_SHELL_BROWSER_NOTIFICATIONS_MAC_NOTIFICATION_PRESENTER_MAC_H_
#include "chrome/common/notifications/notification_image_retainer.h"
#include "shell/browser/notifications/mac/notification_center_delegate.h"
#include "shell/browser/notifications/notification_presenter.h"
#import <UserNotifications/UserNotifications.h>
namespace electron {
class CocoaNotification;
class NotificationPresenterMac : public NotificationPresenter {
public:
CocoaNotification* GetNotification(
UNNotificationRequest* un_notification_request);
NotificationPresenterMac();
~NotificationPresenterMac() override;
NotificationImageRetainer* image_retainer() { return image_retainer_.get(); }
scoped_refptr<base::SequencedTaskRunner> image_task_runner() {
return image_task_runner_;
}
private:
// NotificationPresenter
Notification* CreateNotificationObject(
NotificationDelegate* delegate) override;
NotificationCenterDelegate* __strong notification_center_delegate_;
std::unique_ptr<NotificationImageRetainer> image_retainer_;
scoped_refptr<base::SequencedTaskRunner> image_task_runner_;
};
} // namespace electron
#endif // ELECTRON_SHELL_BROWSER_NOTIFICATIONS_MAC_NOTIFICATION_PRESENTER_MAC_H_