From 34dee1203416d3083a2328357151aca9d3ca9978 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 26 Mar 2020 15:48:24 +0000 Subject: [PATCH] feat: notify when the update is available License: MIT Signed-off-by: Henrique Dias --- assets/locales/en.json | 1 + src/auto-updater/index.js | 34 ++++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/assets/locales/en.json b/assets/locales/en.json index e92512117..08e22a715 100644 --- a/assets/locales/en.json +++ b/assets/locales/en.json @@ -34,6 +34,7 @@ "clickToInstall": "Click here to restart and install the newer version of IPFS Desktop.", "updateNotAvailable": "Update not available", "runningLatestVersion": "You seem to be running the latest version.", + "updateIsBeingDownloaded": "There is an update available and it is being downloaded.", "couldNotCheckForUpdates": "Could not check for updates", "pleaseCheckInternet": "Please check your Internet connection.", "checkForUpdates": "Check for Updates...", diff --git a/src/auto-updater/index.js b/src/auto-updater/index.js index ac332d578..87dc8df9c 100644 --- a/src/auto-updater/index.js +++ b/src/auto-updater/index.js @@ -6,17 +6,21 @@ import { notify } from '../common/notify' let userRequested = false +function notifyIfRequested (...opts) { + if (userRequested) { + userRequested = false + notify(...opts) + } +} + function setup (ctx) { autoUpdater.autoDownload = false autoUpdater.on('error', (err) => { - if (userRequested) { - userRequested = false - notify({ - title: i18n.t('couldNotCheckForUpdates'), - body: i18n.t('pleaseCheckInternet') - }) - } + notifyIfRequested({ + title: i18n.t('couldNotCheckForUpdates'), + body: i18n.t('pleaseCheckInternet') + }) logger.error(`[updater] ${err.toString()}`) }) @@ -24,6 +28,11 @@ function setup (ctx) { autoUpdater.on('update-available', async () => { logger.info('[updater] update available. download started') + notifyIfRequested({ + title: i18n.t('updateAvailable'), + body: i18n.t('updateIsBeingDownloaded') + }) + try { await autoUpdater.downloadUpdate() } catch (err) { @@ -32,13 +41,10 @@ function setup (ctx) { }) autoUpdater.on('update-not-available', async () => { - if (userRequested) { - userRequested = false - notify({ - title: i18n.t('updateNotAvailable'), - body: i18n.t('runningLatestVersion') - }) - } + notifyIfRequested({ + title: i18n.t('updateNotAvailable'), + body: i18n.t('runningLatestVersion') + }) }) autoUpdater.on('update-downloaded', () => {