#include "base/time/time.h"
#include "base/values.h"
#include "atom/browser/auto_updater.h"
-#include "atom/common/v8/native_type_conversions.h"
+#include "native_mate/dictionary.h"
+#include "native_mate/object_template_builder.h"
#include "atom/common/node_includes.h"
namespace api {
-AutoUpdater::AutoUpdater(v8::Handle<v8::Object> wrapper)
- : EventEmitter(wrapper) {
+AutoUpdater::AutoUpdater() {
auto_updater::AutoUpdater::SetDelegate(this);
}
void AutoUpdater::OnError(const std::string& error) {
base::ListValue args;
args.AppendString(error);
- Emit("error", &args);
+ Emit("error", args);
}
void AutoUpdater::OnCheckingForUpdate() {
args.AppendString(release_name);
args.AppendDouble(release_date.ToJsTime());
args.AppendString(update_url);
- Emit("update-downloaded-raw", &args);
+ Emit("update-downloaded-raw", args);
}
-// static
-void AutoUpdater::New(const v8::FunctionCallbackInfo<v8::Value>& args) {
- if (!args.IsConstructCall())
- return node::ThrowError("Require constructor call");
-
- new AutoUpdater(args.This());
+mate::ObjectTemplateBuilder AutoUpdater::GetObjectTemplateBuilder(
+ v8::Isolate* isolate) {
+ return mate::ObjectTemplateBuilder(isolate)
+ .SetMethod("setFeedUrl", &auto_updater::AutoUpdater::SetFeedURL)
+ .SetMethod("checkForUpdates", &auto_updater::AutoUpdater::CheckForUpdates)
+ .SetMethod("quitAndInstall", &AutoUpdater::QuitAndInstall);
}
-// static
-void AutoUpdater::SetFeedURL(const v8::FunctionCallbackInfo<v8::Value>& args) {
- auto_updater::AutoUpdater::SetFeedURL(FromV8Value(args[0]));
+void AutoUpdater::QuitAndInstall() {
+ if (!quit_and_install_.is_null())
+ quit_and_install_.Run();
}
// static
-void AutoUpdater::CheckForUpdates(
- const v8::FunctionCallbackInfo<v8::Value>& args) {
- auto_updater::AutoUpdater::CheckForUpdates();
+mate::Handle<AutoUpdater> AutoUpdater::Create(v8::Isolate* isolate) {
+ return CreateHandle(isolate, new AutoUpdater);
}
-// static
-void AutoUpdater::QuitAndInstall(
- const v8::FunctionCallbackInfo<v8::Value>& args) {
- AutoUpdater* self = AutoUpdater::Unwrap<AutoUpdater>(args.This());
+} // namespace api
- if (!self->quit_and_install_.is_null())
- self->quit_and_install_.Run();
-}
+} // namespace atom
-// static
-void AutoUpdater::Initialize(v8::Handle<v8::Object> target) {
- v8::Local<v8::FunctionTemplate> t(
- v8::FunctionTemplate::New(AutoUpdater::New));
- t->InstanceTemplate()->SetInternalFieldCount(1);
- t->SetClassName(v8::String::NewSymbol("AutoUpdater"));
- NODE_SET_PROTOTYPE_METHOD(t, "setFeedUrl", SetFeedURL);
- NODE_SET_PROTOTYPE_METHOD(t, "checkForUpdates", CheckForUpdates);
- NODE_SET_PROTOTYPE_METHOD(t, "quitAndInstall", QuitAndInstall);
+namespace {
- target->Set(v8::String::NewSymbol("AutoUpdater"), t->GetFunction());
+void Initialize(v8::Handle<v8::Object> exports) {
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
+ mate::Dictionary dict(isolate, exports);
+ dict.Set("autoUpdater", atom::api::AutoUpdater::Create(isolate));
}
-} // namespace api
-
-} // namespace atom
+} // namespace
-NODE_MODULE(atom_browser_auto_updater, atom::api::AutoUpdater::Initialize)
+NODE_MODULE(atom_browser_auto_updater, Initialize)
#include <string>
#include "base/callback.h"
-#include "base/memory/scoped_ptr.h"
+#include "atom/browser/api/event_emitter.h"
#include "atom/browser/auto_updater_delegate.h"
-#include "atom/common/api/atom_api_event_emitter.h"
+#include "native_mate/handle.h"
namespace atom {
namespace api {
-class AutoUpdater : public EventEmitter,
+class AutoUpdater : public mate::EventEmitter,
public auto_updater::AutoUpdaterDelegate {
public:
- virtual ~AutoUpdater();
-
- static void Initialize(v8::Handle<v8::Object> target);
+ static mate::Handle<AutoUpdater> Create(v8::Isolate* isolate);
protected:
- explicit AutoUpdater(v8::Handle<v8::Object> wrapper);
+ AutoUpdater();
+ virtual ~AutoUpdater();
// AutoUpdaterDelegate implementations.
virtual void OnError(const std::string& error) OVERRIDE;
const std::string& update_url,
const base::Closure& quit_and_install) OVERRIDE;
- private:
- static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
-
- static void SetFeedURL(const v8::FunctionCallbackInfo<v8::Value>& args);
- static void CheckForUpdates(const v8::FunctionCallbackInfo<v8::Value>& args);
+ // mate::Wrappable implementations:
+ virtual mate::ObjectTemplateBuilder GetObjectTemplateBuilder(
+ v8::Isolate* isolate);
- static void ContinueUpdate(const v8::FunctionCallbackInfo<v8::Value>& args);
- static void QuitAndInstall(const v8::FunctionCallbackInfo<v8::Value>& args);
+ private:
+ void QuitAndInstall();
base::Closure quit_and_install_;