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/api/atom_api_menu.h"
|
||||||
#include "atom/browser/browser.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/api/atom_api_native_image.h"
|
||||||
#include "atom/common/native_mate_converters/gfx_converter.h"
|
#include "atom/common/native_mate_converters/gfx_converter.h"
|
||||||
#include "atom/common/native_mate_converters/image_converter.h"
|
#include "atom/common/native_mate_converters/image_converter.h"
|
||||||
|
@ -17,6 +16,7 @@
|
||||||
#include "atom/common/node_includes.h"
|
#include "atom/common/node_includes.h"
|
||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
#include "base/threading/thread_task_runner_handle.h"
|
#include "base/threading/thread_task_runner_handle.h"
|
||||||
|
#include "brightray/browser/browser_client.h"
|
||||||
#include "native_mate/constructor.h"
|
#include "native_mate/constructor.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
#include "third_party/skia/include/core/SkBitmap.h"
|
#include "third_party/skia/include/core/SkBitmap.h"
|
||||||
|
@ -28,9 +28,6 @@ namespace atom {
|
||||||
|
|
||||||
namespace api {
|
namespace api {
|
||||||
|
|
||||||
int id_counter = 1;
|
|
||||||
std::map<int, Notification*> notifications_;
|
|
||||||
|
|
||||||
Notification::Notification(v8::Isolate* isolate,
|
Notification::Notification(v8::Isolate* isolate,
|
||||||
v8::Local<v8::Object> wrapper,
|
v8::Local<v8::Object> wrapper,
|
||||||
mate::Arguments* args) {
|
mate::Arguments* args) {
|
||||||
|
@ -47,13 +44,13 @@ Notification::Notification(v8::Isolate* isolate,
|
||||||
opts.Get("silent", &silent_);
|
opts.Get("silent", &silent_);
|
||||||
opts.Get("replyPlaceholder", &reply_placeholder_);
|
opts.Get("replyPlaceholder", &reply_placeholder_);
|
||||||
opts.Get("hasReply", &has_reply_);
|
opts.Get("hasReply", &has_reply_);
|
||||||
id_ = id_counter++;
|
|
||||||
}
|
}
|
||||||
notifications_[id_] = this;
|
|
||||||
OnInitialProps();
|
OnInitialProps();
|
||||||
}
|
}
|
||||||
|
|
||||||
Notification::~Notification() {}
|
Notification::~Notification() {
|
||||||
|
notification_->set_delegate(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
mate::WrappableBase* Notification::New(mate::Arguments* args) {
|
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);
|
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
|
// Getters
|
||||||
int Notification::GetID() {
|
|
||||||
return id_;
|
|
||||||
}
|
|
||||||
base::string16 Notification::GetTitle() {
|
base::string16 Notification::GetTitle() {
|
||||||
return title_;
|
return title_;
|
||||||
}
|
}
|
||||||
|
@ -93,66 +79,54 @@ bool Notification::GetHasReply() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setters
|
// Setters
|
||||||
void Notification::SetTitle(base::string16 new_title) {
|
void Notification::SetTitle(const base::string16& new_title) {
|
||||||
title_ = new_title;
|
title_ = new_title;
|
||||||
NotifyPropsUpdated();
|
|
||||||
}
|
}
|
||||||
void Notification::SetBody(base::string16 new_body) {
|
void Notification::SetBody(const base::string16& new_body) {
|
||||||
body_ = new_body;
|
body_ = new_body;
|
||||||
NotifyPropsUpdated();
|
|
||||||
}
|
}
|
||||||
void Notification::SetSilent(bool new_silent) {
|
void Notification::SetSilent(bool new_silent) {
|
||||||
silent_ = 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;
|
reply_placeholder_ = new_reply_placeholder;
|
||||||
NotifyPropsUpdated();
|
|
||||||
}
|
}
|
||||||
void Notification::SetHasReply(bool new_has_reply) {
|
void Notification::SetHasReply(bool new_has_reply) {
|
||||||
has_reply_ = new_has_reply;
|
has_reply_ = new_has_reply;
|
||||||
NotifyPropsUpdated();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notification::OnClicked() {
|
void Notification::NotificationClick() {
|
||||||
Emit("click");
|
Emit("click");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notification::OnReplied(std::string reply) {
|
void Notification::NotificationReplied(const std::string reply) {
|
||||||
Emit("reply", reply);
|
Emit("reply", reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notification::OnShown() {
|
void Notification::NotificationDisplayed() {
|
||||||
Emit("show");
|
Emit("show");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notification::OnClosed() {
|
void Notification::NotificationDestroyed() {
|
||||||
Emit("close");
|
Emit("close");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notification::NotifyPropsUpdated() {}
|
void Notification::NotificationClosed() {}
|
||||||
|
|
||||||
// Showing notifications
|
// Showing notifications
|
||||||
void Notification::Show() {
|
void Notification::Show() {
|
||||||
SkBitmap image = *(new SkBitmap);
|
if (presenter_) {
|
||||||
if (has_icon_) {
|
notification_ = presenter_->CreateNotification(this);
|
||||||
image = *(icon_.ToSkBitmap());
|
if (notification_) {
|
||||||
}
|
notification_->Show(title_, body_, "", GURL(), icon_.AsBitmap(), silent_, has_reply_, reply_placeholder_);
|
||||||
|
}
|
||||||
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_);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool initialized_ = false;
|
bool initialized_ = false;
|
||||||
void Notification::OnInitialProps() {
|
void Notification::OnInitialProps() {
|
||||||
if (!initialized_) {
|
if (!initialized_) {
|
||||||
presenter_ = brightray::NotificationPresenter::Create();
|
presenter_ = brightray::BrowserClient::Get()->GetNotificationPresenter();
|
||||||
initialized_ = true;
|
initialized_ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,7 +138,6 @@ void Notification::BuildPrototype(v8::Isolate* isolate,
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.MakeDestroyable()
|
.MakeDestroyable()
|
||||||
.SetMethod("show", &Notification::Show)
|
.SetMethod("show", &Notification::Show)
|
||||||
.SetProperty("id", &Notification::GetID)
|
|
||||||
.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)
|
||||||
|
|
|
@ -10,9 +10,9 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "atom/browser/api/trackable_object.h"
|
#include "atom/browser/api/trackable_object.h"
|
||||||
#include "atom/browser/ui/notification_observer.h"
|
|
||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
#include "brightray/browser/notification.h"
|
#include "brightray/browser/notification.h"
|
||||||
|
#include "brightray/browser/notification_delegate.h"
|
||||||
#include "brightray/browser/notification_presenter.h"
|
#include "brightray/browser/notification_presenter.h"
|
||||||
#include "native_mate/handle.h"
|
#include "native_mate/handle.h"
|
||||||
#include "ui/gfx/image/image.h"
|
#include "ui/gfx/image/image.h"
|
||||||
|
@ -22,7 +22,7 @@ namespace atom {
|
||||||
namespace api {
|
namespace api {
|
||||||
|
|
||||||
class Notification : public mate::TrackableObject<Notification>,
|
class Notification : public mate::TrackableObject<Notification>,
|
||||||
public NotifictionObserver {
|
public brightray::NotificationDelegate {
|
||||||
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);
|
||||||
|
@ -31,11 +31,12 @@ class Notification : public mate::TrackableObject<Notification>,
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::FunctionTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
|
||||||
// NotificationObserver:
|
// NotificationDelegate:
|
||||||
void OnClicked() override;
|
void NotificationClick() override;
|
||||||
void OnReplied(std::string reply) override;
|
void NotificationReplied(const std::string reply) override;
|
||||||
void OnShown() override;
|
void NotificationDisplayed() override;
|
||||||
void OnClosed() override;
|
void NotificationDestroyed() override;
|
||||||
|
void NotificationClosed() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Notification(v8::Isolate* isolate,
|
Notification(v8::Isolate* isolate,
|
||||||
|
@ -47,7 +48,6 @@ class Notification : public mate::TrackableObject<Notification>,
|
||||||
void Show();
|
void Show();
|
||||||
|
|
||||||
// Prop Getters
|
// Prop Getters
|
||||||
int GetID();
|
|
||||||
base::string16 GetTitle();
|
base::string16 GetTitle();
|
||||||
base::string16 GetBody();
|
base::string16 GetBody();
|
||||||
bool GetSilent();
|
bool GetSilent();
|
||||||
|
@ -55,26 +55,24 @@ class Notification : public mate::TrackableObject<Notification>,
|
||||||
bool GetHasReply();
|
bool GetHasReply();
|
||||||
|
|
||||||
// Prop Setters
|
// Prop Setters
|
||||||
void SetTitle(base::string16 new_title);
|
void SetTitle(const base::string16& new_title);
|
||||||
void SetBody(base::string16 new_body);
|
void SetBody(const base::string16& new_body);
|
||||||
void SetSilent(bool new_silent);
|
void SetSilent(bool new_silent);
|
||||||
void SetReplyPlaceholder(base::string16 new_reply_placeholder);
|
void SetReplyPlaceholder(const base::string16& new_reply_placeholder);
|
||||||
void SetHasReply(bool new_has_reply);
|
void SetHasReply(bool new_has_reply);
|
||||||
|
|
||||||
void NotifyPropsUpdated();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
base::string16 title_ = base::UTF8ToUTF16("");
|
base::string16 title_;
|
||||||
base::string16 body_ = base::UTF8ToUTF16("");
|
base::string16 body_;
|
||||||
gfx::Image icon_;
|
gfx::Image icon_;
|
||||||
base::string16 icon_path_ = base::UTF8ToUTF16("");
|
base::string16 icon_path_;
|
||||||
bool has_icon_ = false;
|
bool has_icon_ = false;
|
||||||
bool silent_ = false;
|
bool silent_ = false;
|
||||||
base::string16 reply_placeholder_ = base::UTF8ToUTF16("");
|
base::string16 reply_placeholder_;
|
||||||
bool has_reply_ = false;
|
bool has_reply_ = false;
|
||||||
brightray::NotificationPresenter* presenter_;
|
brightray::NotificationPresenter* presenter_;
|
||||||
|
|
||||||
int id_;
|
base::WeakPtr<brightray::Notification> notification_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(Notification);
|
DISALLOW_COPY_AND_ASSIGN(Notification);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
// 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/api/atom_api_notification.h"
|
|
||||||
#include "brightray/browser/notification_delegate.h"
|
|
||||||
|
|
||||||
namespace atom {
|
|
||||||
|
|
||||||
AtomNotificationDelegateAdapter::AtomNotificationDelegateAdapter(
|
|
||||||
atom::api::Notification* target) {
|
|
||||||
observer_ = target;
|
|
||||||
}
|
|
||||||
void AtomNotificationDelegateAdapter::NotificationDisplayed() {
|
|
||||||
observer_->OnShown();
|
|
||||||
}
|
|
||||||
void AtomNotificationDelegateAdapter::NotificationClosed() {}
|
|
||||||
void AtomNotificationDelegateAdapter::NotificationClick() {
|
|
||||||
observer_->OnClicked();
|
|
||||||
}
|
|
||||||
void AtomNotificationDelegateAdapter::NotificationReplied(std::string reply) {
|
|
||||||
observer_->OnReplied(reply);
|
|
||||||
}
|
|
||||||
void AtomNotificationDelegateAdapter::NotificationDestroyed() {
|
|
||||||
observer_->OnClosed();
|
|
||||||
}
|
|
||||||
void AtomNotificationDelegateAdapter::NotificationFailed() {}
|
|
||||||
|
|
||||||
} // namespace atom
|
|
|
@ -1,29 +0,0 @@
|
||||||
// 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 "brightray/browser/notification_delegate.h"
|
|
||||||
|
|
||||||
#include "atom/browser/api/atom_api_notification.h"
|
|
||||||
|
|
||||||
#ifndef ATOM_BROWSER_UI_NOTIFICATION_DELEGATE_ADAPTER_H_
|
|
||||||
#define ATOM_BROWSER_UI_NOTIFICATION_DELEGATE_ADAPTER_H_
|
|
||||||
|
|
||||||
namespace atom {
|
|
||||||
|
|
||||||
class AtomNotificationDelegateAdapter : public brightray::NotificationDelegate {
|
|
||||||
public:
|
|
||||||
atom::api::Notification* observer_;
|
|
||||||
explicit AtomNotificationDelegateAdapter(atom::api::Notification* target);
|
|
||||||
|
|
||||||
void NotificationDisplayed();
|
|
||||||
void NotificationClosed();
|
|
||||||
void NotificationClick();
|
|
||||||
void NotificationDestroyed();
|
|
||||||
void NotificationFailed();
|
|
||||||
void NotificationReplied(std::string reply);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace atom
|
|
||||||
|
|
||||||
#endif // ATOM_BROWSER_UI_NOTIFICATION_DELEGATE_ADAPTER_H_
|
|
|
@ -1,25 +0,0 @@
|
||||||
// Copyright (c) 2014 GitHub, Inc.
|
|
||||||
// Use of this source code is governed by the MIT license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
#ifndef ATOM_BROWSER_UI_NOTIFICATION_OBSERVER_H_
|
|
||||||
#define ATOM_BROWSER_UI_NOTIFICATION_OBSERVER_H_
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace atom {
|
|
||||||
|
|
||||||
class NotifictionObserver {
|
|
||||||
public:
|
|
||||||
virtual void OnClicked() {}
|
|
||||||
virtual void OnReplied(std::string reply) {}
|
|
||||||
virtual void OnShown() {}
|
|
||||||
virtual void OnClosed() {}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual ~NotifictionObserver() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace atom
|
|
||||||
|
|
||||||
#endif // ATOM_BROWSER_UI_NOTIFICATION_OBSERVER_H_
|
|
|
@ -36,7 +36,7 @@ BrowserClient::~BrowserClient() {
|
||||||
|
|
||||||
NotificationPresenter* BrowserClient::GetNotificationPresenter() {
|
NotificationPresenter* BrowserClient::GetNotificationPresenter() {
|
||||||
if (!notification_presenter_) {
|
if (!notification_presenter_) {
|
||||||
// Create a new presenter if on OS X, Linux, or Windows 8+
|
// Create a new presenter if on OS X, Linux, or Windows 7+
|
||||||
notification_presenter_.reset(NotificationPresenter::Create());
|
notification_presenter_.reset(NotificationPresenter::Create());
|
||||||
}
|
}
|
||||||
return notification_presenter_.get();
|
return notification_presenter_.get();
|
||||||
|
|
|
@ -88,9 +88,9 @@ void LibnotifyNotification::Show(const base::string16& title,
|
||||||
const std::string& tag,
|
const std::string& tag,
|
||||||
const GURL& icon_url,
|
const GURL& icon_url,
|
||||||
const SkBitmap& icon,
|
const SkBitmap& icon,
|
||||||
const bool silent,
|
bool silent,
|
||||||
const bool has_reply,
|
bool has_reply,
|
||||||
const base::string16 reply_placeholder) {
|
const base::string16& reply_placeholder) {
|
||||||
notification_ = libnotify_loader_.notify_notification_new(
|
notification_ = libnotify_loader_.notify_notification_new(
|
||||||
base::UTF16ToUTF8(title).c_str(),
|
base::UTF16ToUTF8(title).c_str(),
|
||||||
base::UTF16ToUTF8(body).c_str(),
|
base::UTF16ToUTF8(body).c_str(),
|
||||||
|
@ -139,7 +139,8 @@ void LibnotifyNotification::Show(const base::string16& title,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate()->NotificationDisplayed();
|
if (delegate())
|
||||||
|
delegate()->NotificationDisplayed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibnotifyNotification::Dismiss() {
|
void LibnotifyNotification::Dismiss() {
|
||||||
|
|
|
@ -27,9 +27,9 @@ class LibnotifyNotification : public Notification {
|
||||||
const std::string& tag,
|
const std::string& tag,
|
||||||
const GURL& icon_url,
|
const GURL& icon_url,
|
||||||
const SkBitmap& icon,
|
const SkBitmap& icon,
|
||||||
const bool silent,
|
bool silent,
|
||||||
const bool has_reply,
|
bool has_reply,
|
||||||
const base::string16 reply_placeholder) override;
|
const base::string16& reply_placeholder) override;
|
||||||
void Dismiss() override;
|
void Dismiss() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -26,13 +26,13 @@ class CocoaNotification : public Notification {
|
||||||
const std::string& tag,
|
const std::string& tag,
|
||||||
const GURL& icon_url,
|
const GURL& icon_url,
|
||||||
const SkBitmap& icon,
|
const SkBitmap& icon,
|
||||||
const bool silent,
|
bool silent,
|
||||||
const bool hasReply,
|
const bool hasReply,
|
||||||
const base::string16 replyPlaceholder) override;
|
const base::string16 replyPlaceholder) override;
|
||||||
void Dismiss() override;
|
void Dismiss() override;
|
||||||
|
|
||||||
void NotificationDisplayed();
|
void NotificationDisplayed();
|
||||||
void NotificationReplied(std::string reply);
|
void NotificationReplied(const std::string reply);
|
||||||
|
|
||||||
NSUserNotification* notification() const { return notification_; }
|
NSUserNotification* notification() const { return notification_; }
|
||||||
|
|
||||||
|
|
|
@ -28,9 +28,9 @@ void CocoaNotification::Show(const base::string16& title,
|
||||||
const std::string& tag,
|
const std::string& tag,
|
||||||
const GURL& icon_url,
|
const GURL& icon_url,
|
||||||
const SkBitmap& icon,
|
const SkBitmap& icon,
|
||||||
const bool silent,
|
bool silent,
|
||||||
const bool has_reply,
|
bool has_reply,
|
||||||
const base::string16 reply_placeholder) {
|
const base::string16& reply_placeholder) {
|
||||||
notification_.reset([[NSUserNotification alloc] init]);
|
notification_.reset([[NSUserNotification alloc] init]);
|
||||||
[notification_ setTitle:base::SysUTF16ToNSString(title)];
|
[notification_ setTitle:base::SysUTF16ToNSString(title)];
|
||||||
[notification_ setInformativeText:base::SysUTF16ToNSString(body)];
|
[notification_ setInformativeText:base::SysUTF16ToNSString(body)];
|
||||||
|
@ -65,11 +65,13 @@ void CocoaNotification::Dismiss() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CocoaNotification::NotificationDisplayed() {
|
void CocoaNotification::NotificationDisplayed() {
|
||||||
delegate()->NotificationDisplayed();
|
if (delegate())
|
||||||
|
delegate()->NotificationDisplayed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CocoaNotification::NotificationReplied(const std::string reply) {
|
void CocoaNotification::NotificationReplied(const std::string reply) {
|
||||||
delegate()->NotificationReplied(reply);
|
if (delegate())
|
||||||
|
delegate()->NotificationReplied(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
- (void)userNotificationCenter:(NSUserNotificationCenter*)center
|
- (void)userNotificationCenter:(NSUserNotificationCenter*)center
|
||||||
didDeliverNotification:(NSUserNotification*)notif {
|
didDeliverNotification:(NSUserNotification*)notif {
|
||||||
auto notification = presenter_->GetNotification(notif);
|
auto notification = presenter_->GetNotification(notif);
|
||||||
if (notification)
|
if (notification)
|
||||||
notification->NotificationDisplayed();
|
notification->NotificationDisplayed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,21 +17,29 @@ Notification::Notification(NotificationDelegate* delegate,
|
||||||
}
|
}
|
||||||
|
|
||||||
Notification::~Notification() {
|
Notification::~Notification() {
|
||||||
delegate()->NotificationDestroyed();
|
if (delegate())
|
||||||
|
delegate()->NotificationDestroyed();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Notification::set_delegate(NotificationDelegate* delegate) {
|
||||||
|
delegate_ = delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notification::NotificationClicked() {
|
void Notification::NotificationClicked() {
|
||||||
delegate()->NotificationClick();
|
if (delegate())
|
||||||
|
delegate()->NotificationClick();
|
||||||
Destroy();
|
Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notification::NotificationDismissed() {
|
void Notification::NotificationDismissed() {
|
||||||
delegate()->NotificationClosed();
|
if (delegate())
|
||||||
|
delegate()->NotificationClosed();
|
||||||
Destroy();
|
Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notification::NotificationFailed() {
|
void Notification::NotificationFailed() {
|
||||||
delegate()->NotificationFailed();
|
if (delegate())
|
||||||
|
delegate()->NotificationFailed();
|
||||||
Destroy();
|
Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,9 +26,9 @@ class Notification {
|
||||||
const std::string& tag,
|
const std::string& tag,
|
||||||
const GURL& icon_url,
|
const GURL& icon_url,
|
||||||
const SkBitmap& icon,
|
const SkBitmap& icon,
|
||||||
const bool silent,
|
bool silent,
|
||||||
const bool hasReply,
|
bool hasReply,
|
||||||
const base::string16 replyPlaceholder) = 0;
|
const base::string16& reply_placeholder) = 0;
|
||||||
// Closes the notification, this instance will be destroyed after the
|
// Closes the notification, this instance will be destroyed after the
|
||||||
// notification gets closed.
|
// notification gets closed.
|
||||||
virtual void Dismiss() = 0;
|
virtual void Dismiss() = 0;
|
||||||
|
@ -54,6 +54,7 @@ class Notification {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~Notification();
|
virtual ~Notification();
|
||||||
|
void set_delegate(NotificationDelegate* delegate);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NotificationDelegate* delegate_;
|
NotificationDelegate* delegate_;
|
||||||
|
|
|
@ -19,7 +19,7 @@ class NotificationDelegate : public content::DesktopNotificationDelegate {
|
||||||
virtual void NotificationFailed() {}
|
virtual void NotificationFailed() {}
|
||||||
|
|
||||||
// Notification was replied to
|
// Notification was replied to
|
||||||
virtual void NotificationReplied(std::string reply) {}
|
virtual void NotificationReplied(const std::string reply) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
|
@ -30,8 +30,4 @@ void NotificationDelegateAdapter::NotificationClick() {
|
||||||
delegate_->NotificationClick();
|
delegate_->NotificationClick();
|
||||||
}
|
}
|
||||||
|
|
||||||
// void NotificationDelegateAdapter::NotificationReplied(std::string reply) {
|
|
||||||
// delegate_->NotificationReplied(reply);
|
|
||||||
// }
|
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#include "brightray/browser/win/notification_presenter_win7.h"
|
#include "brightray/browser/win/notification_presenter_win7.h"
|
||||||
#include "brightray/browser/win/windows_toast_notification.h"
|
#include "brightray/browser/win/windows_toast_notification.h"
|
||||||
#include "content/public/browser/desktop_notification_delegate.h"
|
#include "content/public/browser/desktop_notification_delegate.h"
|
||||||
#include "content/public/common/platform_notification_data.h"
|
#include "content/public/common/platform_notification_data.h"
|
||||||
#include "third_party/skia/include/core/SkBitmap.h"
|
#include "third_party/skia/include/core/SkBitmap.h"
|
||||||
#include "ui/gfx/codec/png_codec.h"
|
#include "ui/gfx/codec/png_codec.h"
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,8 @@ namespace brightray {
|
||||||
void Win32Notification::Show(
|
void Win32Notification::Show(
|
||||||
const base::string16& title, const base::string16& msg,
|
const base::string16& title, const base::string16& msg,
|
||||||
const std::string& tag, const GURL& icon_url,
|
const std::string& tag, const GURL& icon_url,
|
||||||
const SkBitmap& icon, const bool silent,
|
const SkBitmap& icon, bool silent,
|
||||||
const bool has_reply, const base::string16 reply_placeholder) {
|
bool has_reply, const base::string16& reply_placeholder) {
|
||||||
auto presenter = static_cast<NotificationPresenterWin7*>(this->presenter());
|
auto presenter = static_cast<NotificationPresenterWin7*>(this->presenter());
|
||||||
if (!presenter) return;
|
if (!presenter) return;
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,8 @@ class Win32Notification : public brightray::Notification {
|
||||||
}
|
}
|
||||||
void Show(const base::string16& title, const base::string16& msg,
|
void Show(const base::string16& title, const base::string16& msg,
|
||||||
const std::string& tag, const GURL& icon_url,
|
const std::string& tag, const GURL& icon_url,
|
||||||
const SkBitmap& icon, const bool silent,
|
const SkBitmap& icon, bool silent,
|
||||||
const bool has_reply, const base::string16 reply_placeholder) override;
|
bool has_reply, const base::string16& reply_placeholder) override;
|
||||||
void Dismiss() override;
|
void Dismiss() override;
|
||||||
|
|
||||||
const DesktopNotificationController::Notification& GetRef() const {
|
const DesktopNotificationController::Notification& GetRef() const {
|
||||||
|
|
|
@ -89,9 +89,9 @@ void WindowsToastNotification::Show(const base::string16& title,
|
||||||
const std::string& tag,
|
const std::string& tag,
|
||||||
const GURL& icon_url,
|
const GURL& icon_url,
|
||||||
const SkBitmap& icon,
|
const SkBitmap& icon,
|
||||||
const bool silent,
|
bool silent,
|
||||||
const bool hasReply,
|
bool has_reply,
|
||||||
const base::string16 replyPlaceholder) {
|
const base::string16& reply_placeholder) {
|
||||||
auto presenter_win = static_cast<NotificationPresenterWin*>(presenter());
|
auto presenter_win = static_cast<NotificationPresenterWin*>(presenter());
|
||||||
std::wstring icon_path = presenter_win->SaveIconToFilesystem(icon, icon_url);
|
std::wstring icon_path = presenter_win->SaveIconToFilesystem(icon, icon_url);
|
||||||
|
|
||||||
|
@ -133,7 +133,8 @@ void WindowsToastNotification::Show(const base::string16& title,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate()->NotificationDisplayed();
|
if (delegate())
|
||||||
|
delegate()->NotificationDisplayed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowsToastNotification::Dismiss() {
|
void WindowsToastNotification::Dismiss() {
|
||||||
|
@ -146,7 +147,7 @@ bool WindowsToastNotification::GetToastXml(
|
||||||
const std::wstring& title,
|
const std::wstring& title,
|
||||||
const std::wstring& msg,
|
const std::wstring& msg,
|
||||||
const std::wstring& icon_path,
|
const std::wstring& icon_path,
|
||||||
const bool silent,
|
bool silent,
|
||||||
IXmlDocument** toast_xml) {
|
IXmlDocument** toast_xml) {
|
||||||
ABI::Windows::UI::Notifications::ToastTemplateType template_type;
|
ABI::Windows::UI::Notifications::ToastTemplateType template_type;
|
||||||
if (title.empty() || msg.empty()) {
|
if (title.empty() || msg.empty()) {
|
||||||
|
|
|
@ -55,9 +55,9 @@ class WindowsToastNotification : public Notification {
|
||||||
const std::string& tag,
|
const std::string& tag,
|
||||||
const GURL& icon_url,
|
const GURL& icon_url,
|
||||||
const SkBitmap& icon,
|
const SkBitmap& icon,
|
||||||
const bool silent,
|
bool silent,
|
||||||
const bool has_reply,
|
bool has_reply,
|
||||||
const base::string16 reply_placeholder) override;
|
const base::string16& reply_placeholder) override;
|
||||||
void Dismiss() override;
|
void Dismiss() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -6,7 +6,7 @@ Process: [Main](../glossary.md#main-process)
|
||||||
|
|
||||||
## Using in the renderer process
|
## Using in the renderer process
|
||||||
|
|
||||||
If you want to use Notifications in a renderer process you should use the [HTML5 Notification API](../tutorial/notifications.md)
|
If you want to show Notifications from a renderer process you should use the [HTML5 Notification API](../tutorial/notifications.md)
|
||||||
|
|
||||||
## Class: Notification
|
## Class: Notification
|
||||||
|
|
||||||
|
|
|
@ -313,9 +313,6 @@
|
||||||
'atom/browser/ui/message_box_gtk.cc',
|
'atom/browser/ui/message_box_gtk.cc',
|
||||||
'atom/browser/ui/message_box_mac.mm',
|
'atom/browser/ui/message_box_mac.mm',
|
||||||
'atom/browser/ui/message_box_win.cc',
|
'atom/browser/ui/message_box_win.cc',
|
||||||
'atom/browser/ui/notification_delegate_adapter.h',
|
|
||||||
'atom/browser/ui/notification_delegate_adapter.cc',
|
|
||||||
'atom/browser/ui/notification_observer.h',
|
|
||||||
'atom/browser/ui/tray_icon.cc',
|
'atom/browser/ui/tray_icon.cc',
|
||||||
'atom/browser/ui/tray_icon.h',
|
'atom/browser/ui/tray_icon.h',
|
||||||
'atom/browser/ui/tray_icon_gtk.cc',
|
'atom/browser/ui/tray_icon_gtk.cc',
|
||||||
|
|
Loading…
Reference in a new issue