feat: set urgency on linux notifications (#20152)
This commit is contained in:
Родитель
e510af77b2
Коммит
ffe2182883
1
BUILD.gn
1
BUILD.gn
|
@ -280,6 +280,7 @@ if (is_linux) {
|
||||||
"notify_notification_add_action",
|
"notify_notification_add_action",
|
||||||
"notify_notification_set_image_from_pixbuf",
|
"notify_notification_set_image_from_pixbuf",
|
||||||
"notify_notification_set_timeout",
|
"notify_notification_set_timeout",
|
||||||
|
"notify_notification_set_urgency",
|
||||||
"notify_notification_set_hint_string",
|
"notify_notification_set_hint_string",
|
||||||
"notify_notification_show",
|
"notify_notification_show",
|
||||||
"notify_notification_close",
|
"notify_notification_close",
|
||||||
|
|
|
@ -37,6 +37,7 @@ Returns `Boolean` - Whether or not desktop notifications are supported on the cu
|
||||||
* `hasReply` Boolean (optional) _macOS_ - Whether or not to add an inline reply option to the notification.
|
* `hasReply` Boolean (optional) _macOS_ - Whether or not to add an inline reply option to the notification.
|
||||||
* `replyPlaceholder` String (optional) _macOS_ - The placeholder to write in the inline reply input field.
|
* `replyPlaceholder` String (optional) _macOS_ - The placeholder to write in the inline reply input field.
|
||||||
* `sound` String (optional) _macOS_ - The name of the sound file to play when the notification is shown.
|
* `sound` String (optional) _macOS_ - The name of the sound file to play when the notification is shown.
|
||||||
|
* `urgency` String (optional) _Linux_ - The urgency level of the notification. Can be 'normal', 'critical', or 'low'.
|
||||||
* `actions` [NotificationAction[]](structures/notification-action.md) (optional) _macOS_ - Actions to add to the notification. Please read the available actions and limitations in the `NotificationAction` documentation.
|
* `actions` [NotificationAction[]](structures/notification-action.md) (optional) _macOS_ - Actions to add to the notification. Please read the available actions and limitations in the `NotificationAction` documentation.
|
||||||
* `closeButtonText` String (optional) _macOS_ - A custom title for the close button of an alert. An empty string will cause the default localized text to be used.
|
* `closeButtonText` String (optional) _macOS_ - A custom title for the close button of an alert. An empty string will cause the default localized text to be used.
|
||||||
|
|
||||||
|
@ -144,6 +145,12 @@ A `Boolean` property representing whether the notification is silent.
|
||||||
|
|
||||||
A `Boolean` property representing whether the notification has a reply action.
|
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/notification-spec/#urgency-levels) for more information.
|
||||||
|
|
||||||
#### `notification.actions`
|
#### `notification.actions`
|
||||||
|
|
||||||
A [`NotificationAction[]`](structures/notification-action.md) property representing the actions of the notification.
|
A [`NotificationAction[]`](structures/notification-action.md) property representing the actions of the notification.
|
||||||
|
|
|
@ -68,6 +68,7 @@ Notification::Notification(v8::Isolate* isolate,
|
||||||
}
|
}
|
||||||
opts.Get("silent", &silent_);
|
opts.Get("silent", &silent_);
|
||||||
opts.Get("replyPlaceholder", &reply_placeholder_);
|
opts.Get("replyPlaceholder", &reply_placeholder_);
|
||||||
|
opts.Get("urgency", &urgency_);
|
||||||
opts.Get("hasReply", &has_reply_);
|
opts.Get("hasReply", &has_reply_);
|
||||||
opts.Get("actions", &actions_);
|
opts.Get("actions", &actions_);
|
||||||
opts.Get("sound", &sound_);
|
opts.Get("sound", &sound_);
|
||||||
|
@ -118,6 +119,10 @@ base::string16 Notification::GetSound() const {
|
||||||
return sound_;
|
return sound_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
base::string16 Notification::GetUrgency() const {
|
||||||
|
return urgency_;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<electron::NotificationAction> Notification::GetActions() const {
|
std::vector<electron::NotificationAction> Notification::GetActions() const {
|
||||||
return actions_;
|
return actions_;
|
||||||
}
|
}
|
||||||
|
@ -155,6 +160,10 @@ void Notification::SetSound(const base::string16& new_sound) {
|
||||||
sound_ = new_sound;
|
sound_ = new_sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Notification::SetUrgency(const base::string16& new_urgency) {
|
||||||
|
urgency_ = new_urgency;
|
||||||
|
}
|
||||||
|
|
||||||
void Notification::SetActions(
|
void Notification::SetActions(
|
||||||
const std::vector<electron::NotificationAction>& actions) {
|
const std::vector<electron::NotificationAction>& actions) {
|
||||||
actions_ = actions;
|
actions_ = actions;
|
||||||
|
@ -211,6 +220,7 @@ void Notification::Show() {
|
||||||
options.actions = actions_;
|
options.actions = actions_;
|
||||||
options.sound = sound_;
|
options.sound = sound_;
|
||||||
options.close_button_text = close_button_text_;
|
options.close_button_text = close_button_text_;
|
||||||
|
options.urgency = urgency_;
|
||||||
notification_->Show(options);
|
notification_->Show(options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -238,6 +248,8 @@ void Notification::BuildPrototype(v8::Isolate* isolate,
|
||||||
&Notification::SetHasReply)
|
&Notification::SetHasReply)
|
||||||
.SetProperty("replyPlaceholder", &Notification::GetReplyPlaceholder,
|
.SetProperty("replyPlaceholder", &Notification::GetReplyPlaceholder,
|
||||||
&Notification::SetReplyPlaceholder)
|
&Notification::SetReplyPlaceholder)
|
||||||
|
.SetProperty("urgency", &Notification::GetUrgency,
|
||||||
|
&Notification::SetUrgency)
|
||||||
.SetProperty("sound", &Notification::GetSound, &Notification::SetSound)
|
.SetProperty("sound", &Notification::GetSound, &Notification::SetSound)
|
||||||
.SetProperty("actions", &Notification::GetActions,
|
.SetProperty("actions", &Notification::GetActions,
|
||||||
&Notification::SetActions)
|
&Notification::SetActions)
|
||||||
|
|
|
@ -54,6 +54,7 @@ class Notification : public mate::TrackableObject<Notification>,
|
||||||
bool GetSilent() const;
|
bool GetSilent() const;
|
||||||
bool GetHasReply() const;
|
bool GetHasReply() const;
|
||||||
base::string16 GetReplyPlaceholder() const;
|
base::string16 GetReplyPlaceholder() const;
|
||||||
|
base::string16 GetUrgency() const;
|
||||||
base::string16 GetSound() const;
|
base::string16 GetSound() const;
|
||||||
std::vector<electron::NotificationAction> GetActions() const;
|
std::vector<electron::NotificationAction> GetActions() const;
|
||||||
base::string16 GetCloseButtonText() const;
|
base::string16 GetCloseButtonText() const;
|
||||||
|
@ -64,6 +65,7 @@ class Notification : public mate::TrackableObject<Notification>,
|
||||||
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 SetHasReply(bool new_has_reply);
|
void SetHasReply(bool new_has_reply);
|
||||||
|
void SetUrgency(const base::string16& new_urgency);
|
||||||
void SetReplyPlaceholder(const base::string16& new_reply_placeholder);
|
void SetReplyPlaceholder(const base::string16& new_reply_placeholder);
|
||||||
void SetSound(const base::string16& sound);
|
void SetSound(const base::string16& sound);
|
||||||
void SetActions(const std::vector<electron::NotificationAction>& actions);
|
void SetActions(const std::vector<electron::NotificationAction>& actions);
|
||||||
|
@ -80,6 +82,7 @@ class Notification : public mate::TrackableObject<Notification>,
|
||||||
bool has_reply_ = false;
|
bool has_reply_ = false;
|
||||||
base::string16 reply_placeholder_;
|
base::string16 reply_placeholder_;
|
||||||
base::string16 sound_;
|
base::string16 sound_;
|
||||||
|
base::string16 urgency_;
|
||||||
std::vector<electron::NotificationAction> actions_;
|
std::vector<electron::NotificationAction> actions_;
|
||||||
base::string16 close_button_text_;
|
base::string16 close_button_text_;
|
||||||
|
|
||||||
|
|
|
@ -100,6 +100,16 @@ void LibnotifyNotification::Show(const NotificationOptions& options) {
|
||||||
nullptr);
|
nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NotifyUrgency urgency = NOTIFY_URGENCY_NORMAL;
|
||||||
|
if (options.urgency == base::ASCIIToUTF16("critical")) {
|
||||||
|
urgency = NOTIFY_URGENCY_CRITICAL;
|
||||||
|
} else if (options.urgency == base::ASCIIToUTF16("low")) {
|
||||||
|
urgency = NOTIFY_URGENCY_LOW;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the urgency level of the notification.
|
||||||
|
libnotify_loader_.notify_notification_set_urgency(notification_, urgency);
|
||||||
|
|
||||||
if (!options.icon.drawsNothing()) {
|
if (!options.icon.drawsNothing()) {
|
||||||
GdkPixbuf* pixbuf = libgtkui::GdkPixbufFromSkBitmap(options.icon);
|
GdkPixbuf* pixbuf = libgtkui::GdkPixbufFromSkBitmap(options.icon);
|
||||||
libnotify_loader_.notify_notification_set_image_from_pixbuf(notification_,
|
libnotify_loader_.notify_notification_set_image_from_pixbuf(notification_,
|
||||||
|
|
|
@ -34,6 +34,7 @@ struct NotificationOptions {
|
||||||
bool has_reply;
|
bool has_reply;
|
||||||
base::string16 reply_placeholder;
|
base::string16 reply_placeholder;
|
||||||
base::string16 sound;
|
base::string16 sound;
|
||||||
|
base::string16 urgency; // Linux
|
||||||
std::vector<NotificationAction> actions;
|
std::vector<NotificationAction> actions;
|
||||||
base::string16 close_button_text;
|
base::string16 close_button_text;
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,8 @@ ifdescribe(!skip)('Notification module (dbus)', () => {
|
||||||
actions: [],
|
actions: [],
|
||||||
hints: {
|
hints: {
|
||||||
'append': 'true',
|
'append': 'true',
|
||||||
'desktop-entry': appName
|
'desktop-entry': appName,
|
||||||
|
'urgency': 1
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Загрузка…
Ссылка в новой задаче