Code cleanup

This commit is contained in:
Samuel Attard 2017-04-24 13:07:42 +10:00
parent 03688b9415
commit c6196810a6
No known key found for this signature in database
GPG key ID: 273DC1869D8F13EF
11 changed files with 758 additions and 614 deletions

View file

@ -4,6 +4,7 @@
#include "atom/browser/api/atom_api_notification.h" #include "atom/browser/api/atom_api_notification.h"
#include <map>
#include <string> #include <string>
#include "atom/browser/api/atom_api_menu.h" #include "atom/browser/api/atom_api_menu.h"
@ -25,7 +26,9 @@ namespace api {
int id_counter = 1; int id_counter = 1;
std::map<int, Notification*> notifications_; std::map<int, Notification*> notifications_;
Notification::Notification(v8::Isolate* isolate, v8::Local<v8::Object> wrapper, mate::Arguments* args) { Notification::Notification(v8::Isolate* isolate,
v8::Local<v8::Object> wrapper,
mate::Arguments* args) {
InitWith(isolate, wrapper); InitWith(isolate, wrapper);
mate::Dictionary opts; mate::Dictionary opts;
@ -65,19 +68,46 @@ Notification* Notification::FromID(int id) {
} }
// Getters // Getters
int Notification::GetID() { return id_; } int Notification::GetID() {
base::string16 Notification::GetTitle() { return title_; } return id_;
base::string16 Notification::GetBody() { return body_; } }
bool Notification::GetSilent() { return silent_; } base::string16 Notification::GetTitle() {
base::string16 Notification::GetReplyPlaceholder() { return reply_placeholder_; } return title_;
bool Notification::GetHasReply() { return has_reply_; } }
base::string16 Notification::GetBody() {
return body_;
}
bool Notification::GetSilent() {
return silent_;
}
base::string16 Notification::GetReplyPlaceholder() {
return reply_placeholder_;
}
bool Notification::GetHasReply() {
return has_reply_;
}
// Setters // Setters
void Notification::SetTitle(base::string16 new_title) { title_ = new_title; NotifyPropsUpdated(); } void Notification::SetTitle(base::string16 new_title) {
void Notification::SetBody(base::string16 new_body) { body_ = new_body; NotifyPropsUpdated(); } title_ = new_title;
void Notification::SetSilent(bool new_silent) { silent_ = new_silent; NotifyPropsUpdated(); } NotifyPropsUpdated();
void Notification::SetReplyPlaceholder(base::string16 new_reply_placeholder) { reply_placeholder_ = new_reply_placeholder; NotifyPropsUpdated(); } }
void Notification::SetHasReply(bool new_has_reply) { has_reply_ = new_has_reply; NotifyPropsUpdated(); } void Notification::SetBody(base::string16 new_body) {
body_ = new_body;
NotifyPropsUpdated();
}
void Notification::SetSilent(bool new_silent) {
silent_ = new_silent;
NotifyPropsUpdated();
}
void Notification::SetReplyPlaceholder(base::string16 new_reply_placeholder) {
reply_placeholder_ = new_reply_placeholder;
NotifyPropsUpdated();
}
void Notification::SetHasReply(bool new_has_reply) {
has_reply_ = new_has_reply;
NotifyPropsUpdated();
}
void Notification::OnClicked() { void Notification::OnClicked() {
Emit("click"); Emit("click");
@ -93,7 +123,7 @@ void Notification::OnShown() {
// static // static
void Notification::BuildPrototype(v8::Isolate* isolate, void Notification::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) { v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "Notification")); prototype->SetClassName(mate::StringToV8(isolate, "Notification"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.MakeDestroyable() .MakeDestroyable()
@ -102,26 +132,30 @@ void Notification::BuildPrototype(v8::Isolate* isolate,
.SetProperty("title", &Notification::GetTitle, &Notification::SetTitle) .SetProperty("title", &Notification::GetTitle, &Notification::SetTitle)
.SetProperty("body", &Notification::GetBody, &Notification::SetBody) .SetProperty("body", &Notification::GetBody, &Notification::SetBody)
.SetProperty("silent", &Notification::GetSilent, &Notification::SetSilent) .SetProperty("silent", &Notification::GetSilent, &Notification::SetSilent)
.SetProperty("replyPlaceholder", &Notification::GetReplyPlaceholder, &Notification::SetReplyPlaceholder) .SetProperty("replyPlaceholder", &Notification::GetReplyPlaceholder,
.SetProperty("hasReply", &Notification::GetHasReply, &Notification::SetHasReply); &Notification::SetReplyPlaceholder)
.SetProperty("hasReply", &Notification::GetHasReply,
&Notification::SetHasReply);
} }
} // namespace api } // namespace api
} // namespace atom } // namespace atom
namespace { namespace {
using atom::api::Notification; using atom::api::Notification;
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused, void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Context> context, void* priv) { v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate(); v8::Isolate* isolate = context->GetIsolate();
Notification::SetConstructor(isolate, base::Bind(&Notification::New)); Notification::SetConstructor(isolate, base::Bind(&Notification::New));
mate::Dictionary dict(isolate, exports); mate::Dictionary dict(isolate, exports);
dict.Set("Notification", Notification::GetConstructor(isolate)->GetFunction()); dict.Set("Notification",
Notification::GetConstructor(isolate)->GetFunction());
} }
} // namespace } // namespace

View file

@ -20,7 +20,7 @@ namespace atom {
namespace api { namespace api {
class Notification : public mate::TrackableObject<Notification>, class Notification : public mate::TrackableObject<Notification>,
public NotifictionObserver { public NotifictionObserver {
public: public:
static mate::WrappableBase* New(mate::Arguments* args); static mate::WrappableBase* New(mate::Arguments* args);
static bool HasID(int id); static bool HasID(int id);
@ -35,7 +35,9 @@ class Notification : public mate::TrackableObject<Notification>,
void OnShown() override; void OnShown() override;
protected: protected:
Notification(v8::Isolate* isolate, v8::Local<v8::Object> wrapper, mate::Arguments* args); Notification(v8::Isolate* isolate,
v8::Local<v8::Object> wrapper,
mate::Arguments* args);
~Notification() override; ~Notification() override;
void OnInitialProps(); void OnInitialProps();

View file

@ -48,7 +48,8 @@ void Notification::Show() {
if (can_toast_) { if (can_toast_) {
atom::AtomToastHandler* handler = new atom::AtomToastHandler(this); atom::AtomToastHandler* handler = new atom::AtomToastHandler(this);
WinToastLib::WinToastTemplate::WinToastTemplateType toastType = WinToastLib::WinToastTemplate::TextOneLine; WinToastLib::WinToastTemplate::WinToastTemplateType toastType =
WinToastLib::WinToastTemplate::TextOneLine;
if (!has_icon_) { if (!has_icon_) {
if (body_ != L"") { if (body_ != L"") {
toastType = WinToastLib::WinToastTemplate::TextTwoLines; toastType = WinToastLib::WinToastTemplate::TextTwoLines;
@ -62,40 +63,41 @@ void Notification::Show() {
toastType = WinToastLib::WinToastTemplate::ImageWithOneLine; toastType = WinToastLib::WinToastTemplate::ImageWithOneLine;
} }
} }
WinToastLib::WinToastTemplate toast = WinToastLib::WinToastTemplate(toastType); WinToastLib::WinToastTemplate toast =
WinToastLib::WinToastTemplate(toastType);
std::string filename = base::MD5String(base::UTF16ToUTF8(icon_path_)) + ".png"; std::string filename =
base::FilePath savePath = temp_dir_.GetPath().Append(base::UTF8ToUTF16(filename)); base::MD5String(base::UTF16ToUTF8(icon_path_)) + ".png";
base::FilePath savePath =
temp_dir_.GetPath().Append(base::UTF8ToUTF16(filename));
if (has_icon_ && SaveIconToPath(image, savePath)) { if (has_icon_ && SaveIconToPath(image, savePath)) {
toast.setImagePath(savePath.value()); toast.setImagePath(savePath.value());
} }
toast.setTextField(title_, WinToastLib::WinToastTemplate::TextField::FirstLine); toast.setTextField(title_,
toast.setTextField(body_, WinToastLib::WinToastTemplate::TextField::SecondLine); WinToastLib::WinToastTemplate::TextField::FirstLine);
toast.setTextField(body_,
WinToastLib::WinToastTemplate::TextField::SecondLine);
toast.setSilent(silent_); toast.setSilent(silent_);
WinToastLib::WinToast::instance()->showToast(toast, handler); WinToastLib::WinToast::instance()->showToast(toast, handler);
OnShown(); OnShown();
} else { } else {
AtomNotificationDelegateAdapter* adapter = new AtomNotificationDelegateAdapter(this); AtomNotificationDelegateAdapter* adapter =
new AtomNotificationDelegateAdapter(this);
auto notif = presenter->CreateNotification(adapter); auto notif = presenter->CreateNotification(adapter);
GURL nullUrl = *(new GURL); GURL nullUrl = *(new GURL);
notif->Show( notif->Show(title_, body_, "", nullUrl, image, silent_);
title_,
body_,
"",
nullUrl,
image,
silent_
);
} }
} }
void Notification::OnInitialProps() { void Notification::OnInitialProps() {
if (!initialized_) { if (!initialized_) {
Browser* browser = Browser::Get(); Browser* browser = Browser::Get();
WinToastLib::WinToast::instance()->setAppName(base::UTF8ToUTF16(browser->GetName())); WinToastLib::WinToast::instance()->setAppName(
WinToastLib::WinToast::instance()->setAppUserModelId(browser->GetAppUserModelID()); base::UTF8ToUTF16(browser->GetName()));
WinToastLib::WinToast::instance()->setAppUserModelId(
browser->GetAppUserModelID());
can_toast_ = WinToastLib::WinToast::instance()->initialize(); can_toast_ = WinToastLib::WinToast::instance()->initialize();
temp_dir_.CreateUniqueTempDir(); temp_dir_.CreateUniqueTempDir();
} }
@ -104,10 +106,6 @@ void Notification::OnInitialProps() {
} }
} }
void Notification::NotifyPropsUpdated() { void Notification::NotifyPropsUpdated() {}
} // namespace api
} } // namespace atom
}
}

View file

@ -1,3 +1,7 @@
// Copyright (c) 2014 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/browser/ui/notification_delegate_adapter.h" #include "atom/browser/ui/notification_delegate_adapter.h"
#include "atom/browser/api/atom_api_notification.h" #include "atom/browser/api/atom_api_notification.h"
@ -5,17 +9,18 @@
namespace atom { namespace atom {
AtomNotificationDelegateAdapter::AtomNotificationDelegateAdapter(atom::api::Notification* target) { AtomNotificationDelegateAdapter::AtomNotificationDelegateAdapter(
observer_ = target; atom::api::Notification* target) {
observer_ = target;
} }
void AtomNotificationDelegateAdapter::NotificationDisplayed() { void AtomNotificationDelegateAdapter::NotificationDisplayed() {
observer_->OnShown(); observer_->OnShown();
} }
void AtomNotificationDelegateAdapter::NotificationClosed() {} void AtomNotificationDelegateAdapter::NotificationClosed() {}
void AtomNotificationDelegateAdapter::NotificationClick() { void AtomNotificationDelegateAdapter::NotificationClick() {
observer_->OnClicked(); observer_->OnClicked();
} }
void AtomNotificationDelegateAdapter::NotificationDestroyed() {} void AtomNotificationDelegateAdapter::NotificationDestroyed() {}
void AtomNotificationDelegateAdapter::NotificationFailed() {} void AtomNotificationDelegateAdapter::NotificationFailed() {}
} } // namespace atom

View file

@ -12,17 +12,17 @@
namespace atom { namespace atom {
class AtomNotificationDelegateAdapter : public brightray::NotificationDelegate { class AtomNotificationDelegateAdapter : public brightray::NotificationDelegate {
public: public:
atom::api::Notification* observer_; atom::api::Notification* observer_;
AtomNotificationDelegateAdapter(atom::api::Notification* target); explicit AtomNotificationDelegateAdapter(atom::api::Notification* target);
void NotificationDisplayed(); void NotificationDisplayed();
void NotificationClosed(); void NotificationClosed();
void NotificationClick(); void NotificationClick();
void NotificationDestroyed(); void NotificationDestroyed();
void NotificationFailed(); void NotificationFailed();
}; };
} } // namespace atom
#endif // ATOM_BROWSER_UI_NOTIFICATION_DELEGATE_ADAPTER_H_ #endif // ATOM_BROWSER_UI_NOTIFICATION_DELEGATE_ADAPTER_H_

View file

@ -5,6 +5,8 @@
#ifndef ATOM_BROWSER_UI_NOTIFICATION_OBSERVER_H_ #ifndef ATOM_BROWSER_UI_NOTIFICATION_OBSERVER_H_
#define ATOM_BROWSER_UI_NOTIFICATION_OBSERVER_H_ #define ATOM_BROWSER_UI_NOTIFICATION_OBSERVER_H_
#include <string>
namespace atom { namespace atom {
class NotifictionObserver { class NotifictionObserver {

View file

@ -15,14 +15,15 @@ AtomToastHandler::AtomToastHandler(atom::api::Notification* target) {
void AtomToastHandler::toastActivated() { void AtomToastHandler::toastActivated() {
observer_->OnClicked(); observer_->OnClicked();
}; }
void AtomToastHandler::toastDismissed(WinToastLib::WinToastHandler::WinToastDismissalReason state) { void AtomToastHandler::toastDismissed(
WinToastLib::WinToastHandler::WinToastDismissalReason state) {
// observer_->OnDismissed(); // observer_->OnDismissed();
}; }
void AtomToastHandler::toastFailed() { void AtomToastHandler::toastFailed() {
// observer_->OnErrored(); // observer_->OnErrored();
};
} }
} // namespace atom

View file

@ -5,21 +5,22 @@
#include "atom/browser/ui/win/toast_lib.h" #include "atom/browser/ui/win/toast_lib.h"
#include "atom/browser/api/atom_api_notification.h" #include "atom/browser/api/atom_api_notification.h"
#ifndef ATOM_BROWSER_UI_TOAST_HANDLER_H_ #ifndef ATOM_BROWSER_UI_WIN_TOAST_HANDLER_H_
#define ATOM_BROWSER_UI_TOAST_HANDLER_H_ #define ATOM_BROWSER_UI_WIN_TOAST_HANDLER_H_
namespace atom { namespace atom {
class AtomToastHandler : public WinToastLib::WinToastHandler { class AtomToastHandler : public WinToastLib::WinToastHandler {
public: public:
atom::api::Notification* observer_; atom::api::Notification* observer_;
AtomToastHandler(atom::api::Notification* target); explicit AtomToastHandler(atom::api::Notification* target);
void toastActivated() override; void toastActivated() override;
void toastDismissed(WinToastLib::WinToastHandler::WinToastDismissalReason state); void toastDismissed(
WinToastLib::WinToastHandler::WinToastDismissalReason state);
void toastFailed(); 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

View file

@ -9,8 +9,8 @@
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in
// copies or substantial portions of the Software. // all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // 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 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
#ifndef WINTOASTLIB_H #ifndef ATOM_BROWSER_UI_WIN_TOAST_LIB_H_
#define WINTOASTLIB_H #define ATOM_BROWSER_UI_WIN_TOAST_LIB_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;
#define DEFAULT_SHELL_LINKS_PATH L"\\Microsoft\\Windows\\Start Menu\\Programs\\" #include <string.h>
#define DEFAULT_LINK_FORMAT L".lnk" #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 { namespace WinToastLib {
class WinToastStringWrapper { class WinToastStringWrapper {
public: public:
WinToastStringWrapper(_In_reads_(length) PCWSTR stringRef, _In_ UINT32 length) throw(); WinToastStringWrapper(_In_reads_(length) PCWSTR stringRef,
WinToastStringWrapper(_In_ const std::wstring &stringRef) throw(); _In_ UINT32 length) throw();
~WinToastStringWrapper(); explicit WinToastStringWrapper(_In_ const std::wstring& stringRef) throw();
HSTRING Get() const throw(); ~WinToastStringWrapper();
private: HSTRING Get() const throw();
HSTRING _hstring;
HSTRING_HEADER _header;
}; 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 { virtual void toastActivated() {}
public: virtual void toastDismissed(WinToastDismissalReason state) {}
enum WinToastDismissalReason { virtual void toastFailed() {}
UserCanceled = ToastDismissalReason::ToastDismissalReason_UserCanceled, };
ApplicationHidden = ToastDismissalReason::ToastDismissalReason_ApplicationHidden,
TimedOut = ToastDismissalReason::ToastDismissalReason_TimedOut
};
virtual void toastActivated() {}; class WinToastTemplate {
virtual void toastDismissed(WinToastDismissalReason state) {}; public:
virtual void toastFailed() {}; enum TextField { FirstLine = 0, SecondLine, ThirdLine, LineCount };
};
class WinToastTemplate enum WinToastTemplateType {
{ ImageWithOneLine = ToastTemplateType::ToastTemplateType_ToastImageAndText01,
public: ImageWithTwoLines =
enum TextField { ToastTemplateType::ToastTemplateType_ToastImageAndText02,
FirstLine = 0, ImageWithThreeLines =
SecondLine, ToastTemplateType::ToastTemplateType_ToastImageAndText03,
ThirdLine, ImageWithFourLines =
LineCount ToastTemplateType::ToastTemplateType_ToastImageAndText04,
}; TextOneLine = ToastTemplateType::ToastTemplateType_ToastText01,
TextTwoLines = ToastTemplateType::ToastTemplateType_ToastText02,
TextThreeLines = ToastTemplateType::ToastTemplateType_ToastText03,
TextFourLines = ToastTemplateType::ToastTemplateType_ToastText04,
WinToastTemplateTypeCount
};
enum WinToastTemplateType { explicit WinToastTemplate(
ImageWithOneLine = ToastTemplateType::ToastTemplateType_ToastImageAndText01, _In_ const WinToastTemplateType& type = ImageWithTwoLines);
ImageWithTwoLines = ToastTemplateType::ToastTemplateType_ToastImageAndText02, ~WinToastTemplate();
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
};
WinToastTemplate(_In_ const WinToastTemplateType& type = ImageWithTwoLines); int textFieldsCount() const { return _textFields.size(); }
~WinToastTemplate(); 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(); } private:
bool hasImage() const { return _hasImage; } static int TextFieldsCount[WinToastTemplateTypeCount];
std::vector<std::wstring> textFields() const { return _textFields; } bool _hasImage;
std::wstring textField(_In_ const TextField& pos) const { return _textFields[pos]; } bool _silent = false;
std::wstring imagePath() const { return _imagePath; } std::vector<std::wstring> _textFields;
WinToastTemplateType type() const { return _type; } std::wstring _imagePath;
void setTextField(_In_ const std::wstring& txt, _In_ const TextField& pos); WinToastTemplateType _type;
void setImagePath(_In_ const std::wstring& imgPath); void initComponentsFromType();
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();
};
class WinToast { class WinToast {
public: public:
static WinToast* instance(); static WinToast* instance();
static bool isCompatible(); static bool isCompatible();
static std::wstring configureAUMI(_In_ const std::wstring& company, static std::wstring configureAUMI(_In_ const std::wstring& company,
_In_ const std::wstring& name, _In_ const std::wstring& name,
_In_ const std::wstring& surname, _In_ const std::wstring& surname,
_In_ const std::wstring& versionInfo _In_ const std::wstring& versionInfo);
); bool initialize();
bool initialize(); bool isInitialized() const { return _isInitialized; }
bool isInitialized() const { return _isInitialized; } bool showToast(_In_ const WinToastTemplate& toast,
bool showToast(_In_ const WinToastTemplate& toast, _In_ WinToastHandler* handler); _In_ WinToastHandler* handler);
std::wstring appName() const; std::wstring appName() const;
std::wstring appUserModelId() const; std::wstring appUserModelId() const;
void setAppUserModelId(_In_ const std::wstring& appName); void setAppUserModelId(_In_ const std::wstring& appName);
void setAppName(_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;
WinToast(void); private:
IXmlDocument* xmlDocument() const { return _xmlDocument.Get(); } bool _isInitialized;
IToastNotifier* notifier() const { return _notifier.Get(); } std::wstring _appName;
IToastNotificationFactory* notificationFactory() const { return _notificationFactory.Get(); } std::wstring _aumi;
IToastNotificationManagerStatics* notificationManager() const { return _notificationManager.Get(); } ComPtr<IXmlDocument> _xmlDocument;
IToastNotification* notification() const { return _notification.Get(); } ComPtr<IToastNotificationManagerStatics> _notificationManager;
ComPtr<IToastNotifier> _notifier;
ComPtr<IToastNotificationFactory> _notificationFactory;
ComPtr<IToastNotification> _notification;
static WinToast* _instance;
HRESULT validateShellLink(); WinToast(void);
HRESULT createShellLink(); IXmlDocument* xmlDocument() const { return _xmlDocument.Get(); }
HRESULT setImageField(_In_ const std::wstring& path); IToastNotifier* notifier() const { return _notifier.Get(); }
HRESULT setTextField(_In_ const std::wstring& text, _In_ int pos); IToastNotificationFactory* notificationFactory() const {
bool makeSilent(bool is_silent); 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 // ATOM_BROWSER_UI_WIN_TOAST_LIB_H_
}
#endif // WINTOASTLIB_H

View file

@ -32,14 +32,14 @@ exports.load = (appUrl) => {
title: 'Hello World', title: 'Hello World',
body: 'This is the long and complicated body for this notification that just goes on and on and on and never really seems to stop', body: 'This is the long and complicated body for this notification that just goes on and on and on and never really seems to stop',
silent: true, silent: true,
icon: '/Users/samuel/Downloads/ninja.png', icon: path.resolve('C:\\Users\\Samuel\\Downloads\\icon.png'),
hasReply: true, hasReply: true,
replyPlaceholder: 'Type Here!!' replyPlaceholder: 'Type Here!!'
}); })
n.on('show', () => console.log('showed')); n.on('show', () => console.log('showed'))
n.on('click', () => console.info('clicked!!')); n.on('click', () => console.info('clicked!!'))
n.on('reply', (e, reply) => console.log('Replied:', reply)); n.on('reply', (e, reply) => console.log('Replied:', reply))
n.show(); n.show()
}) })
} }