From 6cdfb43e4e28e1cb1348322b7e8c449ecc36cdc5 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Mon, 29 May 2017 21:33:43 +1000 Subject: [PATCH] Emit a close event --- atom/browser/api/atom_api_notification.cc | 4 ++++ atom/browser/api/atom_api_notification.h | 1 + .../ui/notification_delegate_adapter.cc | 4 +++- atom/browser/ui/notification_observer.h | 1 + docs/api/notification.md | 22 ++++++++++--------- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/atom/browser/api/atom_api_notification.cc b/atom/browser/api/atom_api_notification.cc index 1ed3a291c2..f5b1fc4ce3 100644 --- a/atom/browser/api/atom_api_notification.cc +++ b/atom/browser/api/atom_api_notification.cc @@ -126,6 +126,10 @@ void Notification::OnShown() { Emit("show"); } +void Notification::OnClosed() { + Emit("close"); +} + void Notification::NotifyPropsUpdated() {} // Showing notifications diff --git a/atom/browser/api/atom_api_notification.h b/atom/browser/api/atom_api_notification.h index 513a9a67fd..5309745a30 100644 --- a/atom/browser/api/atom_api_notification.h +++ b/atom/browser/api/atom_api_notification.h @@ -35,6 +35,7 @@ class Notification : public mate::TrackableObject, void OnClicked() override; void OnReplied(std::string reply) override; void OnShown() override; + void OnClosed() override; protected: Notification(v8::Isolate* isolate, diff --git a/atom/browser/ui/notification_delegate_adapter.cc b/atom/browser/ui/notification_delegate_adapter.cc index b91a1a97d5..0ac9ef1115 100644 --- a/atom/browser/ui/notification_delegate_adapter.cc +++ b/atom/browser/ui/notification_delegate_adapter.cc @@ -23,7 +23,9 @@ void AtomNotificationDelegateAdapter::NotificationClick() { void AtomNotificationDelegateAdapter::NotificationReplied(std::string reply) { observer_->OnReplied(reply); } -void AtomNotificationDelegateAdapter::NotificationDestroyed() {} +void AtomNotificationDelegateAdapter::NotificationDestroyed() { + observer_->OnClosed(); +} void AtomNotificationDelegateAdapter::NotificationFailed() {} } // namespace atom diff --git a/atom/browser/ui/notification_observer.h b/atom/browser/ui/notification_observer.h index 5b1ba053ec..7b4e9acd17 100644 --- a/atom/browser/ui/notification_observer.h +++ b/atom/browser/ui/notification_observer.h @@ -14,6 +14,7 @@ class NotifictionObserver { virtual void OnClicked() {} virtual void OnReplied(std::string reply) {} virtual void OnShown() {} + virtual void OnClosed() {} protected: virtual ~NotifictionObserver() {} diff --git a/docs/api/notification.md b/docs/api/notification.md index abab31df3c..cc8cd7c165 100644 --- a/docs/api/notification.md +++ b/docs/api/notification.md @@ -37,16 +37,7 @@ Objects created with `new Notification` emit the following events: **Note:** Some events are only available on specific operating systems and are labeled as such. -#### Event: 'click' - -Returns: - -* `event` Event - -Emitted when the document changed its title, calling `event.preventDefault()` -will prevent the native window's title from changing. - -#### Event: 'close' +#### Event: 'show' Returns: @@ -64,6 +55,17 @@ Returns: Emitted when the notification is clicked by the user. +#### Event: 'close' + +Returns: + +* `event` Event + +Emitted when the notification is closed by manual intervention from the user. + +This event is not guarunteed to be emitted in all cases where the notification +is closed. + #### Event: 'reply' _macOS_ Returns: