fix alpha updater rolling back to previous stable version (#2217)

This commit is contained in:
jeffvli
2026-07-11 11:48:14 -07:00
parent 9f7178a15b
commit 8dd5a90582
+65 -26
View File
@@ -65,16 +65,19 @@ class AppUpdater {
console.log('Effective update channel:', effectiveChannel); console.log('Effective update channel:', effectiveChannel);
if (effectiveChannel === 'alpha') { if (effectiveChannel === 'alpha') {
checkAllChannelsAndGetBest().then(({ result, updater: updaterInstance }) => { checkAllChannelsAndGetBest().then(({ result, updater: updaterInstance }) => {
if (!result?.isUpdateAvailable) {
return;
}
updaterInstance.autoInstallOnAppQuit = true; updaterInstance.autoInstallOnAppQuit = true;
updaterInstance.autoRunAppAfterInstall = true; updaterInstance.autoRunAppAfterInstall = true;
if (isMacOS()) { if (isMacOS()) {
if (result?.isUpdateAvailable) {
getMainWindow()?.webContents.send( getMainWindow()?.webContents.send(
'update-available', 'update-available',
result.updateInfo.version, result.updateInfo.version,
); );
}
} else { } else {
updaterInstance.autoDownload = true;
updaterInstance.checkForUpdatesAndNotify(); updaterInstance.checkForUpdatesAndNotify();
} }
}); });
@@ -115,12 +118,7 @@ async function checkAllChannelsAndGetBest(): Promise<{
updater: UpdaterInstance; updater: UpdaterInstance;
}> = []; }> = [];
const alphaUpdater = createAlphaUpdaterInstance(); const alphaUpdater = createAlphaUpdaterInstance({ probeOnly: true });
alphaUpdater.logger = autoUpdaterLogInterface;
alphaUpdater.channel = ALPHA_UPDATER_CONFIG.channel;
alphaUpdater.allowPrerelease = true;
alphaUpdater.disableDifferentialDownload = true;
alphaUpdater.allowDowngrade = true;
try { try {
console.log('Checking for updates on alpha channel'); console.log('Checking for updates on alpha channel');
@@ -138,17 +136,16 @@ async function checkAllChannelsAndGetBest(): Promise<{
} }
try { try {
autoUpdater.setFeedURL(GITHUB_UPDATER_CONFIG); const latestUpdater = createGithubUpdaterInstance('latest', { probeOnly: true });
configureAutoUpdaterForChannel('latest');
console.log('Checking for updates on latest channel (GitHub)'); console.log('Checking for updates on latest channel (GitHub)');
const latestResult = await autoUpdater.checkForUpdates(); const latestResult = await latestUpdater.checkForUpdates();
if ( if (
latestResult?.updateInfo?.version && latestResult?.updateInfo?.version &&
latestResult.isUpdateAvailable && latestResult.isUpdateAvailable &&
semver.valid(latestResult.updateInfo.version) && semver.valid(latestResult.updateInfo.version) &&
semver.gt(latestResult.updateInfo.version, currentVersion) semver.gt(latestResult.updateInfo.version, currentVersion)
) { ) {
candidates.push({ channel: 'latest', result: latestResult, updater: autoUpdater }); candidates.push({ channel: 'latest', result: latestResult, updater: latestUpdater });
} }
} catch (e) { } catch (e) {
log.warn('Latest channel check failed', e); log.warn('Latest channel check failed', e);
@@ -164,6 +161,7 @@ async function checkAllChannelsAndGetBest(): Promise<{
if (best.channel === 'latest') { if (best.channel === 'latest') {
configureAutoUpdaterForChannel('latest'); configureAutoUpdaterForChannel('latest');
return { result: best.result, updater: autoUpdater };
} }
return { result: best.result, updater: best.updater }; return { result: best.result, updater: best.updater };
@@ -190,16 +188,8 @@ function configureAndGetUpdater(): UpdaterInstance {
const effectiveChannel = store.get('release_channel') as string; const effectiveChannel = store.get('release_channel') as string;
if (effectiveChannel === 'alpha') { if (effectiveChannel === 'alpha') {
const updater = createAlphaUpdaterInstance();
log.transports.file.level = 'info'; log.transports.file.level = 'info';
updater.logger = autoUpdaterLogInterface; return createAlphaUpdaterInstance();
updater.channel = ALPHA_UPDATER_CONFIG.channel;
updater.allowPrerelease = true;
updater.disableDifferentialDownload = true;
updater.allowDowngrade = true;
updater.autoInstallOnAppQuit = true;
updater.autoRunAppAfterInstall = true;
return updater;
} }
log.transports.file.level = 'info'; log.transports.file.level = 'info';
@@ -214,6 +204,7 @@ function configureAndGetUpdater(): UpdaterInstance {
autoUpdater.disableDifferentialDownload = true; autoUpdater.disableDifferentialDownload = true;
} else { } else {
autoUpdater.channel = 'latest'; autoUpdater.channel = 'latest';
autoUpdater.allowDowngrade = false;
autoUpdater.allowPrerelease = false; autoUpdater.allowPrerelease = false;
} }
@@ -236,20 +227,68 @@ function configureAutoUpdaterForChannel(channel: 'beta' | 'latest'): void {
autoUpdater.disableDifferentialDownload = true; autoUpdater.disableDifferentialDownload = true;
} else { } else {
autoUpdater.channel = 'latest'; autoUpdater.channel = 'latest';
autoUpdater.allowDowngrade = false;
autoUpdater.allowPrerelease = 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()) { 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()) { updater.logger = autoUpdaterLogInterface;
return new AppImageUpdater(ALPHA_UPDATER_CONFIG); 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([ protocol.registerSchemesAsPrivileged([