From fe9069c02806fc7dabc8a9b599f4f725b3a755eb Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Fri, 27 Oct 2017 16:22:21 +1300 Subject: [PATCH 1/3] Close the previous notification on multiple calls to show --- atom/browser/api/atom_api_notification.cc | 9 +++++++++ docs/api/notification.md | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/atom/browser/api/atom_api_notification.cc b/atom/browser/api/atom_api_notification.cc index ef5b9ce1296a..d7da05a1fe8a 100644 --- a/atom/browser/api/atom_api_notification.cc +++ b/atom/browser/api/atom_api_notification.cc @@ -175,8 +175,16 @@ void Notification::NotificationDestroyed() { void Notification::NotificationClosed() { } +void Notification::Close() { + if (notification_) { + notification_->Dismiss(); + notification_.reset(); + } +} + // Showing notifications void Notification::Show() { + Close(); if (presenter_) { notification_ = presenter_->CreateNotification(this); if (notification_) { @@ -207,6 +215,7 @@ void Notification::BuildPrototype(v8::Isolate* isolate, mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) .MakeDestroyable() .SetMethod("show", &Notification::Show) + .SetMethod("close", &Notification::Close) .SetProperty("title", &Notification::GetTitle, &Notification::SetTitle) .SetProperty("subtitle", &Notification::GetSubtitle, &Notification::SetSubtitle) diff --git a/docs/api/notification.md b/docs/api/notification.md index 402bbb69db71..f0b39e7b6b5f 100644 --- a/docs/api/notification.md +++ b/docs/api/notification.md @@ -104,6 +104,10 @@ HTML5 Notification implementation, simply instantiating a `new Notification` doe not immediately show it to the user, you need to call this method before the OS will display it. +#### `notification.close()` + +Dismisses the notification + ### Playing Sounds On macOS, you can specify the name of the sound you'd like to play when the From 8719e9f09813755a6395ab7ec0959baec68de9a8 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Fri, 27 Oct 2017 16:27:37 +1300 Subject: [PATCH 2/3] Definitely didn't forget to push the header file --- atom/browser/api/atom_api_notification.h | 1 + 1 file changed, 1 insertion(+) diff --git a/atom/browser/api/atom_api_notification.h b/atom/browser/api/atom_api_notification.h index d4679e7c2c90..50197350bc5e 100644 --- a/atom/browser/api/atom_api_notification.h +++ b/atom/browser/api/atom_api_notification.h @@ -45,6 +45,7 @@ class Notification : public mate::TrackableObject, ~Notification() override; void Show(); + void Close(); // Prop Getters base::string16 GetTitle() const; From 2e487adf8aaf56f1cbccefd47a35877d8ec652e5 Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Fri, 27 Oct 2017 12:17:30 -0700 Subject: [PATCH 3/3] :memo: Add a line to the docs --- docs/api/notification.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/api/notification.md b/docs/api/notification.md index f0b39e7b6b5f..c73678d7984c 100644 --- a/docs/api/notification.md +++ b/docs/api/notification.md @@ -104,9 +104,12 @@ HTML5 Notification implementation, simply instantiating a `new Notification` doe not immediately show it to the user, you need to call this method before the OS will display it. +If the notification has been shown before, this method will dismiss the previously +shown notification and create a new one with identical properties. + #### `notification.close()` -Dismisses the notification +Dismisses the notification. ### Playing Sounds