File tree Expand file tree Collapse file tree 3 files changed +18
-5
lines changed
shell/browser/notifications Expand file tree Collapse file tree 3 files changed +18
-5
lines changed Original file line number Diff line number Diff line change 111
111
112
112
NotificationDismissed ();
113
113
114
- this ->LogAction (" dismissed" );
115
-
116
114
notification_.reset (nil );
117
115
}
118
116
163
161
}
164
162
165
163
void CocoaNotification::LogAction (const char * action) {
166
- if (getenv (" ELECTRON_DEBUG_NOTIFICATIONS" )) {
164
+ if (getenv (" ELECTRON_DEBUG_NOTIFICATIONS" ) && notification_ ) {
167
165
NSString * identifier = [notification_ valueForKey: @" identifier" ];
166
+ DCHECK (identifier);
168
167
LOG (INFO) << " Notification " << action << " (" << [identifier UTF8String ]
169
168
<< " )" ;
170
169
}
Original file line number Diff line number Diff line change @@ -37,8 +37,11 @@ void NotificationPresenter::CloseNotificationWithId(
37
37
[¬ification_id](const Notification* n) {
38
38
return n->notification_id () == notification_id;
39
39
});
40
- if (it != notifications_.end ())
41
- (*it)->Dismiss ();
40
+ if (it != notifications_.end ()) {
41
+ Notification* notification = (*it);
42
+ notification->Dismiss ();
43
+ notifications_.erase (notification);
44
+ }
42
45
}
43
46
44
47
} // namespace electron
Original file line number Diff line number Diff line change @@ -86,8 +86,19 @@ void PlatformNotificationService::DisplayNotification(
86
86
auto * presenter = browser_client_->GetNotificationPresenter ();
87
87
if (!presenter)
88
88
return ;
89
+
90
+ // If a new notification is created with the same tag as an
91
+ // existing one, replace the old notification with the new one.
92
+ // The notification_id is generated from the tag, so the only way a
93
+ // notification will be closed as a result of this call is if one with
94
+ // the same tag is already extant.
95
+ //
96
+ // See: https://notifications.spec.whatwg.org/#showing-a-notification
97
+ presenter->CloseNotificationWithId (notification_id);
98
+
89
99
NotificationDelegateImpl* delegate =
90
100
new NotificationDelegateImpl (notification_id);
101
+
91
102
auto notification = presenter->CreateNotification (delegate, notification_id);
92
103
if (notification) {
93
104
browser_client_->WebNotificationAllowed (
You can’t perform that action at this time.
0 commit comments