diff --git a/atom/browser/api/atom_api_auto_updater.cc b/atom/browser/api/atom_api_auto_updater.cc index 54e2bd9f746a..f8d9a2f9ac92 100644 --- a/atom/browser/api/atom_api_auto_updater.cc +++ b/atom/browser/api/atom_api_auto_updater.cc @@ -109,6 +109,7 @@ void AutoUpdater::BuildPrototype( v8::Isolate* isolate, v8::Local prototype) { mate::ObjectTemplateBuilder(isolate, prototype) .SetMethod("checkForUpdates", &auto_updater::AutoUpdater::CheckForUpdates) + .SetMethod("getFeedURL", &auto_updater::AutoUpdater::GetFeedURL) .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 e8c135f292ea..4c73f7ce8e9c 100644 --- a/atom/browser/api/atom_api_auto_updater.h +++ b/atom/browser/api/atom_api_auto_updater.h @@ -44,6 +44,7 @@ class AutoUpdater : public mate::EventEmitter, void OnWindowAllClosed() override; private: + std::string GetFeedURL(); void SetFeedURL(const std::string& url, mate::Arguments* args); void QuitAndInstall(); diff --git a/atom/browser/auto_updater.cc b/atom/browser/auto_updater.cc index 5a14eda2e147..8ada3ff6ab3d 100644 --- a/atom/browser/auto_updater.cc +++ b/atom/browser/auto_updater.cc @@ -17,6 +17,10 @@ void AutoUpdater::SetDelegate(Delegate* delegate) { } #if !defined(OS_MACOSX) || defined(MAS_BUILD) +std::string AutoUpdater::GetFeedURL() { + return ""; +} + void AutoUpdater::SetFeedURL(const std::string& url, const HeaderMap& requestHeaders) { } diff --git a/atom/browser/auto_updater.h b/atom/browser/auto_updater.h index ad0b2cc18b9a..aa4ca19cf21f 100644 --- a/atom/browser/auto_updater.h +++ b/atom/browser/auto_updater.h @@ -49,6 +49,7 @@ class AutoUpdater { static Delegate* GetDelegate(); static void SetDelegate(Delegate* delegate); + static std::string GetFeedURL(); static void SetFeedURL(const std::string& url, const HeaderMap& requestHeaders); static void CheckForUpdates(); diff --git a/atom/browser/auto_updater_mac.mm b/atom/browser/auto_updater_mac.mm index 005627e6c089..1987f33621d8 100644 --- a/atom/browser/auto_updater_mac.mm +++ b/atom/browser/auto_updater_mac.mm @@ -25,9 +25,14 @@ SQRLUpdater* g_updater = nil; namespace { bool g_update_available = false; +std::string update_url_ = ""; } +std::string AutoUpdater::GetFeedURL() { + return update_url_; +} + // static void AutoUpdater::SetFeedURL(const std::string& feed, const HeaderMap& requestHeaders) { @@ -35,6 +40,8 @@ void AutoUpdater::SetFeedURL(const std::string& feed, if (!delegate) return; + update_url_ = feed; + NSURL* url = [NSURL URLWithString:base::SysUTF8ToNSString(feed)]; NSMutableURLRequest* urlRequest = [NSMutableURLRequest requestWithURL:url]; diff --git a/docs/api/auto-updater.md b/docs/api/auto-updater.md index 46157d02e911..20ba44c721c5 100644 --- a/docs/api/auto-updater.md +++ b/docs/api/auto-updater.md @@ -100,6 +100,10 @@ The `autoUpdater` object has the following methods: Sets the `url` and initialize the auto updater. +### `autoUpdater.getFeedURL()` + +Returns the current update feed URL. + ### `autoUpdater.checkForUpdates()` Asks the server whether there is an update. You must call `setFeedURL` before diff --git a/lib/browser/api/auto-updater/auto-updater-win.js b/lib/browser/api/auto-updater/auto-updater-win.js index 8775534031f4..564e2ff762a2 100644 --- a/lib/browser/api/auto-updater/auto-updater-win.js +++ b/lib/browser/api/auto-updater/auto-updater-win.js @@ -19,6 +19,10 @@ AutoUpdater.prototype.quitAndInstall = function () { return app.quit() } +AutoUpdater.prototype.getFeedURL = function () { + return this.updateURL +} + AutoUpdater.prototype.setFeedURL = function (updateURL, headers) { this.updateURL = updateURL } diff --git a/spec/api-auto-updater-spec.js b/spec/api-auto-updater-spec.js index f3c897865b88..f93590ccadd4 100644 --- a/spec/api-auto-updater-spec.js +++ b/spec/api-auto-updater-spec.js @@ -33,5 +33,22 @@ if (!process.mas) { autoUpdater.setFeedURL('') }) }) + + describe('getFeedURL', function () { + it('returns a falsey value by default', function () { + assert.ok(!autoUpdater.getFeedURL()) + }) + + it('correctly fetches the previously set FeedURL', function (done) { + if (process.platform !== 'win32') { + return done() + } + + const updateURL = 'https://fake-update.electron.io' + autoUpdater.setFeedURL(updateURL) + assert.equal(autoUpdater.getFeedURL(), updateURL) + done() + }) + }) }) }