From 0b23c7d5edaa545b2f61e5c9ad22d20d703c72d3 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Tue, 19 Mar 2019 14:44:54 -0700 Subject: [PATCH] fix: use a more unique identifier for NSUserNotification instances So although apple has it documented that notifications with duplicate identifiers in the same session won't be presented. They apparently forgot to mention that macOS also non-deterministically and without any errors, logs or warnings will also not present some notifications in future sessions if they have a previously used identifier. As such, we're going to truly randomize these identifiers so they are unique between apps and sessions. The identifier now consists of a randomly generated UUID and the app bundle id. --- atom/browser/notifications/mac/cocoa_notification.mm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/atom/browser/notifications/mac/cocoa_notification.mm b/atom/browser/notifications/mac/cocoa_notification.mm index 7aefdd13af58f..caaca8a283429 100644 --- a/atom/browser/notifications/mac/cocoa_notification.mm +++ b/atom/browser/notifications/mac/cocoa_notification.mm @@ -13,8 +13,6 @@ namespace atom { -int g_identifier_ = 1; - CocoaNotification::CocoaNotification(NotificationDelegate* delegate, NotificationPresenter* presenter) : Notification(delegate, presenter) {} @@ -29,7 +27,9 @@ notification_.reset([[NSUserNotification alloc] init]); NSString* identifier = - [NSString stringWithFormat:@"ElectronNotification%d", g_identifier_++]; + [NSString stringWithFormat:@"%@:notification:%@", + [[NSBundle mainBundle] bundleIdentifier], + [[[NSUUID alloc] init] UUIDString]]; [notification_ setTitle:base::SysUTF16ToNSString(options.title)]; [notification_ setSubtitle:base::SysUTF16ToNSString(options.subtitle)];