win: Fire NotificationFailed when failed to show notification
This commit is contained in:
parent
c81bacc840
commit
82cef44623
2 changed files with 27 additions and 9 deletions
|
@ -13,6 +13,9 @@ class NotificationDelegate : public content::DesktopNotificationDelegate {
|
||||||
public:
|
public:
|
||||||
// The native Notification object is destroyed.
|
// The native Notification object is destroyed.
|
||||||
virtual void NotificationDestroyed() {}
|
virtual void NotificationDestroyed() {}
|
||||||
|
|
||||||
|
// Failed to send the notification.
|
||||||
|
virtual void NotificationFailed() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
|
@ -74,9 +74,11 @@ WindowsToastNotification::WindowsToastNotification(
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowsToastNotification::~WindowsToastNotification() {
|
WindowsToastNotification::~WindowsToastNotification() {
|
||||||
// Remove the notification on exit, regardless whether it succeeds.
|
// Remove the notification on exit.
|
||||||
RemoveCallbacks(toast_notification_.Get());
|
if (toast_notification_) {
|
||||||
Dismiss();
|
RemoveCallbacks(toast_notification_.Get());
|
||||||
|
Dismiss();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowsToastNotification::Show(
|
void WindowsToastNotification::Show(
|
||||||
|
@ -88,28 +90,40 @@ void WindowsToastNotification::Show(
|
||||||
std::wstring icon_path = presenter_win->SaveIconToFilesystem(icon, icon_url);
|
std::wstring icon_path = presenter_win->SaveIconToFilesystem(icon, icon_url);
|
||||||
|
|
||||||
ComPtr<IXmlDocument> toast_xml;
|
ComPtr<IXmlDocument> toast_xml;
|
||||||
if(FAILED(GetToastXml(toast_manager_.Get(), title, msg, icon_path, &toast_xml)))
|
if(FAILED(GetToastXml(toast_manager_.Get(), title, msg, icon_path, &toast_xml))) {
|
||||||
|
NotificationFailed();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ScopedHString toast_str(
|
ScopedHString toast_str(
|
||||||
RuntimeClass_Windows_UI_Notifications_ToastNotification);
|
RuntimeClass_Windows_UI_Notifications_ToastNotification);
|
||||||
if (!toast_str.success())
|
if (!toast_str.success()) {
|
||||||
|
NotificationFailed();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ComPtr<ABI::Windows::UI::Notifications::IToastNotificationFactory> toast_factory;
|
ComPtr<ABI::Windows::UI::Notifications::IToastNotificationFactory> toast_factory;
|
||||||
if (FAILED(Windows::Foundation::GetActivationFactory(toast_str,
|
if (FAILED(Windows::Foundation::GetActivationFactory(toast_str,
|
||||||
&toast_factory)))
|
&toast_factory))) {
|
||||||
|
NotificationFailed();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (FAILED(toast_factory->CreateToastNotification(toast_xml.Get(),
|
if (FAILED(toast_factory->CreateToastNotification(toast_xml.Get(),
|
||||||
&toast_notification_)))
|
&toast_notification_))) {
|
||||||
|
NotificationFailed();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (FAILED(SetupCallbacks(toast_notification_.Get())))
|
if (FAILED(SetupCallbacks(toast_notification_.Get()))) {
|
||||||
|
NotificationFailed();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (FAILED(toast_notifier_->Show(toast_notification_.Get())))
|
if (FAILED(toast_notifier_->Show(toast_notification_.Get()))) {
|
||||||
|
NotificationFailed();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
delegate()->NotificationDisplayed();
|
delegate()->NotificationDisplayed();
|
||||||
}
|
}
|
||||||
|
@ -129,6 +143,7 @@ void WindowsToastNotification::NotificationDismissed() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowsToastNotification::NotificationFailed() {
|
void WindowsToastNotification::NotificationFailed() {
|
||||||
|
delegate()->NotificationFailed();
|
||||||
Destroy();
|
Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue