Merge pull request #210 from 3v1n0/notify-check-actions-cap
Notify check actions cap
This commit is contained in:
commit
f716ae58a6
4 changed files with 40 additions and 30 deletions
|
@ -38,6 +38,24 @@ bool LibNotifyLoader::Load(const std::string& library_name) {
|
|||
return false;
|
||||
}
|
||||
|
||||
notify_get_server_info =
|
||||
reinterpret_cast<decltype(this->notify_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_get_server_caps =
|
||||
reinterpret_cast<decltype(this->notify_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_cast<decltype(this->notify_notification_new)>(
|
||||
dlsym(library_, "notify_notification_new"));
|
||||
|
@ -104,6 +122,8 @@ void LibNotifyLoader::CleanUp(bool unload) {
|
|||
loaded_ = false;
|
||||
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;
|
||||
|
|
|
@ -20,6 +20,8 @@ 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;
|
||||
decltype(&::notify_notification_set_image_from_pixbuf) notify_notification_set_image_from_pixbuf;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -35,8 +35,6 @@ class LibnotifyNotification : public Notification {
|
|||
|
||||
void NotificationFailed();
|
||||
|
||||
static LibNotifyLoader libnotify_loader_;
|
||||
|
||||
NotifyNotification* notification_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(LibnotifyNotification);
|
||||
|
|
Loading…
Reference in a new issue