From a3786f66c916abf22d876d195d8ae3c9649c7d30 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 13 Jun 2016 09:32:24 +0900 Subject: [PATCH] Do not add JS wrapper for setFeedURL When possible we should avoid adding wrappers in JS, it usually makes code more difficult to mantain --- atom/browser/api/atom_api_auto_updater.cc | 8 +++++++- atom/browser/api/atom_api_auto_updater.h | 2 ++ docs/api/auto-updater.md | 2 +- lib/browser/api/auto-updater/auto-updater-native.js | 4 ---- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/atom/browser/api/atom_api_auto_updater.cc b/atom/browser/api/atom_api_auto_updater.cc index cb9bce147212..54e2bd9f746a 100644 --- a/atom/browser/api/atom_api_auto_updater.cc +++ b/atom/browser/api/atom_api_auto_updater.cc @@ -79,6 +79,12 @@ void AutoUpdater::OnWindowAllClosed() { QuitAndInstall(); } +void AutoUpdater::SetFeedURL(const std::string& url, mate::Arguments* args) { + auto_updater::AutoUpdater::HeaderMap headers; + args->GetNext(&headers); + auto_updater::AutoUpdater::SetFeedURL(url, headers); +} + void AutoUpdater::QuitAndInstall() { // If we don't have any window then quitAndInstall immediately. WindowList* window_list = WindowList::GetInstance(); @@ -102,8 +108,8 @@ mate::Handle AutoUpdater::Create(v8::Isolate* isolate) { void AutoUpdater::BuildPrototype( v8::Isolate* isolate, v8::Local prototype) { mate::ObjectTemplateBuilder(isolate, prototype) - .SetMethod("_setFeedURL", &auto_updater::AutoUpdater::SetFeedURL) .SetMethod("checkForUpdates", &auto_updater::AutoUpdater::CheckForUpdates) + .SetMethod("setFeedURL", &AutoUpdater::SetFeedURL) .SetMethod("quitAndInstall", &AutoUpdater::QuitAndInstall); } diff --git a/atom/browser/api/atom_api_auto_updater.h b/atom/browser/api/atom_api_auto_updater.h index 857647258adf..e8c135f292ea 100644 --- a/atom/browser/api/atom_api_auto_updater.h +++ b/atom/browser/api/atom_api_auto_updater.h @@ -10,6 +10,7 @@ #include "atom/browser/api/event_emitter.h" #include "atom/browser/auto_updater.h" #include "atom/browser/window_list_observer.h" +#include "native_mate/arguments.h" #include "native_mate/handle.h" namespace atom { @@ -43,6 +44,7 @@ class AutoUpdater : public mate::EventEmitter, void OnWindowAllClosed() override; private: + void SetFeedURL(const std::string& url, mate::Arguments* args); void QuitAndInstall(); DISALLOW_COPY_AND_ASSIGN(AutoUpdater); diff --git a/docs/api/auto-updater.md b/docs/api/auto-updater.md index a1752769473f..268404dee95a 100644 --- a/docs/api/auto-updater.md +++ b/docs/api/auto-updater.md @@ -97,7 +97,7 @@ The `autoUpdater` object has the following methods: ### `autoUpdater.setFeedURL(url[, requestHeaders])` * `url` String -* `requestHeaders` Object - HTTP request headers (_OS X_) +* `requestHeaders` Object _OS X_ - HTTP request headers. Sets the `url` and initialize the auto updater. diff --git a/lib/browser/api/auto-updater/auto-updater-native.js b/lib/browser/api/auto-updater/auto-updater-native.js index e2c79a910106..1fff05dbd65c 100644 --- a/lib/browser/api/auto-updater/auto-updater-native.js +++ b/lib/browser/api/auto-updater/auto-updater-native.js @@ -3,8 +3,4 @@ const autoUpdater = process.atomBinding('auto_updater').autoUpdater Object.setPrototypeOf(autoUpdater, EventEmitter.prototype) -autoUpdater.setFeedURL = function (url, headers) { - return autoUpdater._setFeedURL(url, headers || {}) -} - module.exports = autoUpdater