Skip to content

Commit 6cdfb43

Browse files
Emit a close event
1 parent 9aa6b83 commit 6cdfb43

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

atom/browser/api/atom_api_notification.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ void Notification::OnShown() {
126126
Emit("show");
127127
}
128128

129+
void Notification::OnClosed() {
130+
Emit("close");
131+
}
132+
129133
void Notification::NotifyPropsUpdated() {}
130134

131135
// Showing notifications

atom/browser/api/atom_api_notification.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Notification : public mate::TrackableObject<Notification>,
3535
void OnClicked() override;
3636
void OnReplied(std::string reply) override;
3737
void OnShown() override;
38+
void OnClosed() override;
3839

3940
protected:
4041
Notification(v8::Isolate* isolate,

atom/browser/ui/notification_delegate_adapter.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ void AtomNotificationDelegateAdapter::NotificationClick() {
2323
void AtomNotificationDelegateAdapter::NotificationReplied(std::string reply) {
2424
observer_->OnReplied(reply);
2525
}
26-
void AtomNotificationDelegateAdapter::NotificationDestroyed() {}
26+
void AtomNotificationDelegateAdapter::NotificationDestroyed() {
27+
observer_->OnClosed();
28+
}
2729
void AtomNotificationDelegateAdapter::NotificationFailed() {}
2830

2931
} // namespace atom

atom/browser/ui/notification_observer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class NotifictionObserver {
1414
virtual void OnClicked() {}
1515
virtual void OnReplied(std::string reply) {}
1616
virtual void OnShown() {}
17+
virtual void OnClosed() {}
1718

1819
protected:
1920
virtual ~NotifictionObserver() {}

docs/api/notification.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,34 @@ Objects created with `new Notification` emit the following events:
3737
**Note:** Some events are only available on specific operating systems and are
3838
labeled as such.
3939

40-
#### Event: 'click'
40+
#### Event: 'show'
4141

4242
Returns:
4343

4444
* `event` Event
4545

46-
Emitted when the document changed its title, calling `event.preventDefault()`
47-
will prevent the native window's title from changing.
46+
Emitted when the notification is shown to the user, note this could be fired
47+
multiple times as a notification can be shown multiple times through the
48+
`show()` method.
4849

49-
#### Event: 'close'
50+
#### Event: 'click'
5051

5152
Returns:
5253

5354
* `event` Event
5455

55-
Emitted when the notification is shown to the user, note this could be fired
56-
multiple times as a notification can be shown multiple times through the
57-
`show()` method.
56+
Emitted when the notification is clicked by the user.
5857

59-
#### Event: 'click'
58+
#### Event: 'close'
6059

6160
Returns:
6261

6362
* `event` Event
6463

65-
Emitted when the notification is clicked by the user.
64+
Emitted when the notification is closed by manual intervention from the user.
65+
66+
This event is not guarunteed to be emitted in all cases where the notification
67+
is closed.
6668

6769
#### Event: 'reply' _macOS_
6870

0 commit comments

Comments
 (0)