Update implementation as per feedback
This commit is contained in:
parent
6cdfb43e4e
commit
5048425e6e
22 changed files with 85 additions and 193 deletions
|
@ -9,7 +9,6 @@
|
|||
|
||||
#include "atom/browser/api/atom_api_menu.h"
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/browser/ui/notification_delegate_adapter.h"
|
||||
#include "atom/common/api/atom_api_native_image.h"
|
||||
#include "atom/common/native_mate_converters/gfx_converter.h"
|
||||
#include "atom/common/native_mate_converters/image_converter.h"
|
||||
|
@ -17,6 +16,7 @@
|
|||
#include "atom/common/node_includes.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
#include "brightray/browser/browser_client.h"
|
||||
#include "native_mate/constructor.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
|
@ -28,9 +28,6 @@ namespace atom {
|
|||
|
||||
namespace api {
|
||||
|
||||
int id_counter = 1;
|
||||
std::map<int, Notification*> notifications_;
|
||||
|
||||
Notification::Notification(v8::Isolate* isolate,
|
||||
v8::Local<v8::Object> wrapper,
|
||||
mate::Arguments* args) {
|
||||
|
@ -47,13 +44,13 @@ Notification::Notification(v8::Isolate* isolate,
|
|||
opts.Get("silent", &silent_);
|
||||
opts.Get("replyPlaceholder", &reply_placeholder_);
|
||||
opts.Get("hasReply", &has_reply_);
|
||||
id_ = id_counter++;
|
||||
}
|
||||
notifications_[id_] = this;
|
||||
OnInitialProps();
|
||||
}
|
||||
|
||||
Notification::~Notification() {}
|
||||
Notification::~Notification() {
|
||||
notification_->set_delegate(nullptr);
|
||||
}
|
||||
|
||||
// static
|
||||
mate::WrappableBase* Notification::New(mate::Arguments* args) {
|
||||
|
@ -64,18 +61,7 @@ mate::WrappableBase* Notification::New(mate::Arguments* args) {
|
|||
return new Notification(args->isolate(), args->GetThis(), args);
|
||||
}
|
||||
|
||||
bool Notification::HasID(int id) {
|
||||
return notifications_.find(id) != notifications_.end();
|
||||
}
|
||||
|
||||
Notification* Notification::FromID(int id) {
|
||||
return notifications_[id];
|
||||
}
|
||||
|
||||
// Getters
|
||||
int Notification::GetID() {
|
||||
return id_;
|
||||
}
|
||||
base::string16 Notification::GetTitle() {
|
||||
return title_;
|
||||
}
|
||||
|
@ -93,66 +79,54 @@ bool Notification::GetHasReply() {
|
|||
}
|
||||
|
||||
// Setters
|
||||
void Notification::SetTitle(base::string16 new_title) {
|
||||
void Notification::SetTitle(const base::string16& new_title) {
|
||||
title_ = new_title;
|
||||
NotifyPropsUpdated();
|
||||
}
|
||||
void Notification::SetBody(base::string16 new_body) {
|
||||
void Notification::SetBody(const 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) {
|
||||
void Notification::SetReplyPlaceholder(const 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::NotificationClick() {
|
||||
Emit("click");
|
||||
}
|
||||
|
||||
void Notification::OnReplied(std::string reply) {
|
||||
void Notification::NotificationReplied(const std::string reply) {
|
||||
Emit("reply", reply);
|
||||
}
|
||||
|
||||
void Notification::OnShown() {
|
||||
void Notification::NotificationDisplayed() {
|
||||
Emit("show");
|
||||
}
|
||||
|
||||
void Notification::OnClosed() {
|
||||
void Notification::NotificationDestroyed() {
|
||||
Emit("close");
|
||||
}
|
||||
|
||||
void Notification::NotifyPropsUpdated() {}
|
||||
void Notification::NotificationClosed() {}
|
||||
|
||||
// Showing notifications
|
||||
void Notification::Show() {
|
||||
SkBitmap image = *(new SkBitmap);
|
||||
if (has_icon_) {
|
||||
image = *(icon_.ToSkBitmap());
|
||||
}
|
||||
|
||||
std::unique_ptr<AtomNotificationDelegateAdapter> adapter(
|
||||
new AtomNotificationDelegateAdapter(this));
|
||||
auto notif = presenter_->CreateNotification(adapter.get());
|
||||
if (notif) {
|
||||
ignore_result(adapter.release()); // it will release itself automatically.
|
||||
GURL nullUrl = *(new GURL);
|
||||
notif->Show(title_, body_, "", nullUrl, image, silent_, has_reply_, reply_placeholder_);
|
||||
if (presenter_) {
|
||||
notification_ = presenter_->CreateNotification(this);
|
||||
if (notification_) {
|
||||
notification_->Show(title_, body_, "", GURL(), icon_.AsBitmap(), silent_, has_reply_, reply_placeholder_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool initialized_ = false;
|
||||
void Notification::OnInitialProps() {
|
||||
if (!initialized_) {
|
||||
presenter_ = brightray::NotificationPresenter::Create();
|
||||
presenter_ = brightray::BrowserClient::Get()->GetNotificationPresenter();
|
||||
initialized_ = true;
|
||||
}
|
||||
}
|
||||
|
@ -164,7 +138,6 @@ void Notification::BuildPrototype(v8::Isolate* isolate,
|
|||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||
.MakeDestroyable()
|
||||
.SetMethod("show", &Notification::Show)
|
||||
.SetProperty("id", &Notification::GetID)
|
||||
.SetProperty("title", &Notification::GetTitle, &Notification::SetTitle)
|
||||
.SetProperty("body", &Notification::GetBody, &Notification::SetBody)
|
||||
.SetProperty("silent", &Notification::GetSilent, &Notification::SetSilent)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue