Merge pull request #10944 from electron/fix-notification-ref-crash
Close the previous notification on multiple calls to show
This commit is contained in:
commit
dc8b583363
3 changed files with 17 additions and 0 deletions
|
@ -175,8 +175,16 @@ void Notification::NotificationClosed() {
|
||||||
Emit("close");
|
Emit("close");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Notification::Close() {
|
||||||
|
if (notification_) {
|
||||||
|
notification_->Dismiss();
|
||||||
|
notification_.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Showing notifications
|
// Showing notifications
|
||||||
void Notification::Show() {
|
void Notification::Show() {
|
||||||
|
Close();
|
||||||
if (presenter_) {
|
if (presenter_) {
|
||||||
notification_ = presenter_->CreateNotification(this);
|
notification_ = presenter_->CreateNotification(this);
|
||||||
if (notification_) {
|
if (notification_) {
|
||||||
|
@ -207,6 +215,7 @@ void Notification::BuildPrototype(v8::Isolate* isolate,
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.MakeDestroyable()
|
.MakeDestroyable()
|
||||||
.SetMethod("show", &Notification::Show)
|
.SetMethod("show", &Notification::Show)
|
||||||
|
.SetMethod("close", &Notification::Close)
|
||||||
.SetProperty("title", &Notification::GetTitle, &Notification::SetTitle)
|
.SetProperty("title", &Notification::GetTitle, &Notification::SetTitle)
|
||||||
.SetProperty("subtitle", &Notification::GetSubtitle,
|
.SetProperty("subtitle", &Notification::GetSubtitle,
|
||||||
&Notification::SetSubtitle)
|
&Notification::SetSubtitle)
|
||||||
|
|
|
@ -45,6 +45,7 @@ class Notification : public mate::TrackableObject<Notification>,
|
||||||
~Notification() override;
|
~Notification() override;
|
||||||
|
|
||||||
void Show();
|
void Show();
|
||||||
|
void Close();
|
||||||
|
|
||||||
// Prop Getters
|
// Prop Getters
|
||||||
base::string16 GetTitle() const;
|
base::string16 GetTitle() const;
|
||||||
|
|
|
@ -104,6 +104,13 @@ 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
|
not immediately show it to the user, you need to call this method before the OS
|
||||||
will display it.
|
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.
|
||||||
|
|
||||||
### Playing Sounds
|
### Playing Sounds
|
||||||
|
|
||||||
On macOS, you can specify the name of the sound you'd like to play when the
|
On macOS, you can specify the name of the sound you'd like to play when the
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue