Make it able to set close button text
This commit is contained in:
parent
647d04cf92
commit
be118d4f13
4 changed files with 21 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -56,6 +56,7 @@ class Notification : public mate::TrackableObject<Notification>,
|
|||
bool GetHasReply() const;
|
||||
std::vector<brightray::NotificationAction> 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<Notification>,
|
|||
void SetHasReply(bool new_has_reply);
|
||||
void SetActions(const std::vector<brightray::NotificationAction>& 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<Notification>,
|
|||
bool has_reply_ = false;
|
||||
std::vector<brightray::NotificationAction> actions_;
|
||||
base::string16 sound_;
|
||||
base::string16 close_button_text_;
|
||||
|
||||
brightray::NotificationPresenter* presenter_;
|
||||
|
||||
|
|
|
@ -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_];
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ struct NotificationOptions {
|
|||
base::string16 reply_placeholder;
|
||||
base::string16 sound;
|
||||
std::vector<NotificationAction> actions;
|
||||
base::string16 close_button_text;
|
||||
};
|
||||
|
||||
class Notification {
|
||||
|
|
Loading…
Reference in a new issue