Code cleanup
This commit is contained in:
parent
03688b9415
commit
c6196810a6
11 changed files with 758 additions and 614 deletions
|
@ -15,14 +15,15 @@ AtomToastHandler::AtomToastHandler(atom::api::Notification* target) {
|
|||
|
||||
void AtomToastHandler::toastActivated() {
|
||||
observer_->OnClicked();
|
||||
};
|
||||
}
|
||||
|
||||
void AtomToastHandler::toastDismissed(WinToastLib::WinToastHandler::WinToastDismissalReason state) {
|
||||
void AtomToastHandler::toastDismissed(
|
||||
WinToastLib::WinToastHandler::WinToastDismissalReason state) {
|
||||
// observer_->OnDismissed();
|
||||
};
|
||||
}
|
||||
|
||||
void AtomToastHandler::toastFailed() {
|
||||
// observer_->OnErrored();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -5,21 +5,22 @@
|
|||
#include "atom/browser/ui/win/toast_lib.h"
|
||||
#include "atom/browser/api/atom_api_notification.h"
|
||||
|
||||
#ifndef ATOM_BROWSER_UI_TOAST_HANDLER_H_
|
||||
#define ATOM_BROWSER_UI_TOAST_HANDLER_H_
|
||||
#ifndef ATOM_BROWSER_UI_WIN_TOAST_HANDLER_H_
|
||||
#define ATOM_BROWSER_UI_WIN_TOAST_HANDLER_H_
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomToastHandler : public WinToastLib::WinToastHandler {
|
||||
public:
|
||||
atom::api::Notification* observer_;
|
||||
AtomToastHandler(atom::api::Notification* target);
|
||||
explicit AtomToastHandler(atom::api::Notification* target);
|
||||
|
||||
void toastActivated() override;
|
||||
void toastDismissed(WinToastLib::WinToastHandler::WinToastDismissalReason state);
|
||||
void toastDismissed(
|
||||
WinToastLib::WinToastHandler::WinToastDismissalReason state);
|
||||
void toastFailed();
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_BROWSER_UI_TOAST_HANDLER_H_
|
||||
#endif // ATOM_BROWSER_UI_WIN_TOAST_HANDLER_H_
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -9,8 +9,8 @@
|
|||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
|
@ -20,149 +20,179 @@
|
|||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#ifndef WINTOASTLIB_H
|
||||
#define WINTOASTLIB_H
|
||||
#include <windows.h>
|
||||
#include <SDKDDKVer.h>
|
||||
#include <WinUser.h>
|
||||
#include <Shobjidl.h>
|
||||
#include <wrl/implements.h>
|
||||
#include <wrl/event.h>
|
||||
#include <windows.ui.notifications.h>
|
||||
#include <strsafe.h>
|
||||
#include <Psapi.h>
|
||||
#include <shlobj.h>
|
||||
#include <roapi.h>
|
||||
#include <propvarutil.h>
|
||||
#include <functiondiscoverykeys.h>
|
||||
#include <iostream>
|
||||
#include <winstring.h>
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
using namespace Microsoft::WRL;
|
||||
using namespace ABI::Windows::Data::Xml::Dom;
|
||||
using namespace ABI::Windows::Foundation;
|
||||
using namespace ABI::Windows::UI::Notifications;
|
||||
using namespace Windows::Foundation;
|
||||
#ifndef ATOM_BROWSER_UI_WIN_TOAST_LIB_H_
|
||||
#define ATOM_BROWSER_UI_WIN_TOAST_LIB_H_
|
||||
|
||||
#define DEFAULT_SHELL_LINKS_PATH L"\\Microsoft\\Windows\\Start Menu\\Programs\\"
|
||||
#define DEFAULT_LINK_FORMAT L".lnk"
|
||||
#include <string.h>
|
||||
#include <winstring.h>
|
||||
|
||||
#include <SDKDDKVer.h>
|
||||
#include <Shobjidl.h>
|
||||
#include <WinUser.h>
|
||||
|
||||
#include <functiondiscoverykeys.h>
|
||||
#include <propvarutil.h>
|
||||
#include <roapi.h>
|
||||
#include <shlobj.h>
|
||||
#include <strsafe.h>
|
||||
#include <windows.h>
|
||||
#include <windows.ui.notifications.h>
|
||||
#include <wrl/event.h>
|
||||
#include <wrl/implements.h>
|
||||
|
||||
#include <Psapi.h>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using Microsoft::WRL::ComPtr;
|
||||
using Microsoft::WRL::Details::ComPtrRef;
|
||||
using Microsoft::WRL::Callback;
|
||||
using Microsoft::WRL::Implements;
|
||||
using Microsoft::WRL::RuntimeClassFlags;
|
||||
using Microsoft::WRL::ClassicCom;
|
||||
using ABI::Windows::Data::Xml::Dom::IXmlAttribute;
|
||||
using ABI::Windows::Data::Xml::Dom::IXmlDocument;
|
||||
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::IXmlText;
|
||||
using ABI::Windows::UI::Notifications::ToastDismissalReason;
|
||||
using ABI::Windows::UI::Notifications::ToastTemplateType;
|
||||
using ABI::Windows::UI::Notifications::IToastNotificationManagerStatics;
|
||||
using ABI::Windows::UI::Notifications::IToastNotifier;
|
||||
using ABI::Windows::UI::Notifications::IToastNotificationFactory;
|
||||
using ABI::Windows::UI::Notifications::IToastNotification;
|
||||
using ABI::Windows::UI::Notifications::ToastNotification;
|
||||
using ABI::Windows::UI::Notifications::ToastDismissedEventArgs;
|
||||
using ABI::Windows::UI::Notifications::IToastDismissedEventArgs;
|
||||
using ABI::Windows::UI::Notifications::ToastFailedEventArgs;
|
||||
using ABI::Windows::UI::Notifications::IToastFailedEventArgs;
|
||||
using ABI::Windows::UI::Notifications::ToastTemplateType_ToastText01;
|
||||
using ABI::Windows::Foundation::ITypedEventHandler;
|
||||
|
||||
#define DEFAULT_SHELL_LINKS_PATH L"\\Microsoft\\Windows\\Start Menu\\Programs\\"
|
||||
#define DEFAULT_LINK_FORMAT L".lnk"
|
||||
|
||||
namespace WinToastLib {
|
||||
class WinToastStringWrapper {
|
||||
public:
|
||||
WinToastStringWrapper(_In_reads_(length) PCWSTR stringRef, _In_ UINT32 length) throw();
|
||||
WinToastStringWrapper(_In_ const std::wstring &stringRef) throw();
|
||||
~WinToastStringWrapper();
|
||||
HSTRING Get() const throw();
|
||||
private:
|
||||
HSTRING _hstring;
|
||||
HSTRING_HEADER _header;
|
||||
class WinToastStringWrapper {
|
||||
public:
|
||||
WinToastStringWrapper(_In_reads_(length) PCWSTR stringRef,
|
||||
_In_ UINT32 length) throw();
|
||||
explicit WinToastStringWrapper(_In_ const std::wstring& stringRef) throw();
|
||||
~WinToastStringWrapper();
|
||||
HSTRING Get() const throw();
|
||||
|
||||
};
|
||||
private:
|
||||
HSTRING _hstring;
|
||||
HSTRING_HEADER _header;
|
||||
};
|
||||
|
||||
class WinToastHandler {
|
||||
public:
|
||||
enum WinToastDismissalReason {
|
||||
UserCanceled = ToastDismissalReason::ToastDismissalReason_UserCanceled,
|
||||
ApplicationHidden =
|
||||
ToastDismissalReason::ToastDismissalReason_ApplicationHidden,
|
||||
TimedOut = ToastDismissalReason::ToastDismissalReason_TimedOut
|
||||
};
|
||||
|
||||
class WinToastHandler {
|
||||
public:
|
||||
enum WinToastDismissalReason {
|
||||
UserCanceled = ToastDismissalReason::ToastDismissalReason_UserCanceled,
|
||||
ApplicationHidden = ToastDismissalReason::ToastDismissalReason_ApplicationHidden,
|
||||
TimedOut = ToastDismissalReason::ToastDismissalReason_TimedOut
|
||||
};
|
||||
virtual void toastActivated() {}
|
||||
virtual void toastDismissed(WinToastDismissalReason state) {}
|
||||
virtual void toastFailed() {}
|
||||
};
|
||||
|
||||
virtual void toastActivated() {};
|
||||
virtual void toastDismissed(WinToastDismissalReason state) {};
|
||||
virtual void toastFailed() {};
|
||||
};
|
||||
class WinToastTemplate {
|
||||
public:
|
||||
enum TextField { FirstLine = 0, SecondLine, ThirdLine, LineCount };
|
||||
|
||||
class WinToastTemplate
|
||||
{
|
||||
public:
|
||||
enum TextField {
|
||||
FirstLine = 0,
|
||||
SecondLine,
|
||||
ThirdLine,
|
||||
LineCount
|
||||
};
|
||||
enum WinToastTemplateType {
|
||||
ImageWithOneLine = ToastTemplateType::ToastTemplateType_ToastImageAndText01,
|
||||
ImageWithTwoLines =
|
||||
ToastTemplateType::ToastTemplateType_ToastImageAndText02,
|
||||
ImageWithThreeLines =
|
||||
ToastTemplateType::ToastTemplateType_ToastImageAndText03,
|
||||
ImageWithFourLines =
|
||||
ToastTemplateType::ToastTemplateType_ToastImageAndText04,
|
||||
TextOneLine = ToastTemplateType::ToastTemplateType_ToastText01,
|
||||
TextTwoLines = ToastTemplateType::ToastTemplateType_ToastText02,
|
||||
TextThreeLines = ToastTemplateType::ToastTemplateType_ToastText03,
|
||||
TextFourLines = ToastTemplateType::ToastTemplateType_ToastText04,
|
||||
WinToastTemplateTypeCount
|
||||
};
|
||||
|
||||
enum WinToastTemplateType {
|
||||
ImageWithOneLine = ToastTemplateType::ToastTemplateType_ToastImageAndText01,
|
||||
ImageWithTwoLines = ToastTemplateType::ToastTemplateType_ToastImageAndText02,
|
||||
ImageWithThreeLines = ToastTemplateType::ToastTemplateType_ToastImageAndText03,
|
||||
ImageWithFourLines = ToastTemplateType::ToastTemplateType_ToastImageAndText04,
|
||||
TextOneLine = ToastTemplateType::ToastTemplateType_ToastText01,
|
||||
TextTwoLines = ToastTemplateType::ToastTemplateType_ToastText02,
|
||||
TextThreeLines = ToastTemplateType::ToastTemplateType_ToastText03,
|
||||
TextFourLines = ToastTemplateType::ToastTemplateType_ToastText04,
|
||||
WinToastTemplateTypeCount
|
||||
};
|
||||
explicit WinToastTemplate(
|
||||
_In_ const WinToastTemplateType& type = ImageWithTwoLines);
|
||||
~WinToastTemplate();
|
||||
|
||||
WinToastTemplate(_In_ const WinToastTemplateType& type = ImageWithTwoLines);
|
||||
~WinToastTemplate();
|
||||
int textFieldsCount() const { return _textFields.size(); }
|
||||
bool hasImage() const { return _hasImage; }
|
||||
std::vector<std::wstring> textFields() const { return _textFields; }
|
||||
std::wstring textField(_In_ const TextField& pos) const {
|
||||
return _textFields[pos];
|
||||
}
|
||||
std::wstring imagePath() const { return _imagePath; }
|
||||
WinToastTemplateType type() const { return _type; }
|
||||
void setTextField(_In_ const std::wstring& txt, _In_ const TextField& pos);
|
||||
void setImagePath(_In_ const std::wstring& imgPath);
|
||||
void setSilent(bool is_silent);
|
||||
bool isSilent() const { return _silent; }
|
||||
|
||||
int textFieldsCount() const { return _textFields.size(); }
|
||||
bool hasImage() const { return _hasImage; }
|
||||
std::vector<std::wstring> textFields() const { return _textFields; }
|
||||
std::wstring textField(_In_ const TextField& pos) const { return _textFields[pos]; }
|
||||
std::wstring imagePath() const { return _imagePath; }
|
||||
WinToastTemplateType type() const { return _type; }
|
||||
void setTextField(_In_ const std::wstring& txt, _In_ const TextField& pos);
|
||||
void setImagePath(_In_ const std::wstring& imgPath);
|
||||
void setSilent(bool is_silent);
|
||||
bool isSilent() const { return _silent; }
|
||||
private:
|
||||
static int TextFieldsCount[WinToastTemplateTypeCount];
|
||||
bool _hasImage;
|
||||
bool _silent = false;
|
||||
std::vector<std::wstring> _textFields;
|
||||
std::wstring _imagePath;
|
||||
WinToastTemplateType _type;
|
||||
void initComponentsFromType();
|
||||
};
|
||||
private:
|
||||
static int TextFieldsCount[WinToastTemplateTypeCount];
|
||||
bool _hasImage;
|
||||
bool _silent = false;
|
||||
std::vector<std::wstring> _textFields;
|
||||
std::wstring _imagePath;
|
||||
WinToastTemplateType _type;
|
||||
void initComponentsFromType();
|
||||
};
|
||||
|
||||
class WinToast {
|
||||
public:
|
||||
static WinToast* instance();
|
||||
static bool isCompatible();
|
||||
static std::wstring configureAUMI(_In_ const std::wstring& company,
|
||||
_In_ const std::wstring& name,
|
||||
_In_ const std::wstring& surname,
|
||||
_In_ const std::wstring& versionInfo
|
||||
);
|
||||
bool initialize();
|
||||
bool isInitialized() const { return _isInitialized; }
|
||||
bool showToast(_In_ const WinToastTemplate& toast, _In_ WinToastHandler* handler);
|
||||
std::wstring appName() const;
|
||||
std::wstring appUserModelId() const;
|
||||
void setAppUserModelId(_In_ const std::wstring& appName);
|
||||
void setAppName(_In_ const std::wstring& appName);
|
||||
private:
|
||||
bool _isInitialized;
|
||||
std::wstring _appName;
|
||||
std::wstring _aumi;
|
||||
ComPtr<IXmlDocument> _xmlDocument;
|
||||
ComPtr<IToastNotificationManagerStatics> _notificationManager;
|
||||
ComPtr<IToastNotifier> _notifier;
|
||||
ComPtr<IToastNotificationFactory> _notificationFactory;
|
||||
ComPtr<IToastNotification> _notification;
|
||||
static WinToast* _instance;
|
||||
class WinToast {
|
||||
public:
|
||||
static WinToast* instance();
|
||||
static bool isCompatible();
|
||||
static std::wstring configureAUMI(_In_ const std::wstring& company,
|
||||
_In_ const std::wstring& name,
|
||||
_In_ const std::wstring& surname,
|
||||
_In_ const std::wstring& versionInfo);
|
||||
bool initialize();
|
||||
bool isInitialized() const { return _isInitialized; }
|
||||
bool showToast(_In_ const WinToastTemplate& toast,
|
||||
_In_ WinToastHandler* handler);
|
||||
std::wstring appName() const;
|
||||
std::wstring appUserModelId() const;
|
||||
void setAppUserModelId(_In_ const std::wstring& appName);
|
||||
void setAppName(_In_ const std::wstring& appName);
|
||||
|
||||
WinToast(void);
|
||||
IXmlDocument* xmlDocument() const { return _xmlDocument.Get(); }
|
||||
IToastNotifier* notifier() const { return _notifier.Get(); }
|
||||
IToastNotificationFactory* notificationFactory() const { return _notificationFactory.Get(); }
|
||||
IToastNotificationManagerStatics* notificationManager() const { return _notificationManager.Get(); }
|
||||
IToastNotification* notification() const { return _notification.Get(); }
|
||||
private:
|
||||
bool _isInitialized;
|
||||
std::wstring _appName;
|
||||
std::wstring _aumi;
|
||||
ComPtr<IXmlDocument> _xmlDocument;
|
||||
ComPtr<IToastNotificationManagerStatics> _notificationManager;
|
||||
ComPtr<IToastNotifier> _notifier;
|
||||
ComPtr<IToastNotificationFactory> _notificationFactory;
|
||||
ComPtr<IToastNotification> _notification;
|
||||
static WinToast* _instance;
|
||||
|
||||
HRESULT validateShellLink();
|
||||
HRESULT createShellLink();
|
||||
HRESULT setImageField(_In_ const std::wstring& path);
|
||||
HRESULT setTextField(_In_ const std::wstring& text, _In_ int pos);
|
||||
bool makeSilent(bool is_silent);
|
||||
};
|
||||
WinToast(void);
|
||||
IXmlDocument* xmlDocument() const { return _xmlDocument.Get(); }
|
||||
IToastNotifier* notifier() const { return _notifier.Get(); }
|
||||
IToastNotificationFactory* notificationFactory() const {
|
||||
return _notificationFactory.Get();
|
||||
}
|
||||
IToastNotificationManagerStatics* notificationManager() const {
|
||||
return _notificationManager.Get();
|
||||
}
|
||||
IToastNotification* notification() const { return _notification.Get(); }
|
||||
|
||||
HRESULT validateShellLink();
|
||||
HRESULT createShellLink();
|
||||
HRESULT setImageField(_In_ const std::wstring& path);
|
||||
HRESULT setTextField(_In_ const std::wstring& text, _In_ int pos);
|
||||
bool makeSilent(bool is_silent);
|
||||
};
|
||||
} // namespace WinToastLib
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif // WINTOASTLIB_H
|
||||
#endif // ATOM_BROWSER_UI_WIN_TOAST_LIB_H_
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue