From 51687e1bc947800e641315ff1d25bf22d8111f98 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Fri, 15 Jul 2016 00:04:48 +1200 Subject: [PATCH 1/6] Add the getFeedURL API for macOS and Windows --- atom/browser/api/atom_api_auto_updater.cc | 5 +++++ atom/browser/api/atom_api_auto_updater.h | 1 + atom/browser/auto_updater.cc | 4 ++++ atom/browser/auto_updater.h | 1 + atom/browser/auto_updater_mac.mm | 7 +++++++ lib/browser/api/auto-updater/auto-updater-win.js | 4 ++++ 6 files changed, 22 insertions(+) diff --git a/atom/browser/api/atom_api_auto_updater.cc b/atom/browser/api/atom_api_auto_updater.cc index 54e2bd9f746a..3b493d4d2092 100644 --- a/atom/browser/api/atom_api_auto_updater.cc +++ b/atom/browser/api/atom_api_auto_updater.cc @@ -79,6 +79,10 @@ void AutoUpdater::OnWindowAllClosed() { QuitAndInstall(); } +std::string AutoUpdater::GetFeedURL() { + return ""; +} + void AutoUpdater::SetFeedURL(const std::string& url, mate::Arguments* args) { auto_updater::AutoUpdater::HeaderMap headers; args->GetNext(&headers); @@ -109,6 +113,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/lib/browser/api/auto-updater/auto-updater-win.js b/lib/browser/api/auto-updater/auto-updater-win.js index 8775534031f4..6c8f5d289664 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 } From b367c65bcd48099ecfd65dd92a5ca2130b75c69c Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Fri, 15 Jul 2016 00:07:17 +1200 Subject: [PATCH 2/6] Add docs for getFeedURL --- docs/api/auto-updater.md | 4 ++++ 1 file changed, 4 insertions(+) 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 From fa7526202b96f5b46bc79508d9824eeca1e87bef Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Fri, 15 Jul 2016 00:12:31 +1200 Subject: [PATCH 3/6] Remove unnecessary method --- atom/browser/api/atom_api_auto_updater.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/atom/browser/api/atom_api_auto_updater.cc b/atom/browser/api/atom_api_auto_updater.cc index 3b493d4d2092..f8d9a2f9ac92 100644 --- a/atom/browser/api/atom_api_auto_updater.cc +++ b/atom/browser/api/atom_api_auto_updater.cc @@ -79,10 +79,6 @@ void AutoUpdater::OnWindowAllClosed() { QuitAndInstall(); } -std::string AutoUpdater::GetFeedURL() { - return ""; -} - void AutoUpdater::SetFeedURL(const std::string& url, mate::Arguments* args) { auto_updater::AutoUpdater::HeaderMap headers; args->GetNext(&headers); From 84a8c393a87f53b23ffb1ce47752e14d753407c8 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Fri, 15 Jul 2016 00:29:53 +1200 Subject: [PATCH 4/6] Fix linting, removes additional semicolon --- lib/browser/api/auto-updater/auto-updater-win.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/browser/api/auto-updater/auto-updater-win.js b/lib/browser/api/auto-updater/auto-updater-win.js index 6c8f5d289664..fc9c4a6e56ba 100644 --- a/lib/browser/api/auto-updater/auto-updater-win.js +++ b/lib/browser/api/auto-updater/auto-updater-win.js @@ -20,7 +20,7 @@ AutoUpdater.prototype.quitAndInstall = function () { } AutoUpdater.prototype.GetFeedURL = function () { - return this.updateURL; + return this.updateURL } AutoUpdater.prototype.setFeedURL = function (updateURL, headers) { From d42e6b3c1f45599acd3dffde4593c6fbfa86602b Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Fri, 15 Jul 2016 10:05:36 +1200 Subject: [PATCH 5/6] Fix casing issue on the windows update JS file --- lib/browser/api/auto-updater/auto-updater-win.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/browser/api/auto-updater/auto-updater-win.js b/lib/browser/api/auto-updater/auto-updater-win.js index fc9c4a6e56ba..564e2ff762a2 100644 --- a/lib/browser/api/auto-updater/auto-updater-win.js +++ b/lib/browser/api/auto-updater/auto-updater-win.js @@ -19,7 +19,7 @@ AutoUpdater.prototype.quitAndInstall = function () { return app.quit() } -AutoUpdater.prototype.GetFeedURL = function () { +AutoUpdater.prototype.getFeedURL = function () { return this.updateURL } From 450c181da3de4fae51ab0114612a42dce852a70b Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Fri, 15 Jul 2016 10:13:41 +1200 Subject: [PATCH 6/6] Add autoUpdater getFeedURL specs --- spec/api-auto-updater-spec.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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() + }) + }) }) }