perf: cache whether or not ELECTRON_DEBUG_NOTIFICATIONS env var is set (#45161)
* perf: cache whether or not ELECTRON_DEBUG_NOTIFICATIONS env var is set Co-authored-by: Charles Kerr <charles@charleskerr.com> * chore: remove unused #include Co-authored-by: Charles Kerr <charles@charleskerr.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
parent
dd85ddce20
commit
48aba26aac
7 changed files with 12 additions and 12 deletions
|
@ -44,7 +44,7 @@ void CocoaNotification::Show(const NotificationOptions& options) {
|
||||||
[notification_ setInformativeText:base::SysUTF16ToNSString(options.msg)];
|
[notification_ setInformativeText:base::SysUTF16ToNSString(options.msg)];
|
||||||
[notification_ setIdentifier:identifier];
|
[notification_ setIdentifier:identifier];
|
||||||
|
|
||||||
if (getenv("ELECTRON_DEBUG_NOTIFICATIONS")) {
|
if (electron::debug_notifications) {
|
||||||
LOG(INFO) << "Notification created (" << [identifier UTF8String] << ")";
|
LOG(INFO) << "Notification created (" << [identifier UTF8String] << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ void CocoaNotification::NotificationDismissed() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CocoaNotification::LogAction(const char* action) {
|
void CocoaNotification::LogAction(const char* action) {
|
||||||
if (getenv("ELECTRON_DEBUG_NOTIFICATIONS") && notification_) {
|
if (electron::debug_notifications && notification_) {
|
||||||
NSString* identifier = [notification_ valueForKey:@"identifier"];
|
NSString* identifier = [notification_ valueForKey:@"identifier"];
|
||||||
DCHECK(identifier);
|
DCHECK(identifier);
|
||||||
LOG(INFO) << "Notification " << action << " (" << [identifier UTF8String]
|
LOG(INFO) << "Notification " << action << " (" << [identifier UTF8String]
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
didActivateNotification:(NSUserNotification*)notif {
|
didActivateNotification:(NSUserNotification*)notif {
|
||||||
auto* notification = presenter_->GetNotification(notif);
|
auto* notification = presenter_->GetNotification(notif);
|
||||||
|
|
||||||
if (getenv("ELECTRON_DEBUG_NOTIFICATIONS")) {
|
if (electron::debug_notifications) {
|
||||||
LOG(INFO) << "Notification activated (" << [notif.identifier UTF8String]
|
LOG(INFO) << "Notification activated (" << [notif.identifier UTF8String]
|
||||||
<< ")";
|
<< ")";
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ CocoaNotification* NotificationPresenterMac::GetNotification(
|
||||||
return native_notification;
|
return native_notification;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getenv("ELECTRON_DEBUG_NOTIFICATIONS")) {
|
if (electron::debug_notifications) {
|
||||||
LOG(INFO) << "Could not find notification for "
|
LOG(INFO) << "Could not find notification for "
|
||||||
<< [ns_notification.identifier UTF8String];
|
<< [ns_notification.identifier UTF8String];
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,15 @@
|
||||||
|
|
||||||
#include "shell/browser/notifications/notification.h"
|
#include "shell/browser/notifications/notification.h"
|
||||||
|
|
||||||
|
#include "base/environment.h"
|
||||||
#include "shell/browser/notifications/notification_delegate.h"
|
#include "shell/browser/notifications/notification_delegate.h"
|
||||||
#include "shell/browser/notifications/notification_presenter.h"
|
#include "shell/browser/notifications/notification_presenter.h"
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
|
||||||
|
const bool debug_notifications =
|
||||||
|
base::Environment::Create()->HasVar("ELECTRON_DEBUG_NOTIFICATIONS");
|
||||||
|
|
||||||
NotificationOptions::NotificationOptions() = default;
|
NotificationOptions::NotificationOptions() = default;
|
||||||
NotificationOptions::~NotificationOptions() = default;
|
NotificationOptions::~NotificationOptions() = default;
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
|
||||||
|
extern const bool debug_notifications;
|
||||||
|
|
||||||
class NotificationDelegate;
|
class NotificationDelegate;
|
||||||
class NotificationPresenter;
|
class NotificationPresenter;
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "base/environment.h"
|
|
||||||
#include "base/files/file_util.h"
|
#include "base/files/file_util.h"
|
||||||
#include "base/hash/md5.h"
|
#include "base/hash/md5.h"
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
|
@ -28,10 +27,6 @@ namespace electron {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
bool IsDebuggingNotifications() {
|
|
||||||
return base::Environment::Create()->HasVar("ELECTRON_DEBUG_NOTIFICATIONS");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SaveIconToPath(const SkBitmap& bitmap, const base::FilePath& path) {
|
bool SaveIconToPath(const SkBitmap& bitmap, const base::FilePath& path) {
|
||||||
std::vector<unsigned char> png_data;
|
std::vector<unsigned char> png_data;
|
||||||
if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &png_data))
|
if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &png_data))
|
||||||
|
@ -50,7 +45,7 @@ std::unique_ptr<NotificationPresenter> NotificationPresenter::Create() {
|
||||||
if (!presenter->Init())
|
if (!presenter->Init())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
if (IsDebuggingNotifications())
|
if (electron::debug_notifications)
|
||||||
LOG(INFO) << "Successfully created Windows notifications presenter";
|
LOG(INFO) << "Successfully created Windows notifications presenter";
|
||||||
|
|
||||||
return presenter;
|
return presenter;
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
#include <shlobj.h>
|
#include <shlobj.h>
|
||||||
#include <wrl\wrappers\corewrappers.h>
|
#include <wrl\wrappers\corewrappers.h>
|
||||||
|
|
||||||
#include "base/environment.h"
|
|
||||||
#include "base/hash/hash.h"
|
#include "base/hash/hash.h"
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
#include "base/strings/strcat.h"
|
#include "base/strings/strcat.h"
|
||||||
|
@ -67,7 +66,7 @@ namespace {
|
||||||
constexpr wchar_t kGroup[] = L"Notifications";
|
constexpr wchar_t kGroup[] = L"Notifications";
|
||||||
|
|
||||||
void DebugLog(std::string_view log_msg) {
|
void DebugLog(std::string_view log_msg) {
|
||||||
if (base::Environment::Create()->HasVar("ELECTRON_DEBUG_NOTIFICATIONS"))
|
if (electron::debug_notifications)
|
||||||
LOG(INFO) << log_msg;
|
LOG(INFO) << log_msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue