From 18a037bc388cf8295ad5cef560b3426aac4c2cec Mon Sep 17 00:00:00 2001 From: Julian Gruber Date: Thu, 7 Mar 2024 14:23:26 +0100 Subject: [PATCH] updater: add retry `downloadUpdate()` --- main/updater.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/main/updater.js b/main/updater.js index d7ccd6a94..31196137c 100644 --- a/main/updater.js +++ b/main/updater.js @@ -10,6 +10,9 @@ const log = require('electron-log').scope('updater') const { showDialogSync } = require('./dialog') const Store = require('electron-store') +/** @type {import('p-retry').default} */ +let pRetry + // must be global to avoid gc let updateNotification = null @@ -34,7 +37,9 @@ function beforeQuitCleanup () { app.removeAllListeners('window-all-closed') } -function setup (/** @type {import('./typings').Context} */ ctx) { +async function setup (/** @type {import('./typings').Context} */ ctx) { + pRetry = (await import('p-retry')).default + autoUpdater.logger = log autoUpdater.autoDownload = false // we download manually in 'update-available' @@ -134,7 +139,16 @@ function onUpdateAvailable ({ version /*, releaseNotes */ }) { nextVersion = version log.info(`Update to version ${version} is available, downloading..`) - autoUpdater.downloadUpdate().then( + pRetry( + () => autoUpdater.downloadUpdate(), + { + retries: 10, + onFailedAttempt: err => { + console.error(err) + console.error('Failed to download update. Retrying...') + } + } + ).then( _ => log.info('Update downloaded'), err => log.error('Cannot download the update.', err) )