Merge pull request #11925 from electron/squirrel-mac-cdn

Update to use Squirrel.Mac that supports CDN releases
This commit is contained in:
Cheng Zhao 2018-02-16 15:28:39 +09:00 committed by GitHub
commit 67fa13d7cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 138 additions and 36 deletions

View file

@ -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() {

View file

@ -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);

View file

@ -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() {

View file

@ -10,6 +10,7 @@
#include "base/macros.h"
#include "build/build_config.h"
#include "native_mate/arguments.h"
namespace base {
class Time;
@ -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();

View file

@ -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 {
@ -34,8 +38,29 @@ std::string AutoUpdater::GetFeedURL() {
}
// 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;
@ -55,7 +80,13 @@ void AutoUpdater::SetFeedURL(const std::string& feed,
// 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;