From 8dd7a8d7fe79261c087ba1e5c0af02e422948a04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 14 Apr 2016 18:24:00 +0200 Subject: [PATCH 1/3] LibNotifyLoader: implement generic HasCapability --- .../browser/linux/libnotify_notification.cc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/brightray/browser/linux/libnotify_notification.cc b/brightray/browser/linux/libnotify_notification.cc index 399416a5721f..6772588f5099 100644 --- a/brightray/browser/linux/libnotify_notification.cc +++ b/brightray/browser/linux/libnotify_notification.cc @@ -17,6 +17,18 @@ namespace brightray { namespace { 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() { if (getenv("ELECTRON_USE_UBUNTU_NOTIFIER")) return false; @@ -28,12 +40,7 @@ bool NotifierSupportsActions() { if (notify_has_result) return notify_result; - capabilities = libnotify_loader_.notify_get_server_caps(); - - if (g_list_find_custom(capabilities, "actions", (GCompareFunc) g_strcmp0) != NULL) - notify_result = true; - - g_list_free_full(capabilities, g_free); + notify_result = HasCapability("actions"); return notify_result; } From 8962da380bb73d7ebe6dc1ad033e521412002e25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 14 Apr 2016 18:29:00 +0200 Subject: [PATCH 2/3] LibnotifyLoader: add notify_notification_set_hint_string --- brightray/browser/linux/libnotify_loader.cc | 10 ++++++++++ brightray/browser/linux/libnotify_loader.h | 1 + 2 files changed, 11 insertions(+) diff --git a/brightray/browser/linux/libnotify_loader.cc b/brightray/browser/linux/libnotify_loader.cc index f5c384db5672..9720e64d8c1e 100644 --- a/brightray/browser/linux/libnotify_loader.cc +++ b/brightray/browser/linux/libnotify_loader.cc @@ -92,6 +92,15 @@ bool LibNotifyLoader::Load(const std::string& library_name) { return false; } + notify_notification_set_hint_string = + reinterpret_castnotify_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 = reinterpret_castnotify_notification_show)>( dlsym(library_, "notify_notification_show")); @@ -128,6 +137,7 @@ void LibNotifyLoader::CleanUp(bool unload) { notify_notification_add_action = NULL; notify_notification_set_image_from_pixbuf = NULL; notify_notification_set_timeout = NULL; + notify_notification_set_hint_string = NULL; notify_notification_show = NULL; notify_notification_close = NULL; } diff --git a/brightray/browser/linux/libnotify_loader.h b/brightray/browser/linux/libnotify_loader.h index 818b0ddae074..825a349b39fc 100644 --- a/brightray/browser/linux/libnotify_loader.h +++ b/brightray/browser/linux/libnotify_loader.h @@ -26,6 +26,7 @@ class LibNotifyLoader { 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_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_close) notify_notification_close; From 83cbc1182d5ded13d6b00c6517a528886a694f94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 14 Apr 2016 18:31:02 +0200 Subject: [PATCH 3/3] LibnotifyNotification: use "append" when supported This behavior can be overridden by just providing unique tags to notifications --- brightray/browser/linux/libnotify_notification.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/brightray/browser/linux/libnotify_notification.cc b/brightray/browser/linux/libnotify_notification.cc index 6772588f5099..6314bd650f2a 100644 --- a/brightray/browser/linux/libnotify_notification.cc +++ b/brightray/browser/linux/libnotify_notification.cc @@ -121,6 +121,16 @@ void LibnotifyNotification::Show(const base::string16& title, 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; libnotify_loader_.notify_notification_show(notification_, &error); if (error) {