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; diff --git a/brightray/browser/linux/libnotify_notification.cc b/brightray/browser/linux/libnotify_notification.cc index e94c81619fe7..49c3b6ad0477 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; } @@ -114,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) {