From 108980befb7c31508e75857126398cc24cd68725 Mon Sep 17 00:00:00 2001 From: cc <98377878+hicccc77@users.noreply.github.com> Date: Fri, 3 Apr 2026 20:34:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/main.ts | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/electron/main.ts b/electron/main.ts index 980c972..352651d 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -135,17 +135,33 @@ const shouldOfferUpdateForTrack = (latestVersion: string, currentVersion: string return false } +let lastAppliedUpdaterChannel: string | null = null +const resetUpdaterProviderCache = () => { + const updater = autoUpdater as any + // electron-updater 会缓存 provider;切换 channel 后需清理缓存,避免仍请求旧通道 + for (const key of ['clientPromise', '_clientPromise', 'updateInfoAndProvider']) { + if (Object.prototype.hasOwnProperty.call(updater, key)) { + updater[key] = null + } + } +} + const applyAutoUpdateChannel = (reason: 'startup' | 'settings' = 'startup') => { const track = getEffectiveUpdateTrack() const currentTrack = inferUpdateTrackFromVersion(appVersion) const baseUpdateChannel = track === 'stable' ? 'latest' : track - autoUpdater.allowPrerelease = track !== 'stable' - // 只要用户当前选择的目标通道与当前安装版本所属通道不同,就允许跨通道更新(含降级) - autoUpdater.allowDowngrade = track !== currentTrack - autoUpdater.channel = + const nextUpdaterChannel = process.platform === 'win32' && process.arch === 'arm64' ? `${baseUpdateChannel}-arm64` : baseUpdateChannel + if (lastAppliedUpdaterChannel && lastAppliedUpdaterChannel !== nextUpdaterChannel) { + resetUpdaterProviderCache() + } + autoUpdater.allowPrerelease = track !== 'stable' + // 只要用户当前选择的目标通道与当前安装版本所属通道不同,就允许跨通道更新(含降级) + autoUpdater.allowDowngrade = track !== currentTrack + autoUpdater.channel = nextUpdaterChannel + lastAppliedUpdaterChannel = nextUpdaterChannel console.log(`[Update](${reason}) 当前版本 ${appVersion},当前轨道: ${currentTrack},渠道偏好: ${track},更新通道: ${autoUpdater.channel},allowDowngrade=${autoUpdater.allowDowngrade}`) } @@ -1354,6 +1370,8 @@ function registerIpcHandlers() { if (!AUTO_UPDATE_ENABLED) { return { hasUpdate: false } } + // 每次主动检查前重新应用一次通道配置,确保使用最新选择的更新通道。 + applyAutoUpdateChannel('settings') try { const result = await autoUpdater.checkForUpdates() if (result && result.updateInfo) {