From 4e7f478d1e512cf20509b79ba07c7d91655e0c55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 13 Apr 2016 04:02:23 +0200 Subject: [PATCH 1/3] LibnotifyLoader: add notify_get_server_info support --- 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 ede4eeec670..61d74226895 100644 --- a/brightray/browser/linux/libnotify_loader.cc +++ b/brightray/browser/linux/libnotify_loader.cc @@ -38,6 +38,15 @@ bool LibNotifyLoader::Load(const std::string& library_name) { return false; } + notify_get_server_info = + reinterpret_castnotify_get_server_info)>( + dlsym(library_, "notify_get_server_info")); + notify_get_server_info = &::notify_get_server_info; + if (!notify_get_server_info) { + CleanUp(true); + return false; + } + notify_notification_new = reinterpret_castnotify_notification_new)>( dlsym(library_, "notify_notification_new")); @@ -104,6 +113,7 @@ void LibNotifyLoader::CleanUp(bool unload) { loaded_ = false; notify_is_initted = NULL; notify_init = NULL; + notify_get_server_info = NULL; notify_notification_new = NULL; notify_notification_add_action = NULL; notify_notification_set_image_from_pixbuf = NULL; diff --git a/brightray/browser/linux/libnotify_loader.h b/brightray/browser/linux/libnotify_loader.h index 6cf2853af2c..32b01cf4332 100644 --- a/brightray/browser/linux/libnotify_loader.h +++ b/brightray/browser/linux/libnotify_loader.h @@ -20,6 +20,7 @@ class LibNotifyLoader { decltype(&::notify_is_initted) notify_is_initted; decltype(&::notify_init) notify_init; + decltype(&::notify_get_server_info) notify_get_server_info; decltype(&::notify_notification_new) notify_notification_new; decltype(&::notify_notification_add_action) notify_notification_add_action; decltype(&::notify_notification_set_image_from_pixbuf) notify_notification_set_image_from_pixbuf; From a22dc8676f24899e01a18d85b430ff53df2b739c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 13 Apr 2016 04:42:01 +0200 Subject: [PATCH 2/3] LibnotifyLoader: add notify_get_server_caps support --- 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 61d74226895..f5c384db567 100644 --- a/brightray/browser/linux/libnotify_loader.cc +++ b/brightray/browser/linux/libnotify_loader.cc @@ -47,6 +47,15 @@ bool LibNotifyLoader::Load(const std::string& library_name) { return false; } + notify_get_server_caps = + reinterpret_castnotify_get_server_caps)>( + dlsym(library_, "notify_get_server_caps")); + notify_get_server_caps = &::notify_get_server_caps; + if (!notify_get_server_caps) { + CleanUp(true); + return false; + } + notify_notification_new = reinterpret_castnotify_notification_new)>( dlsym(library_, "notify_notification_new")); @@ -114,6 +123,7 @@ void LibNotifyLoader::CleanUp(bool unload) { notify_is_initted = NULL; notify_init = NULL; notify_get_server_info = NULL; + notify_get_server_caps = NULL; notify_notification_new = NULL; notify_notification_add_action = NULL; notify_notification_set_image_from_pixbuf = NULL; diff --git a/brightray/browser/linux/libnotify_loader.h b/brightray/browser/linux/libnotify_loader.h index 32b01cf4332..818b0ddae07 100644 --- a/brightray/browser/linux/libnotify_loader.h +++ b/brightray/browser/linux/libnotify_loader.h @@ -20,6 +20,7 @@ class LibNotifyLoader { decltype(&::notify_is_initted) notify_is_initted; decltype(&::notify_init) notify_init; + decltype(&::notify_get_server_caps) notify_get_server_caps; decltype(&::notify_get_server_info) notify_get_server_info; decltype(&::notify_notification_new) notify_notification_new; decltype(&::notify_notification_add_action) notify_notification_add_action; From 743ceed7802f5a9e533a8763e13732cfb38c2ae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 13 Apr 2016 04:43:22 +0200 Subject: [PATCH 3/3] LibnotifyNotification: verify if the "actions" capability is supported before adding actions This would prevent to add actions to notifier such as Ubuntu's Notify-OSD which doesn't support them. --- .../browser/linux/libnotify_notification.cc | 46 ++++++++----------- .../browser/linux/libnotify_notification.h | 2 - 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/brightray/browser/linux/libnotify_notification.cc b/brightray/browser/linux/libnotify_notification.cc index a903007b523..3d9fec263ee 100644 --- a/brightray/browser/linux/libnotify_notification.cc +++ b/brightray/browser/linux/libnotify_notification.cc @@ -15,32 +15,26 @@ namespace brightray { namespace { +LibNotifyLoader libnotify_loader_; -bool unity_has_result = false; -bool unity_result = false; - -bool UnityIsRunning() { +bool NotifierSupportsActions() { if (getenv("ELECTRON_USE_UBUNTU_NOTIFIER")) - return true; + return false; - if (unity_has_result) - return unity_result; + static bool notify_has_result = false; + static bool notify_result = false; + GList *capabilities = NULL; - unity_has_result = true; + if (notify_has_result) + return notify_result; - // Look for the presence of libunity as our hint that we're under Ubuntu. - base::FileEnumerator enumerator(base::FilePath("/usr/lib"), - false, base::FileEnumerator::FILES); - base::FilePath haystack; - while (!((haystack = enumerator.Next()).empty())) { - if (base::StartsWith(haystack.value(), "/usr/lib/libunity-", - base::CompareCase::SENSITIVE)) { - unity_result = true; - break; - } - } + capabilities = libnotify_loader_.notify_get_server_caps(); - return unity_result; + if (g_list_find_custom(capabilities, "actions", (GCompareFunc) g_strcmp0) != NULL) + notify_result = true; + + g_list_free_full(capabilities, g_free); + return notify_result; } void log_and_clear_error(GError* error, const char* context) { @@ -59,9 +53,6 @@ Notification* Notification::Create(NotificationDelegate* delegate, return new LibnotifyNotification(delegate, presenter); } -// static -LibNotifyLoader LibnotifyNotification::libnotify_loader_; - // static bool LibnotifyNotification::Initialize() { if (!libnotify_loader_.Load("libnotify.so.4") && @@ -83,6 +74,7 @@ LibnotifyNotification::LibnotifyNotification(NotificationDelegate* delegate, } LibnotifyNotification::~LibnotifyNotification() { + g_signal_handlers_disconnect_by_data(notification_, this); g_object_unref(notification_); } @@ -99,11 +91,9 @@ void LibnotifyNotification::Show(const base::string16& title, g_signal_connect( notification_, "closed", G_CALLBACK(OnNotificationClosedThunk), this); - // NB: On Unity, adding a notification action will cause the notification - // to display as a modal dialog box. Testing for distros that have "Unity - // Zen Nature" is difficult, we will test for the presence of the indicate - // dbus service - if (!UnityIsRunning()) { + // NB: On Unity and on any other DE using Notify-OSD, adding a notification + // action will cause the notification to display as a modal dialog box. + if (NotifierSupportsActions()) { libnotify_loader_.notify_notification_add_action( notification_, "default", "View", OnNotificationViewThunk, this, nullptr); diff --git a/brightray/browser/linux/libnotify_notification.h b/brightray/browser/linux/libnotify_notification.h index 17fb427bcf4..24a4debada4 100644 --- a/brightray/browser/linux/libnotify_notification.h +++ b/brightray/browser/linux/libnotify_notification.h @@ -35,8 +35,6 @@ class LibnotifyNotification : public Notification { void NotificationFailed(); - static LibNotifyLoader libnotify_loader_; - NotifyNotification* notification_; DISALLOW_COPY_AND_ASSIGN(LibnotifyNotification);