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 "brightray/browser/linux/libnotify_notification.h"
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "base/files/file_enumerator.h"
|
#include "base/files/file_enumerator.h"
|
||||||
|
#include "base/logging.h"
|
||||||
#include "base/strings/string_util.h"
|
#include "base/strings/string_util.h"
|
||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
#include "brightray/browser/notification_delegate.h"
|
#include "brightray/browser/notification_delegate.h"
|
||||||
|
@ -20,31 +23,26 @@ namespace {
|
||||||
|
|
||||||
LibNotifyLoader libnotify_loader_;
|
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 HasCapability(const std::string& capability) {
|
||||||
bool result = false;
|
return GetServerCapabilities().count(capability) != 0;
|
||||||
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() {
|
bool NotifierSupportsActions() {
|
||||||
if (getenv("ELECTRON_USE_UBUNTU_NOTIFIER"))
|
if (getenv("ELECTRON_USE_UBUNTU_NOTIFIER"))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
static bool notify_has_result = false;
|
return HasCapability("actions");
|
||||||
static bool notify_result = false;
|
|
||||||
|
|
||||||
if (notify_has_result)
|
|
||||||
return notify_result;
|
|
||||||
|
|
||||||
notify_result = HasCapability("actions");
|
|
||||||
return notify_result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void log_and_clear_error(GError* error, const char* context) {
|
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.5") &&
|
||||||
!libnotify_loader_.Load("libnotify.so.1") &&
|
!libnotify_loader_.Load("libnotify.so.1") &&
|
||||||
!libnotify_loader_.Load("libnotify.so")) {
|
!libnotify_loader_.Load("libnotify.so")) {
|
||||||
|
LOG(WARNING) << "Unable to find libnotify; notifications disabled";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!libnotify_loader_.notify_is_initted() &&
|
if (!libnotify_loader_.notify_is_initted() &&
|
||||||
!libnotify_loader_.notify_init(GetApplicationName().c_str())) {
|
!libnotify_loader_.notify_init(GetApplicationName().c_str())) {
|
||||||
|
LOG(WARNING) << "Unable to initialize libnotify; notifications disabled";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue