🍎 Add subtitle to Notification properties

This commit is contained in:
Milan Burda 2017-06-30 15:59:46 +02:00
parent 440b238157
commit a196bf97bc
5 changed files with 19 additions and 1 deletions

View file

@ -57,6 +57,7 @@ Notification::Notification(v8::Isolate* isolate,
mate::Dictionary opts;
if (args->GetNext(&opts)) {
opts.Get("title", &title_);
opts.Get("subtitle", &subtitle_);
opts.Get("body", &body_);
has_icon_ = opts.Get("icon", &icon_);
if (has_icon_) {
@ -88,6 +89,10 @@ base::string16 Notification::GetTitle() {
return title_;
}
base::string16 Notification::GetSubtitle() {
return subtitle_;
}
base::string16 Notification::GetBody() {
return body_;
}
@ -109,6 +114,10 @@ void Notification::SetTitle(const base::string16& new_title) {
title_ = new_title;
}
void Notification::SetSubtitle(const base::string16& new_subtitle) {
subtitle_ = new_subtitle;
}
void Notification::SetBody(const base::string16& new_body) {
body_ = new_body;
}
@ -164,6 +173,7 @@ void Notification::Show() {
if (notification_) {
brightray::NotificationOptions options;
options.title = title_;
options.subtitle = subtitle_;
options.msg = body_;
options.icon_url = GURL();
options.icon = icon_.AsBitmap();
@ -188,6 +198,8 @@ void Notification::BuildPrototype(v8::Isolate* isolate,
.MakeDestroyable()
.SetMethod("show", &Notification::Show)
.SetProperty("title", &Notification::GetTitle, &Notification::SetTitle)
.SetProperty("subtitle", &Notification::GetSubtitle,
&Notification::SetSubtitle)
.SetProperty("body", &Notification::GetBody, &Notification::SetBody)
.SetProperty("silent", &Notification::GetSilent, &Notification::SetSilent)
.SetProperty("replyPlaceholder", &Notification::GetReplyPlaceholder,

View file

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

View file

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

View file

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

View file

@ -31,7 +31,8 @@ Returns `Boolean` - Whether or not desktop notifications are supported on the cu
* `options` Object
* `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
* `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_