From 6b1ca33671e317a5205841c0ad16e27d236f75a7 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 13 Feb 2018 15:29:27 -0500 Subject: [PATCH] update events --- src/locales/en/messages.json | 3 ++ src/main/updater.main.ts | 67 +++++++++++++++++++----------------- 2 files changed, 38 insertions(+), 32 deletions(-) diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index ee14578616..61c1b73944 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -799,5 +799,8 @@ }, "updateError": { "message": "Update Error" + }, + "unknown": { + "message": "Unknown" } } diff --git a/src/main/updater.main.ts b/src/main/updater.main.ts index 23d4d52a5e..8b33598912 100644 --- a/src/main/updater.main.ts +++ b/src/main/updater.main.ts @@ -23,32 +23,9 @@ export class UpdaterMain { global.setTimeout(async () => await this.checkForUpdate(), UpdaterCheckInitalDelay); global.setInterval(async () => await this.checkForUpdate(), UpdaterCheckInterval); - autoUpdater.on('error', (error) => { - if (this.doingUpdateCheckWithFeedback) { - dialog.showErrorBox(this.i18nService.t('updateError'), - error == null ? "unknown" : (error.stack || error).toString()); - } - - this.reset(); - }); - - autoUpdater.on('update-downloaded', (info) => { - this.updateMenuItem.label = this.i18nService.t('restartToUpdate'); - - const result = dialog.showMessageBox(this.windowMain.win, { - type: 'info', - title: this.i18nService.t('restartToUpdate'), - message: this.i18nService.t('restartToUpdate'), - detail: this.i18nService.t('restartToUpdateDesc', info.version), - buttons: [this.i18nService.t('restart'), this.i18nService.t('later')], - cancelId: 1, - defaultId: 0, - noLink: true, - }); - - if (result === 0) { - autoUpdater.quitAndInstall(); - } + autoUpdater.on('checking-for-update', () => { + this.updateMenuItem.enabled = false; + this.doingUpdateCheck = true; }); autoUpdater.on('update-available', () => { @@ -81,6 +58,34 @@ export class UpdaterMain { this.reset(); }); + + autoUpdater.on('update-downloaded', (info) => { + this.updateMenuItem.label = this.i18nService.t('restartToUpdate'); + + const result = dialog.showMessageBox(this.windowMain.win, { + type: 'info', + title: this.i18nService.t('restartToUpdate'), + message: this.i18nService.t('restartToUpdate'), + detail: this.i18nService.t('restartToUpdateDesc', info.version), + buttons: [this.i18nService.t('restart'), this.i18nService.t('later')], + cancelId: 1, + defaultId: 0, + noLink: true, + }); + + if (result === 0) { + autoUpdater.quitAndInstall(); + } + }); + + autoUpdater.on('error', (error) => { + if (this.doingUpdateCheckWithFeedback) { + dialog.showErrorBox(this.i18nService.t('updateError'), + error == null ? this.i18nService.t('unknown') : (error.stack || error).toString()); + } + + this.reset(); + }); } async checkForUpdate(withFeedback: boolean = false) { @@ -88,18 +93,16 @@ export class UpdaterMain { return; } - this.updateMenuItem.enabled = false; - this.doingUpdateCheck = true; this.doingUpdateCheckWithFeedback = withFeedback; - if (withFeedback) { - await autoUpdater.checkForUpdates(); - } else { - await autoUpdater.checkForUpdatesAndNotify(); + autoUpdater.autoDownload = false; } + + await autoUpdater.checkForUpdates(); } private reset() { + autoUpdater.autoDownload = true; this.updateMenuItem.enabled = true; this.doingUpdateCheck = false; }