Skip to content

Commit fe9069c

Browse files
Close the previous notification on multiple calls to show
1 parent e2d5aaf commit fe9069c

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

atom/browser/api/atom_api_notification.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,16 @@ void Notification::NotificationDestroyed() {
175175
void Notification::NotificationClosed() {
176176
}
177177

178+
void Notification::Close() {
179+
if (notification_) {
180+
notification_->Dismiss();
181+
notification_.reset();
182+
}
183+
}
184+
178185
// Showing notifications
179186
void Notification::Show() {
187+
Close();
180188
if (presenter_) {
181189
notification_ = presenter_->CreateNotification(this);
182190
if (notification_) {
@@ -207,6 +215,7 @@ void Notification::BuildPrototype(v8::Isolate* isolate,
207215
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
208216
.MakeDestroyable()
209217
.SetMethod("show", &Notification::Show)
218+
.SetMethod("close", &Notification::Close)
210219
.SetProperty("title", &Notification::GetTitle, &Notification::SetTitle)
211220
.SetProperty("subtitle", &Notification::GetSubtitle,
212221
&Notification::SetSubtitle)

docs/api/notification.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ HTML5 Notification implementation, simply instantiating a `new Notification` doe
104104
not immediately show it to the user, you need to call this method before the OS
105105
will display it.
106106

107+
#### `notification.close()`
108+
109+
Dismisses the notification
110+
107111
### Playing Sounds
108112

109113
On macOS, you can specify the name of the sound you'd like to play when the

0 commit comments

Comments
 (0)