From e5d4574d3a98bad4161e6f80613145d0bacafe2a Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Sat, 7 Oct 2017 14:45:46 +1100 Subject: [PATCH] Use NSUserNotification identifiers to uniquely find the correct notification from CocoaNotification --- brightray/browser/mac/cocoa_notification.mm | 4 ++++ brightray/browser/mac/notification_presenter_mac.mm | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/brightray/browser/mac/cocoa_notification.mm b/brightray/browser/mac/cocoa_notification.mm index cd7b69ef4058..5e51974b3e46 100644 --- a/brightray/browser/mac/cocoa_notification.mm +++ b/brightray/browser/mac/cocoa_notification.mm @@ -13,6 +13,8 @@ namespace brightray { +int g_identifier_ = 1; + CocoaNotification::CocoaNotification(NotificationDelegate* delegate, NotificationPresenter* presenter) : Notification(delegate, presenter) { @@ -29,6 +31,8 @@ void CocoaNotification::Show(const NotificationOptions& options) { [notification_ setTitle:base::SysUTF16ToNSString(options.title)]; [notification_ setSubtitle:base::SysUTF16ToNSString(options.subtitle)]; [notification_ setInformativeText:base::SysUTF16ToNSString(options.msg)]; + [notification_ setIdentifier:[NSString stringWithFormat:@"%s%d", "ElectronNotification", g_identifier_]]; + g_identifier_++; if ([notification_ respondsToSelector:@selector(setContentImage:)] && !options.icon.drawsNothing()) { diff --git a/brightray/browser/mac/notification_presenter_mac.mm b/brightray/browser/mac/notification_presenter_mac.mm index 5afadab7ebb4..b89030573462 100644 --- a/brightray/browser/mac/notification_presenter_mac.mm +++ b/brightray/browser/mac/notification_presenter_mac.mm @@ -18,7 +18,8 @@ CocoaNotification* NotificationPresenterMac::GetNotification( NSUserNotification* ns_notification) { for (Notification* notification : notifications()) { auto native_notification = static_cast(notification); - if ([native_notification->notification() isEqual:ns_notification]) + if ([native_notification->notification().identifier + isEqual:ns_notification.identifier]) return native_notification; } return nullptr;