refactor: move notifications from brightray to atom (#15209)

This commit is contained in:
Milan Burda 2018-10-17 20:01:11 +02:00 committed by Alexey Kuzmin
parent 4d085c4aae
commit a369a4172b
46 changed files with 423 additions and 363 deletions

View file

@ -5,13 +5,13 @@
#include "atom/browser/api/atom_api_notification.h"
#include "atom/browser/api/atom_api_menu.h"
#include "atom/browser/atom_browser_client.h"
#include "atom/browser/browser.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/string16_converter.h"
#include "base/guid.h"
#include "base/strings/utf_string_conversions.h"
#include "brightray/browser/browser_client.h"
#include "native_mate/constructor.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
@ -22,10 +22,10 @@
namespace mate {
template <>
struct Converter<brightray::NotificationAction> {
struct Converter<atom::NotificationAction> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
brightray::NotificationAction* out) {
atom::NotificationAction* out) {
mate::Dictionary dict;
if (!ConvertFromV8(isolate, val, &dict))
return false;
@ -38,7 +38,7 @@ struct Converter<brightray::NotificationAction> {
}
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
brightray::NotificationAction val) {
atom::NotificationAction val) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
dict.Set("text", val.text);
dict.Set("type", val.type);
@ -56,7 +56,8 @@ Notification::Notification(v8::Isolate* isolate,
mate::Arguments* args) {
InitWith(isolate, wrapper);
presenter_ = brightray::BrowserClient::Get()->GetNotificationPresenter();
presenter_ = static_cast<AtomBrowserClient*>(AtomBrowserClient::Get())
->GetNotificationPresenter();
mate::Dictionary opts;
if (args->GetNext(&opts)) {
@ -119,7 +120,7 @@ base::string16 Notification::GetSound() const {
return sound_;
}
std::vector<brightray::NotificationAction> Notification::GetActions() const {
std::vector<atom::NotificationAction> Notification::GetActions() const {
return actions_;
}
@ -157,7 +158,7 @@ void Notification::SetSound(const base::string16& new_sound) {
}
void Notification::SetActions(
const std::vector<brightray::NotificationAction>& actions) {
const std::vector<atom::NotificationAction>& actions) {
actions_ = actions;
}
@ -200,7 +201,7 @@ void Notification::Show() {
if (presenter_) {
notification_ = presenter_->CreateNotification(this, base::GenerateGUID());
if (notification_) {
brightray::NotificationOptions options;
atom::NotificationOptions options;
options.title = title_;
options.subtitle = subtitle_;
options.msg = body_;
@ -218,7 +219,8 @@ void Notification::Show() {
}
bool Notification::IsSupported() {
return !!brightray::BrowserClient::Get()->GetNotificationPresenter();
return !!static_cast<AtomBrowserClient*>(AtomBrowserClient::Get())
->GetNotificationPresenter();
}
// static

View file

@ -10,10 +10,10 @@
#include <vector>
#include "atom/browser/api/trackable_object.h"
#include "atom/browser/notifications/notification.h"
#include "atom/browser/notifications/notification_delegate.h"
#include "atom/browser/notifications/notification_presenter.h"
#include "base/strings/utf_string_conversions.h"
#include "brightray/browser/notification.h"
#include "brightray/browser/notification_delegate.h"
#include "brightray/browser/notification_presenter.h"
#include "native_mate/handle.h"
#include "ui/gfx/image/image.h"
@ -22,7 +22,7 @@ namespace atom {
namespace api {
class Notification : public mate::TrackableObject<Notification>,
public brightray::NotificationDelegate {
public NotificationDelegate {
public:
static mate::WrappableBase* New(mate::Arguments* args);
static bool IsSupported();
@ -55,7 +55,7 @@ class Notification : public mate::TrackableObject<Notification>,
bool GetHasReply() const;
base::string16 GetReplyPlaceholder() const;
base::string16 GetSound() const;
std::vector<brightray::NotificationAction> GetActions() const;
std::vector<atom::NotificationAction> GetActions() const;
base::string16 GetCloseButtonText() const;
// Prop Setters
@ -66,7 +66,7 @@ class Notification : public mate::TrackableObject<Notification>,
void SetHasReply(bool new_has_reply);
void SetReplyPlaceholder(const base::string16& new_reply_placeholder);
void SetSound(const base::string16& sound);
void SetActions(const std::vector<brightray::NotificationAction>& actions);
void SetActions(const std::vector<atom::NotificationAction>& actions);
void SetCloseButtonText(const base::string16& text);
private:
@ -80,12 +80,12 @@ class Notification : public mate::TrackableObject<Notification>,
bool has_reply_ = false;
base::string16 reply_placeholder_;
base::string16 sound_;
std::vector<brightray::NotificationAction> actions_;
std::vector<atom::NotificationAction> actions_;
base::string16 close_button_text_;
brightray::NotificationPresenter* presenter_;
atom::NotificationPresenter* presenter_;
base::WeakPtr<brightray::Notification> notification_;
base::WeakPtr<atom::Notification> notification_;
DISALLOW_COPY_AND_ASSIGN(Notification);
};