Skip to content

Commit

Permalink
fix: use a more unique identifier for NSUserNotification instances (#…
Browse files Browse the repository at this point in the history
…17483)

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.
  • Loading branch information
trop[bot] authored and MarshallOfSound committed Mar 20, 2019
1 parent ee15295 commit a0d824c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions brightray/browser/mac/cocoa_notification.mm
Expand Up @@ -13,8 +13,6 @@

namespace brightray {

int g_identifier_ = 1;

CocoaNotification::CocoaNotification(NotificationDelegate* delegate,
NotificationPresenter* presenter)
: Notification(delegate, presenter) {}
Expand All @@ -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)];
Expand Down

0 comments on commit a0d824c

Please sign in to comment.