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