Compare commits

...

4 Commits

Author SHA1 Message Date
Michaela Laurencin
43a80c49bf Merge branch 'main' into timeout-never-click-fix 2022-12-12 14:01:22 -08:00
Michaela Laurencin
8553cfee35 Merge branch 'main' into timeout-never-click-fix 2022-10-24 12:01:44 -07:00
Michaela Laurencin
522f595740 Merge branch 'main' into timeout-never-click-fix 2022-10-20 12:28:33 -07:00
mlaurencin
4d2720a9a3 fix: add pinning for timeout never notifications and xml printing for debugging 2022-10-19 14:54:08 -07:00
4 changed files with 35 additions and 1 deletions

View File

@@ -72,6 +72,11 @@ Notification::Notification(gin::Arguments* args) {
opts.Get("closeButtonText", &close_button_text_);
opts.Get("toastXml", &toast_xml_);
}
// The notification should not be garbage collected until it is interacted
// with
if (timeout_type_ == u"never")
Pin(JavascriptEnvironment::GetIsolate());
}
Notification::~Notification() {
@@ -160,6 +165,10 @@ void Notification::SetHasReply(bool new_has_reply) {
}
void Notification::SetTimeoutType(const std::u16string& new_timeout_type) {
// The notification should be garbage collected if it is not set to `never`
if (timeout_type_ == u"never" && new_timeout_type != u"never") {
Unpin();
}
timeout_type_ = new_timeout_type;
}
@@ -193,10 +202,12 @@ void Notification::NotificationAction(int index) {
}
void Notification::NotificationClick() {
Unpin();
Emit("click");
}
void Notification::NotificationReplied(const std::string& reply) {
Unpin();
Emit("reply", reply);
}
@@ -205,17 +216,22 @@ void Notification::NotificationDisplayed() {
}
void Notification::NotificationFailed(const std::string& error) {
Unpin();
Emit("failed", error);
}
void Notification::NotificationDestroyed() {}
void Notification::NotificationDestroyed() {
Unpin();
}
void Notification::NotificationClosed() {
Unpin();
Emit("close");
}
void Notification::Close() {
if (notification_) {
Unpin();
notification_->Dismiss();
notification_->set_delegate(nullptr);
notification_.reset();

View File

@@ -17,6 +17,7 @@
#include "shell/common/gin_helper/cleaned_up_at_exit.h"
#include "shell/common/gin_helper/constructible.h"
#include "shell/common/gin_helper/error_thrower.h"
#include "shell/common/gin_helper/pinnable.h"
#include "ui/gfx/image/image.h"
namespace gin {
@@ -28,6 +29,7 @@ class Handle;
namespace electron::api {
class Notification : public gin::Wrappable<Notification>,
public gin_helper::Pinnable<Notification>,
public gin_helper::EventEmitterMixin<Notification>,
public gin_helper::Constructible<Notification>,
public gin_helper::CleanedUpAtExit,

View File

@@ -15,6 +15,7 @@
#include "base/logging.h"
#include "base/strings/string_util_win.h"
#include "base/strings/utf_string_conversions.h"
#include "base/win/scoped_hstring.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "shell/browser/notifications/notification_delegate.h"
@@ -31,6 +32,7 @@ using ABI::Windows::Data::Xml::Dom::IXmlElement;
using ABI::Windows::Data::Xml::Dom::IXmlNamedNodeMap;
using ABI::Windows::Data::Xml::Dom::IXmlNode;
using ABI::Windows::Data::Xml::Dom::IXmlNodeList;
using ABI::Windows::Data::Xml::Dom::IXmlNodeSerializer;
using ABI::Windows::Data::Xml::Dom::IXmlText;
using Microsoft::WRL::Wrappers::HStringReference;
@@ -234,6 +236,18 @@ HRESULT WindowsToastNotification::GetToastXml(
return S_OK;
}
std::string WindowsToastNotification::XmlStringFromDocument(IXmlDocument* doc) {
ComPtr<IXmlNodeSerializer> ser;
ComPtr<IXmlElement> doc_elem;
doc->get_DocumentElement(&doc_elem);
doc_elem.As<IXmlNodeSerializer>(&ser);
HSTRING result_xml;
ser->GetXml(&result_xml);
base::win::ScopedHString result_string(result_xml);
return result_string.GetAsUTF8();
}
HRESULT WindowsToastNotification::SetXmlScenarioReminder(IXmlDocument* doc) {
ScopedHString tag(L"toast");
if (!tag.success())

View File

@@ -88,6 +88,8 @@ class WindowsToastNotification : public Notification {
HRESULT XmlDocumentFromString(
const wchar_t* xmlString,
ABI::Windows::Data::Xml::Dom::IXmlDocument** doc);
std::string XmlStringFromDocument(
ABI::Windows::Data::Xml::Dom::IXmlDocument* doc);
HRESULT SetupCallbacks(
ABI::Windows::UI::Notifications::IToastNotification* toast);
bool RemoveCallbacks(