feat: custom toast xml and failure reporting for notifications (#25401)

* allow custom toast xml and report failures

* docs

* tests

* don't use namespaces

* lint doesn't like trailing commas

* addressing feedback
This commit is contained in:
bitdisaster 2020-09-29 12:20:10 -07:00 committed by GitHub
parent d2282ac51a
commit b43859f098
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 282 additions and 219 deletions

View file

@ -72,6 +72,7 @@ Notification::Notification(gin::Arguments* args) {
opts.Get("actions", &actions_);
opts.Get("sound", &sound_);
opts.Get("closeButtonText", &close_button_text_);
opts.Get("toastXml", &toast_xml_);
}
}
@ -135,6 +136,10 @@ base::string16 Notification::GetCloseButtonText() const {
return close_button_text_;
}
base::string16 Notification::GetToastXml() const {
return toast_xml_;
}
// Setters
void Notification::SetTitle(const base::string16& new_title) {
title_ = new_title;
@ -181,6 +186,10 @@ void Notification::SetCloseButtonText(const base::string16& text) {
close_button_text_ = text;
}
void Notification::SetToastXml(const base::string16& new_toast_xml) {
toast_xml_ = new_toast_xml;
}
void Notification::NotificationAction(int index) {
Emit("action", index);
}
@ -197,6 +206,10 @@ void Notification::NotificationDisplayed() {
Emit("show");
}
void Notification::NotificationFailed(const std::string& error) {
Emit("failed", error);
}
void Notification::NotificationDestroyed() {}
void Notification::NotificationClosed() {
@ -231,6 +244,7 @@ void Notification::Show() {
options.sound = sound_;
options.close_button_text = close_button_text_;
options.urgency = urgency_;
options.toast_xml = toast_xml_;
notification_->Show(options);
}
}
@ -265,6 +279,8 @@ v8::Local<v8::ObjectTemplate> Notification::FillObjectTemplate(
&Notification::SetActions)
.SetProperty("closeButtonText", &Notification::GetCloseButtonText,
&Notification::SetCloseButtonText)
.SetProperty("toastXml", &Notification::GetToastXml,
&Notification::SetToastXml)
.Build();
}