Merge pull request #9903 from miniak/notification-subtitle

Notification subtitle on Mac
This commit is contained in:
Milan Burda 2017-06-30 19:08:51 +02:00 committed by GitHub
commit d58a5dfe3a
5 changed files with 34 additions and 16 deletions

View file

@ -57,6 +57,7 @@ Notification::Notification(v8::Isolate* isolate,
mate::Dictionary opts; mate::Dictionary opts;
if (args->GetNext(&opts)) { if (args->GetNext(&opts)) {
opts.Get("title", &title_); opts.Get("title", &title_);
opts.Get("subtitle", &subtitle_);
opts.Get("body", &body_); opts.Get("body", &body_);
has_icon_ = opts.Get("icon", &icon_); has_icon_ = opts.Get("icon", &icon_);
if (has_icon_) { if (has_icon_) {
@ -84,31 +85,43 @@ mate::WrappableBase* Notification::New(mate::Arguments* args) {
} }
// Getters // Getters
base::string16 Notification::GetTitle() { base::string16 Notification::GetTitle() const {
return title_; return title_;
} }
base::string16 Notification::GetBody() { base::string16 Notification::GetSubtitle() const {
return subtitle_;
}
base::string16 Notification::GetBody() const {
return body_; return body_;
} }
bool Notification::GetSilent() { bool Notification::GetSilent() const {
return silent_; return silent_;
} }
base::string16 Notification::GetReplyPlaceholder() { base::string16 Notification::GetReplyPlaceholder() const {
return reply_placeholder_; return reply_placeholder_;
} }
bool Notification::GetHasReply() { bool Notification::GetHasReply() const {
return has_reply_; return has_reply_;
} }
std::vector<brightray::NotificationAction> Notification::GetActions() const {
return actions_;
}
// Setters // Setters
void Notification::SetTitle(const base::string16& new_title) { void Notification::SetTitle(const base::string16& new_title) {
title_ = new_title; title_ = new_title;
} }
void Notification::SetSubtitle(const base::string16& new_subtitle) {
subtitle_ = new_subtitle;
}
void Notification::SetBody(const base::string16& new_body) { void Notification::SetBody(const base::string16& new_body) {
body_ = new_body; body_ = new_body;
} }
@ -130,10 +143,6 @@ void Notification::SetActions(
actions_ = actions; actions_ = actions;
} }
std::vector<brightray::NotificationAction> Notification::GetActions() {
return actions_;
}
void Notification::NotificationAction(int index) { void Notification::NotificationAction(int index) {
Emit("action", index); Emit("action", index);
} }
@ -164,6 +173,7 @@ void Notification::Show() {
if (notification_) { if (notification_) {
brightray::NotificationOptions options; brightray::NotificationOptions options;
options.title = title_; options.title = title_;
options.subtitle = subtitle_;
options.msg = body_; options.msg = body_;
options.icon_url = GURL(); options.icon_url = GURL();
options.icon = icon_.AsBitmap(); options.icon = icon_.AsBitmap();
@ -188,6 +198,8 @@ void Notification::BuildPrototype(v8::Isolate* isolate,
.MakeDestroyable() .MakeDestroyable()
.SetMethod("show", &Notification::Show) .SetMethod("show", &Notification::Show)
.SetProperty("title", &Notification::GetTitle, &Notification::SetTitle) .SetProperty("title", &Notification::GetTitle, &Notification::SetTitle)
.SetProperty("subtitle", &Notification::GetSubtitle,
&Notification::SetSubtitle)
.SetProperty("body", &Notification::GetBody, &Notification::SetBody) .SetProperty("body", &Notification::GetBody, &Notification::SetBody)
.SetProperty("silent", &Notification::GetSilent, &Notification::SetSilent) .SetProperty("silent", &Notification::GetSilent, &Notification::SetSilent)
.SetProperty("replyPlaceholder", &Notification::GetReplyPlaceholder, .SetProperty("replyPlaceholder", &Notification::GetReplyPlaceholder,

View file

@ -47,15 +47,17 @@ class Notification : public mate::TrackableObject<Notification>,
void Show(); void Show();
// Prop Getters // Prop Getters
base::string16 GetTitle(); base::string16 GetTitle() const;
base::string16 GetBody(); base::string16 GetSubtitle() const;
bool GetSilent(); base::string16 GetBody() const;
base::string16 GetReplyPlaceholder(); bool GetSilent() const;
bool GetHasReply(); base::string16 GetReplyPlaceholder() const;
std::vector<brightray::NotificationAction> GetActions(); bool GetHasReply() const;
std::vector<brightray::NotificationAction> GetActions() const;
// Prop Setters // Prop Setters
void SetTitle(const base::string16& new_title); void SetTitle(const base::string16& new_title);
void SetSubtitle(const base::string16& new_subtitle);
void SetBody(const base::string16& new_body); void SetBody(const base::string16& new_body);
void SetSilent(bool new_silent); void SetSilent(bool new_silent);
void SetReplyPlaceholder(const base::string16& new_reply_placeholder); void SetReplyPlaceholder(const base::string16& new_reply_placeholder);
@ -64,6 +66,7 @@ class Notification : public mate::TrackableObject<Notification>,
private: private:
base::string16 title_; base::string16 title_;
base::string16 subtitle_;
base::string16 body_; base::string16 body_;
gfx::Image icon_; gfx::Image icon_;
base::string16 icon_path_; base::string16 icon_path_;

View file

@ -27,6 +27,7 @@ CocoaNotification::~CocoaNotification() {
void CocoaNotification::Show(const NotificationOptions& options) { void CocoaNotification::Show(const NotificationOptions& options) {
notification_.reset([[NSUserNotification alloc] init]); notification_.reset([[NSUserNotification alloc] init]);
[notification_ setTitle:base::SysUTF16ToNSString(options.title)]; [notification_ setTitle:base::SysUTF16ToNSString(options.title)];
[notification_ setSubtitle:base::SysUTF16ToNSString(options.subtitle)];
[notification_ setInformativeText:base::SysUTF16ToNSString(options.msg)]; [notification_ setInformativeText:base::SysUTF16ToNSString(options.msg)];
if ([notification_ respondsToSelector:@selector(setContentImage:)] && if ([notification_ respondsToSelector:@selector(setContentImage:)] &&

View file

@ -25,6 +25,7 @@ struct NotificationAction {
struct NotificationOptions { struct NotificationOptions {
base::string16 title; base::string16 title;
base::string16 subtitle;
base::string16 msg; base::string16 msg;
std::string tag; std::string tag;
GURL icon_url; GURL icon_url;

View file

@ -31,7 +31,8 @@ Returns `Boolean` - Whether or not desktop notifications are supported on the cu
* `options` Object * `options` Object
* `title` String - A title for the notification, which will be shown at the top of the notification window when it is shown * `title` String - A title for the notification, which will be shown at the top of the notification window when it is shown
* `body` String - The body text of the notification, which will be displayed below the title * `subtitle` String - A subtitle for the notification, which will be displayed below the title. _macOS_
* `body` String - The body text of the notification, which will be displayed below the title or subtitle
* `silent` Boolean - (optional) Whether or not to emit an OS notification noise when showing the notification * `silent` Boolean - (optional) Whether or not to emit an OS notification noise when showing the notification
* `icon` [NativeImage](native-image.md) - (optional) An icon to use in the notification * `icon` [NativeImage](native-image.md) - (optional) An icon to use in the notification
* `hasReply` Boolean - (optional) Whether or not to add an inline reply option to the notification. _macOS_ * `hasReply` Boolean - (optional) Whether or not to add an inline reply option to the notification. _macOS_