From c22369fff4312e4a8ab98a645a10b9ec22d7021f Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 13 Feb 2018 12:59:24 -0500 Subject: [PATCH] version update alert --- src/locales/en/messages.json | 18 ++++++++++++++++++ src/main.ts | 2 +- src/main/updater.main.ts | 23 +++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index 31ef15e009..a735d7bca2 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -769,5 +769,23 @@ "example": "1.2.3" } } + }, + "updateAvailableDesc": { + "message": "Version $VERSION_NUM$ is ready to install. You must restart Bitwarden to complete the installation. Do you want to restart and update now?", + "placeholders": { + "version_num": { + "content": "$1", + "example": "1.2.3" + } + } + }, + "updateAvailable": { + "message": "Update Available" + }, + "update": { + "message": "Update" + }, + "later": { + "message": "Later" } } diff --git a/src/main.ts b/src/main.ts index 60efc842a2..1c80e2ebe8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -26,7 +26,7 @@ const i18nService = new I18nService('en', './locales/'); const storageService = new DesktopStorageService(); const messagingService = new DesktopMainMessagingService(windowMain, messagingMain); -const updaterMain = new UpdaterMain(); +const updaterMain = new UpdaterMain(windowMain, i18nService); const menuMain = new MenuMain(windowMain, updaterMain, i18nService, messagingService); const powerMonitorMain = new PowerMonitorMain(storageService, messagingService); diff --git a/src/main/updater.main.ts b/src/main/updater.main.ts index abb6b49e49..e5aed96983 100644 --- a/src/main/updater.main.ts +++ b/src/main/updater.main.ts @@ -1,12 +1,35 @@ +import { dialog } from 'electron'; import { autoUpdater } from 'electron-updater'; +import { WindowMain } from './window.main'; + +import { I18nService } from 'jslib/abstractions/i18n.service'; + const UpdaterCheckInitalDelay = 5 * 1000; // 5 seconds const UpdaterCheckInterval = 12 * 60 * 60 * 1000; // 12 hours export class UpdaterMain { + constructor(private windowMain: WindowMain, private i18nService: I18nService) { } + async init() { global.setTimeout(async () => await this.checkForUpdate(), UpdaterCheckInitalDelay); global.setInterval(async () => await this.checkForUpdate(), UpdaterCheckInterval); + + autoUpdater.on('update-downloaded', (info) => { + const result = dialog.showMessageBox(this.windowMain.win, { + type: 'info', + title: this.i18nService.t('updateAvailable'), + message: this.i18nService.t('updateAvailable'), + detail: this.i18nService.t('updateAvailableDesc', info.version), + buttons: [this.i18nService.t('update'), this.i18nService.t('later')], + cancelId: 1, + defaultId: 0, + noLink: true, + }); + if (result === 0) { + autoUpdater.quitAndInstall(); + } + }); } async checkForUpdate() {