Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updater: add retry downloadUpdate() #1389

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions main/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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'

Expand Down Expand Up @@ -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)
)
Expand Down