Merge branch 'MarshallOfSound-master'

This commit is contained in:
Cheng Zhao 2016-04-26 11:15:56 +09:00
commit 570dc7ca9b
2 changed files with 22 additions and 4 deletions

View file

@ -22,6 +22,12 @@ SQRLUpdater* g_updater = nil;
} // namespace } // namespace
namespace {
bool g_update_available = false;
}
// static // static
void AutoUpdater::SetFeedURL(const std::string& feed) { void AutoUpdater::SetFeedURL(const std::string& feed) {
if (g_updater == nil) { if (g_updater == nil) {
@ -69,6 +75,7 @@ void AutoUpdater::CheckForUpdates() {
take:1] take:1]
subscribeNext:^(SQRLDownloadedUpdate *downloadedUpdate) { subscribeNext:^(SQRLDownloadedUpdate *downloadedUpdate) {
if (downloadedUpdate) { if (downloadedUpdate) {
g_update_available = true;
SQRLUpdate* update = downloadedUpdate.update; SQRLUpdate* update = downloadedUpdate.update;
// There is a new update that has been downloaded. // There is a new update that has been downloaded.
delegate->OnUpdateDownloaded( delegate->OnUpdateDownloaded(
@ -77,6 +84,7 @@ void AutoUpdater::CheckForUpdates() {
base::Time::FromDoubleT(update.releaseDate.timeIntervalSince1970), base::Time::FromDoubleT(update.releaseDate.timeIntervalSince1970),
base::SysNSStringToUTF8(update.updateURL.absoluteString)); base::SysNSStringToUTF8(update.updateURL.absoluteString));
} else { } else {
g_update_available = false;
// When the completed event is sent with no update, then we know there // When the completed event is sent with no update, then we know there
// is no update available. // is no update available.
delegate->OnUpdateNotAvailable(); delegate->OnUpdateNotAvailable();
@ -89,11 +97,16 @@ void AutoUpdater::CheckForUpdates() {
} }
void AutoUpdater::QuitAndInstall() { void AutoUpdater::QuitAndInstall() {
[[g_updater relaunchToInstallUpdate] subscribeError:^(NSError* error) {
Delegate* delegate = AutoUpdater::GetDelegate(); Delegate* delegate = AutoUpdater::GetDelegate();
if (g_update_available) {
[[g_updater relaunchToInstallUpdate] subscribeError:^(NSError* error) {
if (delegate) if (delegate)
delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription)); delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription));
}]; }];
} else {
if (delegate)
delegate->OnError("No update available, can't quit and install");
}
} }
} // namespace auto_updater } // namespace auto_updater

View file

@ -12,6 +12,9 @@ function AutoUpdater () {
util.inherits(AutoUpdater, EventEmitter) util.inherits(AutoUpdater, EventEmitter)
AutoUpdater.prototype.quitAndInstall = function () { AutoUpdater.prototype.quitAndInstall = function () {
if (!this.updateAvailable) {
return this.emitError('No update available, can\'t quit and install')
}
squirrelUpdate.processStart() squirrelUpdate.processStart()
return app.quit() return app.quit()
} }
@ -33,8 +36,10 @@ AutoUpdater.prototype.checkForUpdates = function () {
return this.emitError(error) return this.emitError(error)
} }
if (update == null) { if (update == null) {
this.updateAvailable = false
return this.emit('update-not-available') return this.emit('update-not-available')
} }
this.updateAvailable = true
this.emit('update-available') this.emit('update-available')
squirrelUpdate.update(this.updateURL, (error) => { squirrelUpdate.update(this.updateURL, (error) => {
var date, releaseNotes, version var date, releaseNotes, version