1 // Copyright (c) 2013 GitHub, Inc.
2 // Use of this source code is governed by the MIT license that can be
3 // found in the LICENSE file.
5 #include "atom/browser/api/atom_api_auto_updater.h"
7 #include "base/time/time.h"
8 #include "atom/browser/auto_updater.h"
9 #include "atom/browser/browser.h"
10 #include "atom/common/node_includes.h"
11 #include "native_mate/dictionary.h"
12 #include "native_mate/object_template_builder.h"
18 AutoUpdater::AutoUpdater() {
19 auto_updater::AutoUpdater::SetDelegate(this);
22 AutoUpdater::~AutoUpdater() {
23 auto_updater::AutoUpdater::SetDelegate(NULL);
26 void AutoUpdater::OnError(const std::string& error) {
30 void AutoUpdater::OnCheckingForUpdate() {
31 Emit("checking-for-update");
34 void AutoUpdater::OnUpdateAvailable() {
35 Emit("update-available");
38 void AutoUpdater::OnUpdateNotAvailable() {
39 Emit("update-not-available");
42 void AutoUpdater::OnUpdateDownloaded(const std::string& release_notes,
43 const std::string& release_name,
44 const base::Time& release_date,
45 const std::string& update_url,
46 const base::Closure& quit_and_install) {
47 quit_and_install_ = quit_and_install;
48 Emit("update-downloaded-raw", release_notes, release_name,
49 release_date.ToJsTime(), update_url);
52 mate::ObjectTemplateBuilder AutoUpdater::GetObjectTemplateBuilder(
53 v8::Isolate* isolate) {
54 return mate::ObjectTemplateBuilder(isolate)
55 .SetMethod("setFeedUrl", &auto_updater::AutoUpdater::SetFeedURL)
56 .SetMethod("checkForUpdates", &auto_updater::AutoUpdater::CheckForUpdates)
57 .SetMethod("_quitAndInstall", &AutoUpdater::QuitAndInstall);
60 void AutoUpdater::QuitAndInstall() {
61 if (quit_and_install_.is_null())
62 Browser::Get()->Shutdown();
64 quit_and_install_.Run();
68 mate::Handle<AutoUpdater> AutoUpdater::Create(v8::Isolate* isolate) {
69 return CreateHandle(isolate, new AutoUpdater);
79 void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
80 v8::Local<v8::Context> context, void* priv) {
81 v8::Isolate* isolate = context->GetIsolate();
82 mate::Dictionary dict(isolate, exports);
83 dict.Set("autoUpdater", atom::api::AutoUpdater::Create(isolate));
88 NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_auto_updater, Initialize)