Skip to content

Commit

Permalink
feat: set urgency on linux notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Sep 6, 2019
1 parent 432ae81 commit 5a4f279
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/api/notification.md
Expand Up @@ -144,6 +144,12 @@ A `Boolean` property representing whether the notification is silent.

A `Boolean` property representing whether the notification has a reply action.

#### `notification.urgency` _Linux_

A `String` property representing the urgency level of the notification. Can be 'normal', 'critical', or 'low'.

Default is low - see [NotifyUrgency](https://developer.gnome.org/libnotify/unstable/NotifyNotification.html#notify-notification-set-urgency) for more information.

#### `notification.actions`

A [`NotificationAction[]`](structures/notification-action.md) property representing the actions of the notification.
Expand Down
12 changes: 12 additions & 0 deletions shell/browser/api/atom_api_notification.cc
Expand Up @@ -68,6 +68,7 @@ Notification::Notification(v8::Isolate* isolate,
}
opts.Get("silent", &silent_);
opts.Get("replyPlaceholder", &reply_placeholder_);
opts.Get("urgency", &urgency_);
opts.Get("hasReply", &has_reply_);
opts.Get("actions", &actions_);
opts.Get("sound", &sound_);
Expand Down Expand Up @@ -118,6 +119,10 @@ base::string16 Notification::GetSound() const {
return sound_;
}

base::string16 Notification::GetUrgency() const {
return urgency_;
}

std::vector<electron::NotificationAction> Notification::GetActions() const {
return actions_;
}
Expand Down Expand Up @@ -155,6 +160,10 @@ void Notification::SetSound(const base::string16& new_sound) {
sound_ = new_sound;
}

void Notification::SetUrgency(const base::string16& new_urgency) {
urgency_ = new_urgency;
}

void Notification::SetActions(
const std::vector<electron::NotificationAction>& actions) {
actions_ = actions;
Expand Down Expand Up @@ -211,6 +220,7 @@ void Notification::Show() {
options.actions = actions_;
options.sound = sound_;
options.close_button_text = close_button_text_;
options.urgency = urgency_;
notification_->Show(options);
}
}
Expand Down Expand Up @@ -238,6 +248,8 @@ void Notification::BuildPrototype(v8::Isolate* isolate,
&Notification::SetHasReply)
.SetProperty("replyPlaceholder", &Notification::GetReplyPlaceholder,
&Notification::SetReplyPlaceholder)
.SetProperty("urgency", &Notification::GetUrgency,
&Notification::SetUrgency)
.SetProperty("sound", &Notification::GetSound, &Notification::SetSound)
.SetProperty("actions", &Notification::GetActions,
&Notification::SetActions)
Expand Down
1 change: 1 addition & 0 deletions shell/browser/api/atom_api_notification.h
Expand Up @@ -80,6 +80,7 @@ class Notification : public mate::TrackableObject<Notification>,
bool has_reply_ = false;
base::string16 reply_placeholder_;
base::string16 sound_;
base::string16 urgency_;
std::vector<electron::NotificationAction> actions_;
base::string16 close_button_text_;

Expand Down
10 changes: 10 additions & 0 deletions shell/browser/notifications/linux/libnotify_notification.cc
Expand Up @@ -100,6 +100,16 @@ void LibnotifyNotification::Show(const NotificationOptions& options) {
nullptr);
}

NotifyUrgency urgency = NOTIFY_URGENCY_NORMAL;
if (options.urgency == "critical") {
urgency = NOTIFY_URGENCY_CRITICAL;
} else if (options.urgency == "low") {
urgency = NOTIFY_URGENCY_LOW;
}

// Set the urgency level of the notification.
libnotify_loader_.notify_notification_set_urgency(notification_, urgency);

if (!options.icon.drawsNothing()) {
GdkPixbuf* pixbuf = libgtkui::GdkPixbufFromSkBitmap(options.icon);
libnotify_loader_.notify_notification_set_image_from_pixbuf(notification_,
Expand Down
1 change: 1 addition & 0 deletions shell/browser/notifications/notification.h
Expand Up @@ -34,6 +34,7 @@ struct NotificationOptions {
bool has_reply;
base::string16 reply_placeholder;
base::string16 sound;
base::string16 urgency; // Linux
std::vector<NotificationAction> actions;
base::string16 close_button_text;

Expand Down

0 comments on commit 5a4f279

Please sign in to comment.