Cache libnotify server caps (#11965)
* cache libnotify server capabilities * fix broken production cache in NotifierSupportsActions() * log a warning if LibnotifyNotification::Initialize() fails
This commit is contained in:
parent
459a5e3a1f
commit
2a16b28be4
1 changed files with 18 additions and 18 deletions
|
@ -4,9 +4,12 @@
|
|||
|
||||
#include "brightray/browser/linux/libnotify_notification.h"
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/files/file_enumerator.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "brightray/browser/notification_delegate.h"
|
||||
|
@ -20,31 +23,26 @@ namespace {
|
|||
|
||||
LibNotifyLoader libnotify_loader_;
|
||||
|
||||
const std::set<std::string>& GetServerCapabilities() {
|
||||
static std::set<std::string> caps;
|
||||
if (caps.empty()) {
|
||||
auto capabilities = libnotify_loader_.notify_get_server_caps();
|
||||
for (auto l=capabilities; l != nullptr; l=l->next)
|
||||
caps.insert(static_cast<const char*>(l->data));
|
||||
g_list_free_full(capabilities, g_free);
|
||||
}
|
||||
return caps;
|
||||
}
|
||||
|
||||
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;
|
||||
return GetServerCapabilities().count(capability) != 0;
|
||||
}
|
||||
|
||||
bool NotifierSupportsActions() {
|
||||
if (getenv("ELECTRON_USE_UBUNTU_NOTIFIER"))
|
||||
return false;
|
||||
|
||||
static bool notify_has_result = false;
|
||||
static bool notify_result = false;
|
||||
|
||||
if (notify_has_result)
|
||||
return notify_result;
|
||||
|
||||
notify_result = HasCapability("actions");
|
||||
return notify_result;
|
||||
return HasCapability("actions");
|
||||
}
|
||||
|
||||
void log_and_clear_error(GError* error, const char* context) {
|
||||
|
@ -63,10 +61,12 @@ bool LibnotifyNotification::Initialize() {
|
|||
!libnotify_loader_.Load("libnotify.so.5") &&
|
||||
!libnotify_loader_.Load("libnotify.so.1") &&
|
||||
!libnotify_loader_.Load("libnotify.so")) {
|
||||
LOG(WARNING) << "Unable to find libnotify; notifications disabled";
|
||||
return false;
|
||||
}
|
||||
if (!libnotify_loader_.notify_is_initted() &&
|
||||
!libnotify_loader_.notify_init(GetApplicationName().c_str())) {
|
||||
LOG(WARNING) << "Unable to initialize libnotify; notifications disabled";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue