From 8a8aaaf16c2b80b4d183975b34158f16ac06608f Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Wed, 13 Dec 2017 16:25:49 -0800 Subject: [PATCH] :wrench: Allow notifications debugging (Windows) --- .../browser/win/notification_presenter_win.cc | 10 ++++++++ .../browser/win/windows_toast_notification.cc | 23 ++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/brightray/browser/win/notification_presenter_win.cc b/brightray/browser/win/notification_presenter_win.cc index 35f9799b8dab..d02f363fecea 100644 --- a/brightray/browser/win/notification_presenter_win.cc +++ b/brightray/browser/win/notification_presenter_win.cc @@ -13,6 +13,7 @@ #include "base/md5.h" #include "base/strings/utf_string_conversions.h" #include "base/time/time.h" +#include "base/environment.h" #include "base/win/windows_version.h" #include "brightray/browser/win/notification_presenter_win7.h" #include "brightray/browser/win/windows_toast_notification.h" @@ -26,6 +27,10 @@ namespace brightray { namespace { +bool IsDebuggingNotifications() { + return base::Environment::Create()->HasVar("ELECTRON_DEBUG_NOTIFICATIONS"); +} + bool SaveIconToPath(const SkBitmap& bitmap, const base::FilePath& path) { std::vector png_data; if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &png_data)) @@ -49,6 +54,11 @@ NotificationPresenter* NotificationPresenter::Create() { new NotificationPresenterWin); if (!presenter->Init()) return nullptr; + + if (IsDebuggingNotifications()) { + LOG(INFO) << "Successfully created Windows notifications presenter"; + } + return presenter.release(); } diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index 13a8f002616e..c6301f55a0a0 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -11,6 +11,7 @@ #include #include +#include "base/environment.h" #include "base/strings/utf_string_conversions.h" #include "brightray/browser/notification_delegate.h" #include "brightray/browser/win/notification_presenter_win.h" @@ -26,6 +27,7 @@ using ABI::Windows::Data::Xml::Dom::IXmlNode; using ABI::Windows::Data::Xml::Dom::IXmlNodeList; using ABI::Windows::Data::Xml::Dom::IXmlText; + namespace brightray { namespace { @@ -41,6 +43,10 @@ bool GetAppUserModelId(ScopedHString* app_id) { return app_id->success(); } +bool IsDebuggingNotifications() { + return base::Environment::Create()->HasVar("ELECTRON_DEBUG_NOTIFICATIONS"); +} + } // namespace // static @@ -90,7 +96,7 @@ void WindowsToastNotification::Show(const NotificationOptions& options) { std::wstring icon_path = presenter_win->SaveIconToFilesystem( options.icon, options.icon_url); - + ComPtr toast_xml; if (FAILED(GetToastXml(toast_manager_.Get(), options.title, options.msg, icon_path, options.silent, &toast_xml))) { @@ -129,11 +135,14 @@ void WindowsToastNotification::Show(const NotificationOptions& options) { return; } + if (IsDebuggingNotifications()) LOG(INFO) << "Notification created"; + if (delegate()) delegate()->NotificationDisplayed(); } void WindowsToastNotification::Dismiss() { + if (IsDebuggingNotifications()) LOG(INFO) << "Hiding notification"; toast_notifier_->Hide(toast_notification_.Get()); } @@ -165,14 +174,20 @@ bool WindowsToastNotification::GetToastXml( : ABI::Windows::UI::Notifications:: ToastTemplateType_ToastImageAndText02; if (FAILED(toastManager->GetTemplateContent(template_type, toast_xml))) + if (IsDebuggingNotifications()) LOG(INFO) << "Fetching XML template failed"; return false; if (!SetXmlText(*toast_xml, title, msg)) + if (IsDebuggingNotifications()) LOG(INFO) << "Setting text fields on template failed"; return false; } // Configure the toast's notification sound if (silent) { if (FAILED(SetXmlAudioSilent(*toast_xml))) + if (IsDebuggingNotifications()) { + LOG(INFO) << "Setting \"silent\" option on notification failed"; + } + return false; } @@ -398,6 +413,8 @@ IFACEMETHODIMP ToastEventHandler::Invoke( content::BrowserThread::PostTask( content::BrowserThread::UI, FROM_HERE, base::Bind(&Notification::NotificationClicked, notification_)); + if (IsDebuggingNotifications()) LOG(INFO) << "Notification clicked"; + return S_OK; } @@ -407,6 +424,8 @@ IFACEMETHODIMP ToastEventHandler::Invoke( content::BrowserThread::PostTask( content::BrowserThread::UI, FROM_HERE, base::Bind(&Notification::NotificationDismissed, notification_)); + if (IsDebuggingNotifications()) LOG(INFO) << "Notification dismissed"; + return S_OK; } @@ -416,6 +435,8 @@ IFACEMETHODIMP ToastEventHandler::Invoke( content::BrowserThread::PostTask( content::BrowserThread::UI, FROM_HERE, base::Bind(&Notification::NotificationFailed, notification_)); + if (IsDebuggingNotifications()) LOG(INFO) << "Notification failed"; + return S_OK; }