mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: add pinning for timeout never notifications and xml printing for debugging
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user