diff --git a/shell/browser/notifications/mac/cocoa_notification.mm b/shell/browser/notifications/mac/cocoa_notification.mm index 9138515dc570..a90842f09616 100644 --- a/shell/browser/notifications/mac/cocoa_notification.mm +++ b/shell/browser/notifications/mac/cocoa_notification.mm @@ -44,7 +44,7 @@ void CocoaNotification::Show(const NotificationOptions& options) { [notification_ setInformativeText:base::SysUTF16ToNSString(options.msg)]; [notification_ setIdentifier:identifier]; - if (getenv("ELECTRON_DEBUG_NOTIFICATIONS")) { + if (electron::debug_notifications) { LOG(INFO) << "Notification created (" << [identifier UTF8String] << ")"; } @@ -170,7 +170,7 @@ void CocoaNotification::NotificationDismissed() { } void CocoaNotification::LogAction(const char* action) { - if (getenv("ELECTRON_DEBUG_NOTIFICATIONS") && notification_) { + if (electron::debug_notifications && notification_) { NSString* identifier = [notification_ valueForKey:@"identifier"]; DCHECK(identifier); LOG(INFO) << "Notification " << action << " (" << [identifier UTF8String] diff --git a/shell/browser/notifications/mac/notification_center_delegate.mm b/shell/browser/notifications/mac/notification_center_delegate.mm index aceec2336b78..64513e7c4193 100644 --- a/shell/browser/notifications/mac/notification_center_delegate.mm +++ b/shell/browser/notifications/mac/notification_center_delegate.mm @@ -39,7 +39,7 @@ didActivateNotification:(NSUserNotification*)notif { auto* notification = presenter_->GetNotification(notif); - if (getenv("ELECTRON_DEBUG_NOTIFICATIONS")) { + if (electron::debug_notifications) { LOG(INFO) << "Notification activated (" << [notif.identifier UTF8String] << ")"; } diff --git a/shell/browser/notifications/mac/notification_presenter_mac.mm b/shell/browser/notifications/mac/notification_presenter_mac.mm index d94181ef59ff..e2c8ec63e101 100644 --- a/shell/browser/notifications/mac/notification_presenter_mac.mm +++ b/shell/browser/notifications/mac/notification_presenter_mac.mm @@ -30,7 +30,7 @@ CocoaNotification* NotificationPresenterMac::GetNotification( return native_notification; } - if (getenv("ELECTRON_DEBUG_NOTIFICATIONS")) { + if (electron::debug_notifications) { LOG(INFO) << "Could not find notification for " << [ns_notification.identifier UTF8String]; } diff --git a/shell/browser/notifications/notification.cc b/shell/browser/notifications/notification.cc index 72390804824a..39d9bc8f8eb0 100644 --- a/shell/browser/notifications/notification.cc +++ b/shell/browser/notifications/notification.cc @@ -4,11 +4,15 @@ #include "shell/browser/notifications/notification.h" +#include "base/environment.h" #include "shell/browser/notifications/notification_delegate.h" #include "shell/browser/notifications/notification_presenter.h" namespace electron { +const bool debug_notifications = + base::Environment::Create()->HasVar("ELECTRON_DEBUG_NOTIFICATIONS"); + NotificationOptions::NotificationOptions() = default; NotificationOptions::~NotificationOptions() = default; diff --git a/shell/browser/notifications/notification.h b/shell/browser/notifications/notification.h index ab9f81845caa..f4b687b866f5 100644 --- a/shell/browser/notifications/notification.h +++ b/shell/browser/notifications/notification.h @@ -15,6 +15,8 @@ namespace electron { +extern const bool debug_notifications; + class NotificationDelegate; class NotificationPresenter; diff --git a/shell/browser/notifications/win/notification_presenter_win.cc b/shell/browser/notifications/win/notification_presenter_win.cc index 073bd19e67d0..4ceb7e6b64ee 100644 --- a/shell/browser/notifications/win/notification_presenter_win.cc +++ b/shell/browser/notifications/win/notification_presenter_win.cc @@ -10,7 +10,6 @@ #include #include -#include "base/environment.h" #include "base/files/file_util.h" #include "base/hash/md5.h" #include "base/logging.h" @@ -27,10 +26,6 @@ namespace electron { namespace { -bool IsDebuggingNotifications() { - return base::Environment::Create()->HasVar("ELECTRON_DEBUG_NOTIFICATIONS"); -} - bool SaveIconToPath(const SkBitmap& bitmap, const base::FilePath& path) { std::optional> png_data = gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false); @@ -50,7 +45,7 @@ std::unique_ptr NotificationPresenter::Create() { if (!presenter->Init()) return {}; - if (IsDebuggingNotifications()) + if (electron::debug_notifications) LOG(INFO) << "Successfully created Windows notifications presenter"; return presenter; diff --git a/shell/browser/notifications/win/windows_toast_notification.cc b/shell/browser/notifications/win/windows_toast_notification.cc index 1f5d3c316788..73fd9a36f338 100644 --- a/shell/browser/notifications/win/windows_toast_notification.cc +++ b/shell/browser/notifications/win/windows_toast_notification.cc @@ -13,7 +13,6 @@ #include #include -#include "base/environment.h" #include "base/hash/hash.h" #include "base/logging.h" #include "base/strings/strcat.h" @@ -66,7 +65,7 @@ namespace { constexpr wchar_t kGroup[] = L"Notifications"; void DebugLog(std::string_view log_msg) { - if (base::Environment::Create()->HasVar("ELECTRON_DEBUG_NOTIFICATIONS")) + if (electron::debug_notifications) LOG(INFO) << log_msg; }