Merge pull request #213 from 3v1n0/linux-notifications-append
Linux notifications append
This commit is contained in:
commit
aafc48ae2c
3 changed files with 34 additions and 6 deletions
|
@ -92,6 +92,15 @@ bool LibNotifyLoader::Load(const std::string& library_name) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notify_notification_set_hint_string =
|
||||||
|
reinterpret_cast<decltype(this->notify_notification_set_hint_string)>(
|
||||||
|
dlsym(library_, "notify_notification_set_hint_string"));
|
||||||
|
notify_notification_set_hint_string = &::notify_notification_set_hint_string;
|
||||||
|
if (!notify_notification_set_hint_string) {
|
||||||
|
CleanUp(true);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
notify_notification_show =
|
notify_notification_show =
|
||||||
reinterpret_cast<decltype(this->notify_notification_show)>(
|
reinterpret_cast<decltype(this->notify_notification_show)>(
|
||||||
dlsym(library_, "notify_notification_show"));
|
dlsym(library_, "notify_notification_show"));
|
||||||
|
@ -128,6 +137,7 @@ void LibNotifyLoader::CleanUp(bool unload) {
|
||||||
notify_notification_add_action = NULL;
|
notify_notification_add_action = NULL;
|
||||||
notify_notification_set_image_from_pixbuf = NULL;
|
notify_notification_set_image_from_pixbuf = NULL;
|
||||||
notify_notification_set_timeout = NULL;
|
notify_notification_set_timeout = NULL;
|
||||||
|
notify_notification_set_hint_string = NULL;
|
||||||
notify_notification_show = NULL;
|
notify_notification_show = NULL;
|
||||||
notify_notification_close = NULL;
|
notify_notification_close = NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ class LibNotifyLoader {
|
||||||
decltype(&::notify_notification_add_action) notify_notification_add_action;
|
decltype(&::notify_notification_add_action) notify_notification_add_action;
|
||||||
decltype(&::notify_notification_set_image_from_pixbuf) notify_notification_set_image_from_pixbuf;
|
decltype(&::notify_notification_set_image_from_pixbuf) notify_notification_set_image_from_pixbuf;
|
||||||
decltype(&::notify_notification_set_timeout) notify_notification_set_timeout;
|
decltype(&::notify_notification_set_timeout) notify_notification_set_timeout;
|
||||||
|
decltype(&::notify_notification_set_hint_string) notify_notification_set_hint_string;
|
||||||
decltype(&::notify_notification_show) notify_notification_show;
|
decltype(&::notify_notification_show) notify_notification_show;
|
||||||
decltype(&::notify_notification_close) notify_notification_close;
|
decltype(&::notify_notification_close) notify_notification_close;
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,18 @@ namespace brightray {
|
||||||
namespace {
|
namespace {
|
||||||
LibNotifyLoader libnotify_loader_;
|
LibNotifyLoader libnotify_loader_;
|
||||||
|
|
||||||
|
bool HasCapability(const std::string& capability) {
|
||||||
|
bool result = false;
|
||||||
|
GList* capabilities = libnotify_loader_.notify_get_server_caps();
|
||||||
|
|
||||||
|
if (g_list_find_custom(capabilities, capability.c_str(), (GCompareFunc) g_strcmp0) != NULL)
|
||||||
|
result = true;
|
||||||
|
|
||||||
|
g_list_free_full(capabilities, g_free);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
bool NotifierSupportsActions() {
|
bool NotifierSupportsActions() {
|
||||||
if (getenv("ELECTRON_USE_UBUNTU_NOTIFIER"))
|
if (getenv("ELECTRON_USE_UBUNTU_NOTIFIER"))
|
||||||
return false;
|
return false;
|
||||||
|
@ -28,12 +40,7 @@ bool NotifierSupportsActions() {
|
||||||
if (notify_has_result)
|
if (notify_has_result)
|
||||||
return notify_result;
|
return notify_result;
|
||||||
|
|
||||||
capabilities = libnotify_loader_.notify_get_server_caps();
|
notify_result = HasCapability("actions");
|
||||||
|
|
||||||
if (g_list_find_custom(capabilities, "actions", (GCompareFunc) g_strcmp0) != NULL)
|
|
||||||
notify_result = true;
|
|
||||||
|
|
||||||
g_list_free_full(capabilities, g_free);
|
|
||||||
return notify_result;
|
return notify_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,6 +121,16 @@ void LibnotifyNotification::Show(const base::string16& title,
|
||||||
g_object_set(G_OBJECT(notification_), "id", id, NULL);
|
g_object_set(G_OBJECT(notification_), "id", id, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Always try to append notifications.
|
||||||
|
// Unique tags can be used to prevent this.
|
||||||
|
if (HasCapability("append")) {
|
||||||
|
libnotify_loader_.notify_notification_set_hint_string(
|
||||||
|
notification_, "append", "true");
|
||||||
|
} else if (HasCapability("x-canonical-append")) {
|
||||||
|
libnotify_loader_.notify_notification_set_hint_string(
|
||||||
|
notification_, "x-canonical-append", "true");
|
||||||
|
}
|
||||||
|
|
||||||
GError* error = nullptr;
|
GError* error = nullptr;
|
||||||
libnotify_loader_.notify_notification_show(notification_, &error);
|
libnotify_loader_.notify_notification_show(notification_, &error);
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|
Loading…
Reference in a new issue