Initial semi-working windows implementation
This commit is contained in:
parent
5dd4d6a961
commit
7c38633d1e
9 changed files with 833 additions and 18 deletions
|
@ -33,6 +33,9 @@ Notification::Notification(v8::Isolate* isolate, v8::Local<v8::Object> wrapper,
|
|||
opts.Get("title", &title_);
|
||||
opts.Get("body", &body_);
|
||||
has_icon_ = opts.Get("icon", &icon_);
|
||||
if (has_icon_) {
|
||||
opts.Get("icon", &icon_path_);
|
||||
}
|
||||
opts.Get("silent", &silent_);
|
||||
opts.Get("replyPlaceholder", &reply_placeholder_);
|
||||
opts.Get("hasReply", &has_reply_);
|
||||
|
@ -63,17 +66,17 @@ Notification* Notification::FromID(int id) {
|
|||
|
||||
// Getters
|
||||
int Notification::GetID() { return id_; }
|
||||
std::string Notification::GetTitle() { return title_; }
|
||||
std::string Notification::GetBody() { return body_; }
|
||||
base::string16 Notification::GetTitle() { return title_; }
|
||||
base::string16 Notification::GetBody() { return body_; }
|
||||
bool Notification::GetSilent() { return silent_; }
|
||||
std::string Notification::GetReplyPlaceholder() { return reply_placeholder_; }
|
||||
base::string16 Notification::GetReplyPlaceholder() { return reply_placeholder_; }
|
||||
bool Notification::GetHasReply() { return has_reply_; }
|
||||
|
||||
// Setters
|
||||
void Notification::SetTitle(std::string new_title) { title_ = new_title; NotifyPropsUpdated(); }
|
||||
void Notification::SetBody(std::string new_body) { body_ = new_body; NotifyPropsUpdated(); }
|
||||
void Notification::SetTitle(base::string16 new_title) { title_ = new_title; 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(std::string new_reply_placeholder) { reply_placeholder_ = new_reply_placeholder; 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() {
|
||||
|
|
|
@ -42,28 +42,29 @@ class Notification : public mate::TrackableObject<Notification>,
|
|||
|
||||
// Prop Getters
|
||||
int GetID();
|
||||
std::string GetTitle();
|
||||
std::string GetBody();
|
||||
base::string16 GetTitle();
|
||||
base::string16 GetBody();
|
||||
bool GetSilent();
|
||||
std::string GetReplyPlaceholder();
|
||||
base::string16 GetReplyPlaceholder();
|
||||
bool GetHasReply();
|
||||
|
||||
// Prop Setters
|
||||
void SetTitle(std::string new_title);
|
||||
void SetBody(std::string new_body);
|
||||
void SetTitle(base::string16 new_title);
|
||||
void SetBody(base::string16 new_body);
|
||||
void SetSilent(bool new_silent);
|
||||
void SetReplyPlaceholder(std::string new_reply_placeholder);
|
||||
void SetReplyPlaceholder(base::string16 new_reply_placeholder);
|
||||
void SetHasReply(bool new_has_reply);
|
||||
|
||||
void NotifyPropsUpdated();
|
||||
|
||||
private:
|
||||
std::string title_ = "";
|
||||
std::string body_ = "";
|
||||
base::string16 title_ = L"";
|
||||
base::string16 body_ = L"";
|
||||
gfx::Image icon_;
|
||||
base::string16 icon_path_ = L"";
|
||||
bool has_icon_ = false;
|
||||
bool silent_ = false;
|
||||
std::string reply_placeholder_ = "";
|
||||
base::string16 reply_placeholder_ = L"";
|
||||
bool has_reply_ = false;
|
||||
|
||||
int id_;
|
||||
|
|
|
@ -69,8 +69,8 @@ void Notification::OnInitialProps() {
|
|||
void Notification::NotifyPropsUpdated() {
|
||||
base::scoped_nsobject<NSUserNotification> notification_ = native_notifications_[id_];
|
||||
|
||||
[notification_ setTitle:base::SysUTF8ToNSString(title_)];
|
||||
[notification_ setInformativeText:base::SysUTF8ToNSString(body_)];
|
||||
[notification_ setTitle:base::SysUTF16ToNSString(title_)];
|
||||
[notification_ setInformativeText:base::SysUTF16ToNSString(body_)];
|
||||
|
||||
NSDictionary * userInfo = [NSMutableDictionary dictionary];
|
||||
[userInfo setValue:[NSNumber numberWithInt:id_] forKey:@"id"];
|
||||
|
@ -81,7 +81,7 @@ void Notification::NotifyPropsUpdated() {
|
|||
}
|
||||
|
||||
if (has_reply_) {
|
||||
[notification_ setResponsePlaceholder:base::SysUTF8ToNSString(reply_placeholder_)];
|
||||
[notification_ setResponsePlaceholder:base::SysUTF16ToNSString(reply_placeholder_)];
|
||||
[notification_ setHasReplyButton:true];
|
||||
}
|
||||
|
||||
|
|
48
atom/browser/api/atom_api_notification_win.cc
Normal file
48
atom/browser/api/atom_api_notification_win.cc
Normal file
|
@ -0,0 +1,48 @@
|
|||
// 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/api/atom_api_notification.h"
|
||||
|
||||
#include "atom/browser/ui/win/toast_handler.h"
|
||||
#include "atom/browser/ui/win/toast_lib.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "common/string_conversion.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
||||
bool can_toast_ = true;
|
||||
bool initialized_ = false;
|
||||
|
||||
void Notification::Show() {
|
||||
atom::AtomToastHandler* handler = new atom::AtomToastHandler(this);
|
||||
WinToastLib::WinToastTemplate toast = WinToastLib::WinToastTemplate(WinToastLib::WinToastTemplate::TextTwoLines);
|
||||
// toast.setImagePath(L"C:\example.png");
|
||||
toast.setTextField(title_, WinToastLib::WinToastTemplate::TextField::FirstLine);
|
||||
toast.setTextField(body_, WinToastLib::WinToastTemplate::TextField::SecondLine);
|
||||
toast.setSilent(silent_);
|
||||
|
||||
WinToastLib::WinToast::instance()->showToast(toast, handler);
|
||||
|
||||
OnShown();
|
||||
}
|
||||
|
||||
void Notification::OnInitialProps() {
|
||||
if (!initialized_) {
|
||||
WinToastLib::WinToast::instance()->setAppName(L"WinToastExample");
|
||||
WinToastLib::WinToast::instance()->setAppUserModelId(
|
||||
WinToastLib::WinToast::configureAUMI(L"mohabouje", L"wintoast", L"wintoastexample", L"20161006")
|
||||
);
|
||||
can_toast_ = WinToastLib::WinToast::instance()->initialize();
|
||||
}
|
||||
}
|
||||
|
||||
void Notification::NotifyPropsUpdated() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue