Merge pull request #11925 from electron/squirrel-mac-cdn
Update to use Squirrel.Mac that supports CDN releases
This commit is contained in:
commit
67fa13d7cf
10 changed files with 138 additions and 36 deletions
|
@ -99,10 +99,8 @@ void AutoUpdater::OnWindowAllClosed() {
|
||||||
QuitAndInstall();
|
QuitAndInstall();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoUpdater::SetFeedURL(const std::string& url, mate::Arguments* args) {
|
void AutoUpdater::SetFeedURL(mate::Arguments* args) {
|
||||||
auto_updater::AutoUpdater::HeaderMap headers;
|
auto_updater::AutoUpdater::SetFeedURL(args);
|
||||||
args->GetNext(&headers);
|
|
||||||
auto_updater::AutoUpdater::SetFeedURL(url, headers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoUpdater::QuitAndInstall() {
|
void AutoUpdater::QuitAndInstall() {
|
||||||
|
|
|
@ -47,7 +47,7 @@ class AutoUpdater : public mate::EventEmitter<AutoUpdater>,
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string GetFeedURL();
|
std::string GetFeedURL();
|
||||||
void SetFeedURL(const std::string& url, mate::Arguments* args);
|
void SetFeedURL(mate::Arguments* args);
|
||||||
void QuitAndInstall();
|
void QuitAndInstall();
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(AutoUpdater);
|
DISALLOW_COPY_AND_ASSIGN(AutoUpdater);
|
||||||
|
|
|
@ -21,8 +21,7 @@ std::string AutoUpdater::GetFeedURL() {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoUpdater::SetFeedURL(const std::string& url,
|
void AutoUpdater::SetFeedURL(mate::Arguments* args) {
|
||||||
const HeaderMap& requestHeaders) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoUpdater::CheckForUpdates() {
|
void AutoUpdater::CheckForUpdates() {
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include "base/macros.h"
|
#include "base/macros.h"
|
||||||
#include "build/build_config.h"
|
#include "build/build_config.h"
|
||||||
|
#include "native_mate/arguments.h"
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
class Time;
|
class Time;
|
||||||
|
@ -53,8 +54,7 @@ class AutoUpdater {
|
||||||
static void SetDelegate(Delegate* delegate);
|
static void SetDelegate(Delegate* delegate);
|
||||||
|
|
||||||
static std::string GetFeedURL();
|
static std::string GetFeedURL();
|
||||||
static void SetFeedURL(const std::string& url,
|
static void SetFeedURL(mate::Arguments* args);
|
||||||
const HeaderMap& requestHeaders);
|
|
||||||
static void CheckForUpdates();
|
static void CheckForUpdates();
|
||||||
static void QuitAndInstall();
|
static void QuitAndInstall();
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,13 @@
|
||||||
#import <ReactiveCocoa/NSObject+RACPropertySubscribing.h>
|
#import <ReactiveCocoa/NSObject+RACPropertySubscribing.h>
|
||||||
#import <Squirrel/Squirrel.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/bind.h"
|
||||||
#include "base/time/time.h"
|
#include "base/time/time.h"
|
||||||
#include "base/strings/sys_string_conversions.h"
|
#include "base/strings/sys_string_conversions.h"
|
||||||
|
#include "native_mate/converter.h"
|
||||||
|
#include "native_mate/dictionary.h"
|
||||||
|
|
||||||
namespace auto_updater {
|
namespace auto_updater {
|
||||||
|
|
||||||
|
@ -34,8 +38,29 @@ std::string AutoUpdater::GetFeedURL() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void AutoUpdater::SetFeedURL(const std::string& feed,
|
void AutoUpdater::SetFeedURL(mate::Arguments* args) {
|
||||||
const HeaderMap& requestHeaders) {
|
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();
|
Delegate* delegate = GetDelegate();
|
||||||
if (!delegate)
|
if (!delegate)
|
||||||
return;
|
return;
|
||||||
|
@ -55,7 +80,13 @@ void AutoUpdater::SetFeedURL(const std::string& feed,
|
||||||
|
|
||||||
// Initialize the SQRLUpdater.
|
// Initialize the SQRLUpdater.
|
||||||
@try {
|
@try {
|
||||||
|
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];
|
g_updater = [[SQRLUpdater alloc] initWithUpdateRequest:urlRequest];
|
||||||
|
}
|
||||||
} @catch (NSException* error) {
|
} @catch (NSException* error) {
|
||||||
delegate->OnError(base::SysNSStringToUTF8(error.reason));
|
delegate->OnError(base::SysNSStringToUTF8(error.reason));
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -88,10 +88,13 @@ On Windows only `releaseName` is available.
|
||||||
|
|
||||||
The `autoUpdater` object has the following methods:
|
The `autoUpdater` object has the following methods:
|
||||||
|
|
||||||
### `autoUpdater.setFeedURL(url[, requestHeaders])`
|
### `autoUpdater.setFeedURL(options)`
|
||||||
|
|
||||||
|
* `options` Object
|
||||||
* `url` String
|
* `url` String
|
||||||
* `requestHeaders` Object (optional) _macOS_ - HTTP request headers.
|
* `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.
|
Sets the `url` and initialize the auto updater.
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,19 @@ class AutoUpdater extends EventEmitter {
|
||||||
return this.updateURL
|
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
|
this.updateURL = updateURL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
"dugite": "^1.45.0",
|
"dugite": "^1.45.0",
|
||||||
"electabul": "~0.0.4",
|
"electabul": "~0.0.4",
|
||||||
"electron-docs-linter": "^2.3.4",
|
"electron-docs-linter": "^2.3.4",
|
||||||
"electron-typescript-definitions": "^1.3.0",
|
"electron-typescript-definitions": "1.3.1",
|
||||||
"github": "^9.2.0",
|
"github": "^9.2.0",
|
||||||
"husky": "^0.14.3",
|
"husky": "^0.14.3",
|
||||||
"minimist": "^1.2.0",
|
"minimist": "^1.2.0",
|
||||||
|
|
|
@ -8,7 +8,7 @@ from lib.config import get_target_arch
|
||||||
from lib.util import safe_mkdir, rm_rf, extract_zip, tempdir, download
|
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__)))
|
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
||||||
FRAMEWORKS_URL = 'http://github.com/electron/electron-frameworks/releases' \
|
FRAMEWORKS_URL = 'http://github.com/electron/electron-frameworks/releases' \
|
||||||
'/download/' + VERSION
|
'/download/' + VERSION
|
||||||
|
|
|
@ -29,24 +29,6 @@ describe('autoUpdater module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('setFeedURL', function () {
|
|
||||||
describe('on Mac', function () {
|
|
||||||
before(function () {
|
|
||||||
if (process.platform !== 'darwin') {
|
|
||||||
this.skip()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
it('emits an error when the application is unsigned', function (done) {
|
|
||||||
ipcRenderer.once('auto-updater-error', function (event, message) {
|
|
||||||
assert.equal(message, 'Could not get code signature for running application')
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
autoUpdater.setFeedURL('')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('getFeedURL', function () {
|
describe('getFeedURL', function () {
|
||||||
it('returns a falsey value by default', function () {
|
it('returns a falsey value by default', function () {
|
||||||
assert.ok(!autoUpdater.getFeedURL())
|
assert.ok(!autoUpdater.getFeedURL())
|
||||||
|
@ -66,6 +48,83 @@ describe('autoUpdater module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it('emits an error when the application is unsigned', function (done) {
|
||||||
|
ipcRenderer.once('auto-updater-error', function (event, message) {
|
||||||
|
assert.equal(message, 'Could not get code signature for running application')
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
autoUpdater.setFeedURL('')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('does not throw if default is the serverType', () => {
|
||||||
|
assert.doesNotThrow(
|
||||||
|
() => autoUpdater.setFeedURL({ url: '', serverType: 'default' }),
|
||||||
|
isServerTypeError
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('does not throw if json is the serverType', () => {
|
||||||
|
assert.doesNotThrow(
|
||||||
|
() => autoUpdater.setFeedURL({ url: '', serverType: 'default' }),
|
||||||
|
isServerTypeError
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('does throw if an unknown string is the serverType', () => {
|
||||||
|
assert.throws(
|
||||||
|
() => autoUpdater.setFeedURL({ url: '', serverType: 'weow' }),
|
||||||
|
isServerTypeError
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('quitAndInstall', function () {
|
describe('quitAndInstall', function () {
|
||||||
it('emits an error on Windows when no update is available', function (done) {
|
it('emits an error on Windows when no update is available', function (done) {
|
||||||
if (process.platform !== 'win32') {
|
if (process.platform !== 'win32') {
|
||||||
|
|
Loading…
Reference in a new issue