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.
This commit is contained in:
		
					parent
					
						
							
								a22dc8676f
							
						
					
				
			
			
				commit
				
					
						743ceed780
					
				
			
		
					 2 changed files with 18 additions and 30 deletions
				
			
		| 
						 | 
					@ -15,32 +15,26 @@
 | 
				
			||||||
namespace brightray {
 | 
					namespace brightray {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace {
 | 
					namespace {
 | 
				
			||||||
 | 
					LibNotifyLoader libnotify_loader_;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool unity_has_result = false;
 | 
					bool NotifierSupportsActions() {
 | 
				
			||||||
bool unity_result = false;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
bool UnityIsRunning() {
 | 
					 | 
				
			||||||
  if (getenv("ELECTRON_USE_UBUNTU_NOTIFIER"))
 | 
					  if (getenv("ELECTRON_USE_UBUNTU_NOTIFIER"))
 | 
				
			||||||
    return true;
 | 
					    return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (unity_has_result)
 | 
					  static bool notify_has_result = false;
 | 
				
			||||||
    return unity_result;
 | 
					  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.
 | 
					  capabilities = libnotify_loader_.notify_get_server_caps();
 | 
				
			||||||
  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;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  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) {
 | 
					void log_and_clear_error(GError* error, const char* context) {
 | 
				
			||||||
| 
						 | 
					@ -59,9 +53,6 @@ Notification* Notification::Create(NotificationDelegate* delegate,
 | 
				
			||||||
  return new LibnotifyNotification(delegate, presenter);
 | 
					  return new LibnotifyNotification(delegate, presenter);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// static
 | 
					 | 
				
			||||||
LibNotifyLoader LibnotifyNotification::libnotify_loader_;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// static
 | 
					// static
 | 
				
			||||||
bool LibnotifyNotification::Initialize() {
 | 
					bool LibnotifyNotification::Initialize() {
 | 
				
			||||||
  if (!libnotify_loader_.Load("libnotify.so.4") &&
 | 
					  if (!libnotify_loader_.Load("libnotify.so.4") &&
 | 
				
			||||||
| 
						 | 
					@ -83,6 +74,7 @@ LibnotifyNotification::LibnotifyNotification(NotificationDelegate* delegate,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
LibnotifyNotification::~LibnotifyNotification() {
 | 
					LibnotifyNotification::~LibnotifyNotification() {
 | 
				
			||||||
 | 
					  g_signal_handlers_disconnect_by_data(notification_, this);
 | 
				
			||||||
  g_object_unref(notification_);
 | 
					  g_object_unref(notification_);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -99,11 +91,9 @@ void LibnotifyNotification::Show(const base::string16& title,
 | 
				
			||||||
  g_signal_connect(
 | 
					  g_signal_connect(
 | 
				
			||||||
      notification_, "closed", G_CALLBACK(OnNotificationClosedThunk), this);
 | 
					      notification_, "closed", G_CALLBACK(OnNotificationClosedThunk), this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // NB: On Unity, adding a notification action will cause the notification
 | 
					  // NB: On Unity and on any other DE using Notify-OSD, adding a notification
 | 
				
			||||||
  // to display as a modal dialog box. Testing for distros that have "Unity
 | 
					  // action will cause the notification to display as a modal dialog box.
 | 
				
			||||||
  // Zen Nature" is difficult, we will test for the presence of the indicate
 | 
					  if (NotifierSupportsActions()) {
 | 
				
			||||||
  // dbus service
 | 
					 | 
				
			||||||
  if (!UnityIsRunning()) {
 | 
					 | 
				
			||||||
    libnotify_loader_.notify_notification_add_action(
 | 
					    libnotify_loader_.notify_notification_add_action(
 | 
				
			||||||
        notification_, "default", "View", OnNotificationViewThunk, this,
 | 
					        notification_, "default", "View", OnNotificationViewThunk, this,
 | 
				
			||||||
        nullptr);
 | 
					        nullptr);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -35,8 +35,6 @@ class LibnotifyNotification : public Notification {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void NotificationFailed();
 | 
					  void NotificationFailed();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  static LibNotifyLoader libnotify_loader_;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  NotifyNotification* notification_;
 | 
					  NotifyNotification* notification_;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  DISALLOW_COPY_AND_ASSIGN(LibnotifyNotification);
 | 
					  DISALLOW_COPY_AND_ASSIGN(LibnotifyNotification);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue