Skip to content

Commit a196bf9

Browse files
committed
🍎 Add subtitle to Notification properties
1 parent 440b238 commit a196bf9

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

atom/browser/api/atom_api_notification.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Notification::Notification(v8::Isolate* isolate,
5757
mate::Dictionary opts;
5858
if (args->GetNext(&opts)) {
5959
opts.Get("title", &title_);
60+
opts.Get("subtitle", &subtitle_);
6061
opts.Get("body", &body_);
6162
has_icon_ = opts.Get("icon", &icon_);
6263
if (has_icon_) {
@@ -88,6 +89,10 @@ base::string16 Notification::GetTitle() {
8889
return title_;
8990
}
9091

92+
base::string16 Notification::GetSubtitle() {
93+
return subtitle_;
94+
}
95+
9196
base::string16 Notification::GetBody() {
9297
return body_;
9398
}
@@ -109,6 +114,10 @@ void Notification::SetTitle(const base::string16& new_title) {
109114
title_ = new_title;
110115
}
111116

117+
void Notification::SetSubtitle(const base::string16& new_subtitle) {
118+
subtitle_ = new_subtitle;
119+
}
120+
112121
void Notification::SetBody(const base::string16& new_body) {
113122
body_ = new_body;
114123
}
@@ -164,6 +173,7 @@ void Notification::Show() {
164173
if (notification_) {
165174
brightray::NotificationOptions options;
166175
options.title = title_;
176+
options.subtitle = subtitle_;
167177
options.msg = body_;
168178
options.icon_url = GURL();
169179
options.icon = icon_.AsBitmap();
@@ -188,6 +198,8 @@ void Notification::BuildPrototype(v8::Isolate* isolate,
188198
.MakeDestroyable()
189199
.SetMethod("show", &Notification::Show)
190200
.SetProperty("title", &Notification::GetTitle, &Notification::SetTitle)
201+
.SetProperty("subtitle", &Notification::GetSubtitle,
202+
&Notification::SetSubtitle)
191203
.SetProperty("body", &Notification::GetBody, &Notification::SetBody)
192204
.SetProperty("silent", &Notification::GetSilent, &Notification::SetSilent)
193205
.SetProperty("replyPlaceholder", &Notification::GetReplyPlaceholder,

atom/browser/api/atom_api_notification.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class Notification : public mate::TrackableObject<Notification>,
4848

4949
// Prop Getters
5050
base::string16 GetTitle();
51+
base::string16 GetSubtitle();
5152
base::string16 GetBody();
5253
bool GetSilent();
5354
base::string16 GetReplyPlaceholder();
@@ -56,6 +57,7 @@ class Notification : public mate::TrackableObject<Notification>,
5657

5758
// Prop Setters
5859
void SetTitle(const base::string16& new_title);
60+
void SetSubtitle(const base::string16& new_subtitle);
5961
void SetBody(const base::string16& new_body);
6062
void SetSilent(bool new_silent);
6163
void SetReplyPlaceholder(const base::string16& new_reply_placeholder);
@@ -64,6 +66,7 @@ class Notification : public mate::TrackableObject<Notification>,
6466

6567
private:
6668
base::string16 title_;
69+
base::string16 subtitle_;
6770
base::string16 body_;
6871
gfx::Image icon_;
6972
base::string16 icon_path_;

brightray/browser/mac/cocoa_notification.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
void CocoaNotification::Show(const NotificationOptions& options) {
2828
notification_.reset([[NSUserNotification alloc] init]);
2929
[notification_ setTitle:base::SysUTF16ToNSString(options.title)];
30+
[notification_ setSubtitle:base::SysUTF16ToNSString(options.subtitle)];
3031
[notification_ setInformativeText:base::SysUTF16ToNSString(options.msg)];
3132

3233
if ([notification_ respondsToSelector:@selector(setContentImage:)] &&

brightray/browser/notification.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct NotificationAction {
2525

2626
struct NotificationOptions {
2727
base::string16 title;
28+
base::string16 subtitle;
2829
base::string16 msg;
2930
std::string tag;
3031
GURL icon_url;

docs/api/notification.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ Returns `Boolean` - Whether or not desktop notifications are supported on the cu
3131

3232
* `options` Object
3333
* `title` String - A title for the notification, which will be shown at the top of the notification window when it is shown
34-
* `body` String - The body text of the notification, which will be displayed below the title
34+
* `subtitle` String - A subtitle for the notification, which will be displayed below the title. _macOS_
35+
* `body` String - The body text of the notification, which will be displayed below the title or subtitle
3536
* `silent` Boolean - (optional) Whether or not to emit an OS notification noise when showing the notification
3637
* `icon` [NativeImage](native-image.md) - (optional) An icon to use in the notification
3738
* `hasReply` Boolean - (optional) Whether or not to add an inline reply option to the notification. _macOS_

0 commit comments

Comments
 (0)