Call content::DesktopNotificationDelegate::NotificationError when toast notification fails on Windows
This commit is contained in:
parent
cdc27a85c0
commit
dedf3553e2
2 changed files with 24 additions and 3 deletions
|
@ -85,6 +85,11 @@ void WindowsToastNotification::NotificationDismissed() {
|
||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WindowsToastNotification::NotificationFailed() {
|
||||||
|
delegate_->NotificationError();
|
||||||
|
delete this;
|
||||||
|
}
|
||||||
|
|
||||||
bool WindowsToastNotification::GetToastXml(
|
bool WindowsToastNotification::GetToastXml(
|
||||||
ABI::Windows::UI::Notifications::IToastNotificationManagerStatics* toastManager,
|
ABI::Windows::UI::Notifications::IToastNotificationManagerStatics* toastManager,
|
||||||
const std::wstring& title,
|
const std::wstring& title,
|
||||||
|
@ -231,12 +236,15 @@ bool WindowsToastNotification::AppendTextToXml(
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WindowsToastNotification::SetupCallbacks(ABI::Windows::UI::Notifications::IToastNotification* toast) {
|
bool WindowsToastNotification::SetupCallbacks(ABI::Windows::UI::Notifications::IToastNotification* toast) {
|
||||||
EventRegistrationToken activatedToken, dismissedToken;
|
EventRegistrationToken activatedToken, dismissedToken, failedToken;
|
||||||
event_handler_ = Make<ToastEventHandler>(this);
|
event_handler_ = Make<ToastEventHandler>(this);
|
||||||
if (FAILED(toast->add_Activated(event_handler_.Get(), &activatedToken)))
|
if (FAILED(toast->add_Activated(event_handler_.Get(), &activatedToken)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return SUCCEEDED(toast->add_Dismissed(event_handler_.Get(), &dismissedToken));
|
if (FAILED(toast->add_Dismissed(event_handler_.Get(), &dismissedToken)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return SUCCEEDED(toast->add_Failed(event_handler_.Get(), &failedToken));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -262,4 +270,11 @@ IFACEMETHODIMP ToastEventHandler::Invoke(
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IFACEMETHODIMP ToastEventHandler::Invoke(
|
||||||
|
ABI::Windows::UI::Notifications::IToastNotification* sender,
|
||||||
|
ABI::Windows::UI::Notifications::IToastFailedEventArgs* e) {
|
||||||
|
notification_->NotificationFailed();
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
|
@ -27,6 +27,9 @@ using DesktopToastActivatedEventHandler =
|
||||||
using DesktopToastDismissedEventHandler =
|
using DesktopToastDismissedEventHandler =
|
||||||
ABI::Windows::Foundation::ITypedEventHandler<ABI::Windows::UI::Notifications::ToastNotification*,
|
ABI::Windows::Foundation::ITypedEventHandler<ABI::Windows::UI::Notifications::ToastNotification*,
|
||||||
ABI::Windows::UI::Notifications::ToastDismissedEventArgs*>;
|
ABI::Windows::UI::Notifications::ToastDismissedEventArgs*>;
|
||||||
|
using DesktopToastFailedEventHandler =
|
||||||
|
ABI::Windows::Foundation::ITypedEventHandler<ABI::Windows::UI::Notifications::ToastNotification*,
|
||||||
|
ABI::Windows::UI::Notifications::ToastFailedEventArgs*>;
|
||||||
|
|
||||||
class WindowsToastNotification {
|
class WindowsToastNotification {
|
||||||
public:
|
public:
|
||||||
|
@ -49,6 +52,7 @@ class WindowsToastNotification {
|
||||||
|
|
||||||
void NotificationClicked();
|
void NotificationClicked();
|
||||||
void NotificationDismissed();
|
void NotificationDismissed();
|
||||||
|
void NotificationFailed();
|
||||||
|
|
||||||
bool GetToastXml(ABI::Windows::UI::Notifications::IToastNotificationManagerStatics* toastManager,
|
bool GetToastXml(ABI::Windows::UI::Notifications::IToastNotificationManagerStatics* toastManager,
|
||||||
const std::wstring& title,
|
const std::wstring& title,
|
||||||
|
@ -85,13 +89,15 @@ class WindowsToastNotification {
|
||||||
|
|
||||||
class ToastEventHandler : public RuntimeClass<RuntimeClassFlags<ClassicCom>,
|
class ToastEventHandler : public RuntimeClass<RuntimeClassFlags<ClassicCom>,
|
||||||
DesktopToastActivatedEventHandler,
|
DesktopToastActivatedEventHandler,
|
||||||
DesktopToastDismissedEventHandler> {
|
DesktopToastDismissedEventHandler,
|
||||||
|
DesktopToastFailedEventHandler> {
|
||||||
public:
|
public:
|
||||||
ToastEventHandler(WindowsToastNotification* notification);
|
ToastEventHandler(WindowsToastNotification* notification);
|
||||||
~ToastEventHandler();
|
~ToastEventHandler();
|
||||||
|
|
||||||
IFACEMETHODIMP Invoke(ABI::Windows::UI::Notifications::IToastNotification* sender, IInspectable* args);
|
IFACEMETHODIMP Invoke(ABI::Windows::UI::Notifications::IToastNotification* sender, IInspectable* args);
|
||||||
IFACEMETHODIMP Invoke(ABI::Windows::UI::Notifications::IToastNotification* sender, ABI::Windows::UI::Notifications::IToastDismissedEventArgs* e);
|
IFACEMETHODIMP Invoke(ABI::Windows::UI::Notifications::IToastNotification* sender, ABI::Windows::UI::Notifications::IToastDismissedEventArgs* e);
|
||||||
|
IFACEMETHODIMP Invoke(ABI::Windows::UI::Notifications::IToastNotification* sender, ABI::Windows::UI::Notifications::IToastFailedEventArgs* e);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WindowsToastNotification* notification_; // weak ref.
|
WindowsToastNotification* notification_; // weak ref.
|
||||||
|
|
Loading…
Reference in a new issue