Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to use Squirrel.Mac that supports CDN releases #11925

Merged
merged 4 commits into from Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions atom/browser/api/atom_api_auto_updater.cc
Expand Up @@ -99,10 +99,8 @@ 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::SetFeedURL(mate::Arguments* args) {
auto_updater::AutoUpdater::SetFeedURL(args);
}

void AutoUpdater::QuitAndInstall() {
Expand Down
2 changes: 1 addition & 1 deletion atom/browser/api/atom_api_auto_updater.h
Expand Up @@ -47,7 +47,7 @@ class AutoUpdater : public mate::EventEmitter<AutoUpdater>,

private:
std::string GetFeedURL();
void SetFeedURL(const std::string& url, mate::Arguments* args);
void SetFeedURL(mate::Arguments* args);
void QuitAndInstall();

DISALLOW_COPY_AND_ASSIGN(AutoUpdater);
Expand Down
3 changes: 1 addition & 2 deletions atom/browser/auto_updater.cc
Expand Up @@ -21,8 +21,7 @@ std::string AutoUpdater::GetFeedURL() {
return "";
}

void AutoUpdater::SetFeedURL(const std::string& url,
const HeaderMap& requestHeaders) {
void AutoUpdater::SetFeedURL(mate::Arguments* args) {
}

void AutoUpdater::CheckForUpdates() {
Expand Down
4 changes: 2 additions & 2 deletions atom/browser/auto_updater.h
Expand Up @@ -10,6 +10,7 @@

#include "base/macros.h"
#include "build/build_config.h"
#include "native_mate/arguments.h"

namespace base {
class Time;
Expand Down Expand Up @@ -53,8 +54,7 @@ class AutoUpdater {
static void SetDelegate(Delegate* delegate);

static std::string GetFeedURL();
static void SetFeedURL(const std::string& url,
const HeaderMap& requestHeaders);
static void SetFeedURL(mate::Arguments* args);
static void CheckForUpdates();
static void QuitAndInstall();

Expand Down
37 changes: 34 additions & 3 deletions atom/browser/auto_updater_mac.mm
Expand Up @@ -9,9 +9,13 @@
#import <ReactiveCocoa/NSObject+RACPropertySubscribing.h>
#import <Squirrel/Squirrel.h>

#include "atom/browser/browser.h"
#include "atom/common/native_mate_converters/value_converter.h"
#include "base/bind.h"
#include "base/time/time.h"
#include "base/strings/sys_string_conversions.h"
#include "native_mate/converter.h"
#include "native_mate/dictionary.h"

namespace auto_updater {

Expand All @@ -34,8 +38,29 @@
}

// static
void AutoUpdater::SetFeedURL(const std::string& feed,
const HeaderMap& requestHeaders) {
void AutoUpdater::SetFeedURL(mate::Arguments* args) {
mate::Dictionary opts;
std::string feed;
HeaderMap requestHeaders;
std::string serverType = "default";
if (args->GetNext(&opts)) {
if (!opts.Get("url", &feed)) {
args->ThrowError("Expected options object to contain a 'url' string property in setFeedUrl call");
return;
}
opts.Get("headers", &requestHeaders);
opts.Get("serverType", &serverType);
if (serverType != "default" && serverType != "json") {
args->ThrowError("Expected serverType to be 'default' or 'json'");
return;
}
} else if (args->GetNext(&feed)) {
args->GetNext(&requestHeaders);
} else {
args->ThrowError("Expected an options object with a 'url' property to be provided");
return;
}

Delegate* delegate = GetDelegate();
if (!delegate)
return;
Expand All @@ -55,7 +80,13 @@

// Initialize the SQRLUpdater.
@try {
g_updater = [[SQRLUpdater alloc] initWithUpdateRequest:urlRequest];
if (serverType == "json") {
NSString* nsAppVersion = base::SysUTF8ToNSString(atom::Browser::Get()->GetVersion());
g_updater = [[SQRLUpdater alloc] initWithUpdateRequest:urlRequest forVersion:nsAppVersion];
} else {
// default
g_updater = [[SQRLUpdater alloc] initWithUpdateRequest:urlRequest];
}
} @catch (NSException* error) {
delegate->OnError(base::SysNSStringToUTF8(error.reason));
return;
Expand Down
9 changes: 6 additions & 3 deletions docs/api/auto-updater.md
Expand Up @@ -88,10 +88,13 @@ On Windows only `releaseName` is available.

The `autoUpdater` object has the following methods:

### `autoUpdater.setFeedURL(url[, requestHeaders])`
### `autoUpdater.setFeedURL(options)`

* `url` String
* `requestHeaders` Object (optional) _macOS_ - HTTP request headers.
* `options` Object
* `url` String
* `headers` Object (optional) _macOS_ - HTTP request headers.
* `serverType` String (optional) _macOS_ - Either `json` or `default`, see the [Squirrel.Mac][squirrel-mac]
README for more information.

Sets the `url` and initialize the auto updater.

Expand Down
14 changes: 13 additions & 1 deletion lib/browser/api/auto-updater/auto-updater-win.js
Expand Up @@ -17,7 +17,19 @@ class AutoUpdater extends EventEmitter {
return this.updateURL
}

setFeedURL (updateURL, headers) {
setFeedURL (options) {
let updateURL
if (typeof options === 'object') {
if (typeof options.url === 'string') {
updateURL = options.url
} else {
throw new Error('Expected options object to contain a \'url\' string property in setFeedUrl call')
}
} else if (typeof options === 'string') {
updateURL = options
} else {
throw new Error('Expected an options object with a \'url\' property to be provided')
}
this.updateURL = updateURL
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -12,7 +12,7 @@
"dugite": "^1.45.0",
"electabul": "~0.0.4",
"electron-docs-linter": "^2.3.4",
"electron-typescript-definitions": "^1.3.0",
"electron-typescript-definitions": "1.3.1",
"github": "^9.2.0",
"husky": "^0.14.3",
"minimist": "^1.2.0",
Expand Down
2 changes: 1 addition & 1 deletion script/update-external-binaries.py
Expand Up @@ -8,7 +8,7 @@
from lib.util import safe_mkdir, rm_rf, extract_zip, tempdir, download


VERSION = 'v1.2.2'
VERSION = 'v1.3.0'
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
FRAMEWORKS_URL = 'http://github.com/electron/electron-frameworks/releases' \
'/download/' + VERSION
Expand Down
91 changes: 75 additions & 16 deletions spec/api-auto-updater-spec.js
Expand Up @@ -29,8 +29,65 @@ describe('autoUpdater module', function () {
})
})

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') {
// FIXME(alexeykuzmin): Skip the test.
// this.skip()
return done()
}

const updateURL = 'https://fake-update.electron.io'
autoUpdater.setFeedURL(updateURL)
assert.equal(autoUpdater.getFeedURL(), updateURL)
done()
})
})

describe('setFeedURL', function () {
describe('on Mac or Windows', () => {
const noThrow = (fn) => {
try { fn() } catch (err) {}
}

before(function () {
if (process.platform !== 'win32' && process.platform !== 'darwin') {
this.skip()
}
})

it('sets url successfully using old (url, headers) syntax', () => {
noThrow(() => autoUpdater.setFeedURL('http://electronjs.org', { header: 'val' }))
assert.equal(autoUpdater.getFeedURL(), 'http://electronjs.org')
})

it('throws if no url is provided when using the old style', () => {
assert.throws(
() => autoUpdater.setFeedURL(),
err => err.message.includes('Expected an options object with a \'url\' property to be provided') // eslint-disable-line
)
})

it('sets url successfully using new ({ url }) syntax', () => {
noThrow(() => autoUpdater.setFeedURL({ url: 'http://mymagicurl.local' }))
assert.equal(autoUpdater.getFeedURL(), 'http://mymagicurl.local')
})

it('throws if no url is provided when using the new style', () => {
assert.throws(
() => autoUpdater.setFeedURL({ noUrl: 'lol' }),
err => err.message.includes('Expected options object to contain a \'url\' string property in setFeedUrl call') // eslint-disable-line
)
})
})

describe('on Mac', function () {
const isServerTypeError = (err) => err.message.includes('Expected serverType to be \'default\' or \'json\'')

before(function () {
if (process.platform !== 'darwin') {
this.skip()
Expand All @@ -44,25 +101,27 @@ describe('autoUpdater module', function () {
})
autoUpdater.setFeedURL('')
})
})
})

describe('getFeedURL', function () {
it('returns a falsey value by default', function () {
assert.ok(!autoUpdater.getFeedURL())
})
it('does not throw if default is the serverType', () => {
assert.doesNotThrow(
() => autoUpdater.setFeedURL({ url: '', serverType: 'default' }),
isServerTypeError
)
})

it('correctly fetches the previously set FeedURL', function (done) {
if (process.platform !== 'win32') {
// FIXME(alexeykuzmin): Skip the test.
// this.skip()
return done()
}
it('does not throw if json is the serverType', () => {
assert.doesNotThrow(
() => autoUpdater.setFeedURL({ url: '', serverType: 'default' }),
isServerTypeError
)
})

const updateURL = 'https://fake-update.electron.io'
autoUpdater.setFeedURL(updateURL)
assert.equal(autoUpdater.getFeedURL(), updateURL)
done()
it('does throw if an unknown string is the serverType', () => {
assert.throws(
() => autoUpdater.setFeedURL({ url: '', serverType: 'weow' }),
isServerTypeError
)
})
})
})

Expand Down