Windows Toasts: Hide(), Runtime Check, Header Cleanup
This commit is contained in:
parent
86ea0759d8
commit
8dbeca8c7f
4 changed files with 94 additions and 114 deletions
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) 2015 Felix Rieseberg <feriese@microsoft.com>. All rights reserved.
|
||||
// Copyright (c) 2015 Felix Rieseberg <feriese@microsoft.com> and Jason Poon <jason.poon@microsoft.com>. All rights reserved.
|
||||
// Copyright (c) 2015 Ryan McShane <rmcshane@bandwidth.com> and Brandon Smith <bsmith@bandwidth.com>
|
||||
// Thanks to both of those folks mentioned above who first thought up a bunch of this code
|
||||
// and released it as MIT to the world.
|
||||
|
@ -6,24 +6,19 @@
|
|||
#ifndef __WINDOWS_TOAST_NOTIFICATION_H__
|
||||
#define __WINDOWS_TOAST_NOTIFICATION_H__
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
|
||||
#include "content/public/browser/desktop_notification_delegate.h"
|
||||
#include "content/public/common/platform_notification_data.h"
|
||||
#include "base/bind.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include <windows.ui.notifications.h>
|
||||
#include <wrl/client.h>
|
||||
#include <wrl/implements.h>
|
||||
#include <string>
|
||||
|
||||
using namespace Microsoft::WRL;
|
||||
using namespace ABI::Windows::UI::Notifications;
|
||||
using namespace ABI::Windows::Foundation;
|
||||
using namespace ABI::Windows::Data::Xml::Dom;
|
||||
|
||||
namespace WinToasts{
|
||||
namespace WinToasts {
|
||||
|
||||
typedef ITypedEventHandler<ToastNotification*, IInspectable*> DesktopToastActivatedEventHandler;
|
||||
typedef ITypedEventHandler<ToastNotification*, ToastDismissedEventArgs*> DesktopToastDismissedEventHandler;
|
||||
|
@ -32,37 +27,35 @@ namespace WinToasts{
|
|||
|
||||
class WindowsToastNotification
|
||||
{
|
||||
private:
|
||||
static char s_appName[MAX_PATH];
|
||||
ToastEventHandler* m_eventHandler;
|
||||
content::DesktopNotificationDelegate* n_delegate;
|
||||
|
||||
HRESULT GetToastXml(IToastNotificationManagerStatics* toastMgr, const WCHAR* title, const WCHAR* msg, std::string iconPath, IXmlDocument** toastXml);
|
||||
HRESULT SetXmlText(IXmlDocument* doc, const WCHAR* text);
|
||||
HRESULT SetXmlText(IXmlDocument* doc, const WCHAR* title, const WCHAR* body);
|
||||
HRESULT SetXmlImage(IXmlDocument* doc, std::string iconPath);
|
||||
HRESULT GetTextNodeList(HSTRING* tag, IXmlDocument* doc, IXmlNodeList** nodeList, UINT32 reqLength);
|
||||
HRESULT AppendTextToXml(IXmlDocument* doc, IXmlNode* node, const WCHAR* text);
|
||||
HRESULT SetupCallbacks(IToastNotification* toast);
|
||||
HRESULT CreateHString(const WCHAR* source, HSTRING* dest);
|
||||
|
||||
public:
|
||||
WindowsToastNotification(const char* appName, content::DesktopNotificationDelegate* delegate);
|
||||
~WindowsToastNotification();
|
||||
void ShowNotification(const WCHAR* title, const WCHAR* msg, std::string iconPath);
|
||||
void ShowNotification(const WCHAR* title, const WCHAR* msg, std::string iconPath, ComPtr<IToastNotification>& toast);
|
||||
void DismissNotification(ComPtr<IToastNotification> toast);
|
||||
void NotificationClicked();
|
||||
void NotificationDismissed();
|
||||
|
||||
private:
|
||||
ToastEventHandler* m_eventHandler;
|
||||
|
||||
content::DesktopNotificationDelegate* n_delegate;
|
||||
ComPtr<IToastNotificationManagerStatics> m_toastManager;
|
||||
ComPtr<IToastNotifier> m_toastNotifier;
|
||||
|
||||
HRESULT GetToastXml(IToastNotificationManagerStatics* toastManager, const WCHAR* title, const WCHAR* msg, std::string iconPath, ABI::Windows::Data::Xml::Dom::IXmlDocument** toastXml);
|
||||
HRESULT SetXmlText(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, const WCHAR* text);
|
||||
HRESULT SetXmlText(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, const WCHAR* title, const WCHAR* body);
|
||||
HRESULT SetXmlImage(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, std::string iconPath);
|
||||
HRESULT GetTextNodeList(HSTRING* tag, ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, ABI::Windows::Data::Xml::Dom::IXmlNodeList** nodeList, UINT32 reqLength);
|
||||
HRESULT AppendTextToXml(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, ABI::Windows::Data::Xml::Dom::IXmlNode* node, const WCHAR* text);
|
||||
HRESULT SetupCallbacks(IToastNotification* toast);
|
||||
HRESULT CreateHString(const WCHAR* source, HSTRING* dest);
|
||||
};
|
||||
|
||||
|
||||
class ToastEventHandler :
|
||||
public Implements < DesktopToastActivatedEventHandler, DesktopToastDismissedEventHandler >
|
||||
public Implements <DesktopToastActivatedEventHandler, DesktopToastDismissedEventHandler>
|
||||
{
|
||||
private:
|
||||
ULONG m_ref;
|
||||
WindowsToastNotification* m_notification;
|
||||
content::DesktopNotificationDelegate* n_delegate;
|
||||
|
||||
public:
|
||||
ToastEventHandler(WindowsToastNotification* notification, content::DesktopNotificationDelegate* delegate);
|
||||
~ToastEventHandler();
|
||||
|
@ -92,6 +85,11 @@ namespace WinToasts{
|
|||
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
|
||||
private:
|
||||
ULONG m_ref;
|
||||
WindowsToastNotification* m_notification;
|
||||
content::DesktopNotificationDelegate* n_delegate;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue