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