From 8dd5a90582893ae9679ef8b13370f9283a16b72e Mon Sep 17 00:00:00 2001 From: jeffvli Date: Sat, 11 Jul 2026 11:48:14 -0700 Subject: [PATCH] fix alpha updater rolling back to previous stable version (#2217) --- src/main/index.ts | 99 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 69 insertions(+), 30 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index 7533c1575..5db8aa367 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -65,16 +65,19 @@ class AppUpdater { console.log('Effective update channel:', effectiveChannel); if (effectiveChannel === 'alpha') { checkAllChannelsAndGetBest().then(({ result, updater: updaterInstance }) => { + if (!result?.isUpdateAvailable) { + return; + } + updaterInstance.autoInstallOnAppQuit = true; updaterInstance.autoRunAppAfterInstall = true; if (isMacOS()) { - if (result?.isUpdateAvailable) { - getMainWindow()?.webContents.send( - 'update-available', - result.updateInfo.version, - ); - } + getMainWindow()?.webContents.send( + 'update-available', + result.updateInfo.version, + ); } else { + updaterInstance.autoDownload = true; updaterInstance.checkForUpdatesAndNotify(); } }); @@ -115,12 +118,7 @@ async function checkAllChannelsAndGetBest(): Promise<{ updater: UpdaterInstance; }> = []; - const alphaUpdater = createAlphaUpdaterInstance(); - alphaUpdater.logger = autoUpdaterLogInterface; - alphaUpdater.channel = ALPHA_UPDATER_CONFIG.channel; - alphaUpdater.allowPrerelease = true; - alphaUpdater.disableDifferentialDownload = true; - alphaUpdater.allowDowngrade = true; + const alphaUpdater = createAlphaUpdaterInstance({ probeOnly: true }); try { console.log('Checking for updates on alpha channel'); @@ -138,17 +136,16 @@ async function checkAllChannelsAndGetBest(): Promise<{ } try { - autoUpdater.setFeedURL(GITHUB_UPDATER_CONFIG); - configureAutoUpdaterForChannel('latest'); + const latestUpdater = createGithubUpdaterInstance('latest', { probeOnly: true }); console.log('Checking for updates on latest channel (GitHub)'); - const latestResult = await autoUpdater.checkForUpdates(); + const latestResult = await latestUpdater.checkForUpdates(); if ( latestResult?.updateInfo?.version && latestResult.isUpdateAvailable && semver.valid(latestResult.updateInfo.version) && semver.gt(latestResult.updateInfo.version, currentVersion) ) { - candidates.push({ channel: 'latest', result: latestResult, updater: autoUpdater }); + candidates.push({ channel: 'latest', result: latestResult, updater: latestUpdater }); } } catch (e) { log.warn('Latest channel check failed', e); @@ -164,6 +161,7 @@ async function checkAllChannelsAndGetBest(): Promise<{ if (best.channel === 'latest') { configureAutoUpdaterForChannel('latest'); + return { result: best.result, updater: autoUpdater }; } return { result: best.result, updater: best.updater }; @@ -190,16 +188,8 @@ function configureAndGetUpdater(): UpdaterInstance { const effectiveChannel = store.get('release_channel') as string; if (effectiveChannel === 'alpha') { - const updater = createAlphaUpdaterInstance(); log.transports.file.level = 'info'; - updater.logger = autoUpdaterLogInterface; - updater.channel = ALPHA_UPDATER_CONFIG.channel; - updater.allowPrerelease = true; - updater.disableDifferentialDownload = true; - updater.allowDowngrade = true; - updater.autoInstallOnAppQuit = true; - updater.autoRunAppAfterInstall = true; - return updater; + return createAlphaUpdaterInstance(); } log.transports.file.level = 'info'; @@ -214,6 +204,7 @@ function configureAndGetUpdater(): UpdaterInstance { autoUpdater.disableDifferentialDownload = true; } else { autoUpdater.channel = 'latest'; + autoUpdater.allowDowngrade = false; autoUpdater.allowPrerelease = false; } @@ -236,20 +227,68 @@ function configureAutoUpdaterForChannel(channel: 'beta' | 'latest'): void { autoUpdater.disableDifferentialDownload = true; } else { autoUpdater.channel = 'latest'; + autoUpdater.allowDowngrade = false; autoUpdater.allowPrerelease = false; } } -function createAlphaUpdaterInstance(): AppImageUpdater | MacUpdater | NsisUpdater { +function createAlphaUpdaterInstance( + options: { probeOnly?: boolean } = {}, +): AppImageUpdater | MacUpdater | NsisUpdater { + const probeOnly = options.probeOnly ?? false; + let updater: AppImageUpdater | MacUpdater | NsisUpdater; + if (isMacOS()) { - return new MacUpdater(ALPHA_UPDATER_CONFIG); + updater = new MacUpdater(ALPHA_UPDATER_CONFIG); + } else if (isLinux()) { + updater = new AppImageUpdater(ALPHA_UPDATER_CONFIG); + } else { + updater = new NsisUpdater(ALPHA_UPDATER_CONFIG); } - if (isLinux()) { - return new AppImageUpdater(ALPHA_UPDATER_CONFIG); + updater.logger = autoUpdaterLogInterface; + updater.channel = ALPHA_UPDATER_CONFIG.channel; + updater.allowPrerelease = true; + updater.disableDifferentialDownload = true; + updater.allowDowngrade = true; + updater.autoDownload = !probeOnly; + updater.autoInstallOnAppQuit = true; + updater.autoRunAppAfterInstall = true; + + return updater; +} + +function createGithubUpdaterInstance( + channel: 'beta' | 'latest', + options: { probeOnly?: boolean } = {}, +): AppImageUpdater | MacUpdater | NsisUpdater { + const probeOnly = options.probeOnly ?? false; + let updater: AppImageUpdater | MacUpdater | NsisUpdater; + + if (isMacOS()) { + updater = new MacUpdater(GITHUB_UPDATER_CONFIG); + } else if (isLinux()) { + updater = new AppImageUpdater(GITHUB_UPDATER_CONFIG); + } else { + updater = new NsisUpdater(GITHUB_UPDATER_CONFIG); } - return new NsisUpdater(ALPHA_UPDATER_CONFIG); + updater.logger = autoUpdaterLogInterface; + updater.autoDownload = !probeOnly; + updater.autoInstallOnAppQuit = true; + updater.autoRunAppAfterInstall = true; + updater.channel = channel; + + if (channel === 'beta') { + updater.allowDowngrade = true; + updater.allowPrerelease = true; + updater.disableDifferentialDownload = true; + } else { + updater.allowDowngrade = false; + updater.allowPrerelease = false; + } + + return updater; } protocol.registerSchemesAsPrivileged([