Skip to content

Commit

Permalink
fix: ensure notification close takes effect
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Jul 2, 2020
1 parent 4c449fb commit c4e3e0c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
19 changes: 19 additions & 0 deletions patches/chromium/notification_provenance.patch
Expand Up @@ -165,3 +165,22 @@ index 6d108f9884f7e8f608b70ec33d286a06346e7456..4650a01c2d090c5957eb7a7e21f12448
const std::string& notification_id,
const GURL& origin,
const blink::PlatformNotificationData& notification_data,
diff --git a/third_party/blink/renderer/modules/notifications/notification.cc b/third_party/blink/renderer/modules/notifications/notification.cc
index 9249243e98bd918be5ff3c07b92a2a91c79307e8..5ff350c0c71deb52c7e674dfeaa4b8fd9a276d8b 100644
--- a/third_party/blink/renderer/modules/notifications/notification.cc
+++ b/third_party/blink/renderer/modules/notifications/notification.cc
@@ -130,12 +130,8 @@ Notification* Notification::Create(ExecutionContext* context,

// TODO(https://crbug.com/595685): Make |token| a constructor parameter
// once persistent notifications have been mojofied too.
- if (notification->tag().IsNull() || notification->tag().IsEmpty()) {
- auto unguessable_token = base::UnguessableToken::Create();
- notification->SetToken(unguessable_token.ToString().c_str());
- } else {
- notification->SetToken(notification->tag());
- }
+ auto unguessable_token = base::UnguessableToken::Create();
+ notification->SetToken(unguessable_token.ToString().c_str());

notification->SchedulePrepareShow();

15 changes: 9 additions & 6 deletions shell/browser/notifications/mac/cocoa_notification.mm
Expand Up @@ -105,15 +105,16 @@
}

void CocoaNotification::Dismiss() {
if (notification_)
if (notification_) {
[NSUserNotificationCenter.defaultUserNotificationCenter
removeDeliveredNotification:notification_];

NotificationDismissed();
NotificationDismissed();

this->LogAction("dismissed");
this->LogAction("dismissed");

notification_.reset(nil);
notification_.reset(nil);
}
}

void CocoaNotification::NotificationDisplayed() {
Expand Down Expand Up @@ -165,8 +166,10 @@
void CocoaNotification::LogAction(const char* action) {
if (getenv("ELECTRON_DEBUG_NOTIFICATIONS")) {
NSString* identifier = [notification_ valueForKey:@"identifier"];
LOG(INFO) << "Notification " << action << " (" << [identifier UTF8String]
<< ")";
if (identifier) {
LOG(INFO) << "Notification " << action << " (" << [identifier UTF8String]
<< ")";
}
}
}

Expand Down

0 comments on commit c4e3e0c

Please sign in to comment.