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:
parent
d2282ac51a
commit
b43859f098
9 changed files with 282 additions and 219 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ class Notification : public gin::Wrappable<Notification>,
|
|||
void NotificationDisplayed() override;
|
||||
void NotificationDestroyed() override;
|
||||
void NotificationClosed() override;
|
||||
void NotificationFailed(const std::string& error) override;
|
||||
|
||||
// gin::Wrappable
|
||||
static gin::WrapperInfo kWrapperInfo;
|
||||
|
@ -75,6 +76,7 @@ class Notification : public gin::Wrappable<Notification>,
|
|||
base::string16 GetSound() const;
|
||||
std::vector<electron::NotificationAction> GetActions() const;
|
||||
base::string16 GetCloseButtonText() const;
|
||||
base::string16 GetToastXml() const;
|
||||
|
||||
// Prop Setters
|
||||
void SetTitle(const base::string16& new_title);
|
||||
|
@ -88,6 +90,7 @@ class Notification : public gin::Wrappable<Notification>,
|
|||
void SetSound(const base::string16& sound);
|
||||
void SetActions(const std::vector<electron::NotificationAction>& actions);
|
||||
void SetCloseButtonText(const base::string16& text);
|
||||
void SetToastXml(const base::string16& text);
|
||||
|
||||
private:
|
||||
base::string16 title_;
|
||||
|
@ -104,6 +107,7 @@ class Notification : public gin::Wrappable<Notification>,
|
|||
base::string16 urgency_;
|
||||
std::vector<electron::NotificationAction> actions_;
|
||||
base::string16 close_button_text_;
|
||||
base::string16 toast_xml_;
|
||||
|
||||
electron::NotificationPresenter* presenter_;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue