From be118d4f13409d235ebced33a92df11770c93625 Mon Sep 17 00:00:00 2001 From: Zhuo Lu Date: Tue, 16 Jan 2018 11:26:41 -0800 Subject: [PATCH] Make it able to set close button text --- atom/browser/api/atom_api_notification.cc | 14 +++++++++++++- atom/browser/api/atom_api_notification.h | 3 +++ brightray/browser/mac/cocoa_notification.mm | 4 ++++ brightray/browser/notification.h | 1 + 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_notification.cc b/atom/browser/api/atom_api_notification.cc index 9bb24df93a6d..b4e94d377b29 100644 --- a/atom/browser/api/atom_api_notification.cc +++ b/atom/browser/api/atom_api_notification.cc @@ -70,6 +70,7 @@ Notification::Notification(v8::Isolate* isolate, opts.Get("hasReply", &has_reply_); opts.Get("actions", &actions_); opts.Get("sound", &sound_); + opts.Get("closeButtonText", &close_button_text_); } } @@ -120,6 +121,10 @@ base::string16 Notification::GetSound() const { return sound_; } +base::string16 Notification::GetCloseButtonText() const { + return close_button_text_; +} + // Setters void Notification::SetTitle(const base::string16& new_title) { title_ = new_title; @@ -154,6 +159,10 @@ void Notification::SetSound(const base::string16& new_sound) { sound_ = new_sound; } +void Notification::SetCloseButtonText(const base::string16& text) { + close_button_text_ = text; +} + void Notification::NotificationAction(int index) { Emit("action", index); } @@ -201,6 +210,7 @@ void Notification::Show() { options.reply_placeholder = reply_placeholder_; options.actions = actions_; options.sound = sound_; + options.close_button_text = close_button_text_; notification_->Show(options); } } @@ -230,7 +240,9 @@ void Notification::BuildPrototype(v8::Isolate* isolate, .SetProperty("actions", &Notification::GetActions, &Notification::SetActions) .SetProperty("sound", &Notification::GetSound, - &Notification::SetSound); + &Notification::SetSound) + .SetProperty("closeButtonText", &Notification::GetCloseButtonText, + &Notification::SetCloseButtonText); } } // namespace api diff --git a/atom/browser/api/atom_api_notification.h b/atom/browser/api/atom_api_notification.h index 50197350bc5e..e8e7a246e840 100644 --- a/atom/browser/api/atom_api_notification.h +++ b/atom/browser/api/atom_api_notification.h @@ -56,6 +56,7 @@ class Notification : public mate::TrackableObject, bool GetHasReply() const; std::vector GetActions() const; base::string16 GetSound() const; + base::string16 GetCloseButtonText() const; // Prop Setters void SetTitle(const base::string16& new_title); @@ -66,6 +67,7 @@ class Notification : public mate::TrackableObject, void SetHasReply(bool new_has_reply); void SetActions(const std::vector& actions); void SetSound(const base::string16& sound); + void SetCloseButtonText(const base::string16& text); private: base::string16 title_; @@ -79,6 +81,7 @@ class Notification : public mate::TrackableObject, bool has_reply_ = false; std::vector actions_; base::string16 sound_; + base::string16 close_button_text_; brightray::NotificationPresenter* presenter_; diff --git a/brightray/browser/mac/cocoa_notification.mm b/brightray/browser/mac/cocoa_notification.mm index 94b8f93fdc3f..98c3b6abe5b8 100644 --- a/brightray/browser/mac/cocoa_notification.mm +++ b/brightray/browser/mac/cocoa_notification.mm @@ -73,6 +73,10 @@ void CocoaNotification::Show(const NotificationOptions& options) { [notification_ setHasReplyButton:true]; } + if (!options.close_button_text.empty()) { + [notification_ setOtherButtonTitle:base::SysUTF16ToNSString(options.close_button_text)]; + } + [NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification_]; } diff --git a/brightray/browser/notification.h b/brightray/browser/notification.h index 69efcff386f5..853888f1cc8e 100644 --- a/brightray/browser/notification.h +++ b/brightray/browser/notification.h @@ -35,6 +35,7 @@ struct NotificationOptions { base::string16 reply_placeholder; base::string16 sound; std::vector actions; + base::string16 close_button_text; }; class Notification {