Call content::DesktopNotificationDelegate::NotificationError when toast notification fails on Windows

This commit is contained in:
Milan Burda 2015-11-10 20:39:24 +01:00
parent cdc27a85c0
commit dedf3553e2
2 changed files with 24 additions and 3 deletions

View file

@ -85,6 +85,11 @@ void WindowsToastNotification::NotificationDismissed() {
delete this;
}
void WindowsToastNotification::NotificationFailed() {
delegate_->NotificationError();
delete this;
}
bool WindowsToastNotification::GetToastXml(
ABI::Windows::UI::Notifications::IToastNotificationManagerStatics* toastManager,
const std::wstring& title,
@ -231,12 +236,15 @@ bool WindowsToastNotification::AppendTextToXml(
}
bool WindowsToastNotification::SetupCallbacks(ABI::Windows::UI::Notifications::IToastNotification* toast) {
EventRegistrationToken activatedToken, dismissedToken;
EventRegistrationToken activatedToken, dismissedToken, failedToken;
event_handler_ = Make<ToastEventHandler>(this);
if (FAILED(toast->add_Activated(event_handler_.Get(), &activatedToken)))
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;
}
IFACEMETHODIMP ToastEventHandler::Invoke(
ABI::Windows::UI::Notifications::IToastNotification* sender,
ABI::Windows::UI::Notifications::IToastFailedEventArgs* e) {
notification_->NotificationFailed();
return S_OK;
}
} // namespace brightray

View file

@ -27,6 +27,9 @@ using DesktopToastActivatedEventHandler =
using DesktopToastDismissedEventHandler =
ABI::Windows::Foundation::ITypedEventHandler<ABI::Windows::UI::Notifications::ToastNotification*,
ABI::Windows::UI::Notifications::ToastDismissedEventArgs*>;
using DesktopToastFailedEventHandler =
ABI::Windows::Foundation::ITypedEventHandler<ABI::Windows::UI::Notifications::ToastNotification*,
ABI::Windows::UI::Notifications::ToastFailedEventArgs*>;
class WindowsToastNotification {
public:
@ -49,6 +52,7 @@ class WindowsToastNotification {
void NotificationClicked();
void NotificationDismissed();
void NotificationFailed();
bool GetToastXml(ABI::Windows::UI::Notifications::IToastNotificationManagerStatics* toastManager,
const std::wstring& title,
@ -85,13 +89,15 @@ class WindowsToastNotification {
class ToastEventHandler : public RuntimeClass<RuntimeClassFlags<ClassicCom>,
DesktopToastActivatedEventHandler,
DesktopToastDismissedEventHandler> {
DesktopToastDismissedEventHandler,
DesktopToastFailedEventHandler> {
public:
ToastEventHandler(WindowsToastNotification* notification);
~ToastEventHandler();
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::IToastFailedEventArgs* e);
private:
WindowsToastNotification* notification_; // weak ref.