fix(desktop): avoid relaunching without installing updates (#23806)

This commit is contained in:
Brendan Allan 2026-04-24 13:27:36 +08:00 committed by GitHub
parent 3bfe6a1ef6
commit 2e156b8990
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 34 additions and 19 deletions

View file

@ -129,13 +129,12 @@ export const SettingsGeneral: Component = () => {
} }
const actions = const actions =
platform.update && platform.restart platform.updateAndRestart
? [ ? [
{ {
label: language.t("toast.update.action.installRestart"), label: language.t("toast.update.action.installRestart"),
onClick: async () => { onClick: async () => {
await platform.update!() await platform.updateAndRestart!()
await platform.restart!()
}, },
}, },
{ {

View file

@ -49,11 +49,11 @@ export type Platform = {
/** Storage mechanism, defaults to localStorage */ /** Storage mechanism, defaults to localStorage */
storage?: (name?: string) => SyncStorage | AsyncStorage storage?: (name?: string) => SyncStorage | AsyncStorage
/** Check for updates (Tauri only) */ /** Check for a downloadable desktop update */
checkUpdate?(): Promise<UpdateInfo> checkUpdate?(): Promise<UpdateInfo>
/** Install updates (Tauri only) */ /** Install the downloaded update using the platform restart flow */
update?(): Promise<void> updateAndRestart?(): Promise<void>
/** Fetch override */ /** Fetch override */
fetch?: typeof fetch fetch?: typeof fetch

View file

@ -244,10 +244,9 @@ export const ErrorPage: Component<ErrorPageProps> = (props) => {
} }
async function installUpdate() { async function installUpdate() {
if (!platform.update || !platform.restart) return if (!platform.updateAndRestart) return
await platform await platform
.update() .updateAndRestart()
.then(() => platform.restart!())
.then(() => setStore("actionError", undefined)) .then(() => setStore("actionError", undefined))
.catch((err) => { .catch((err) => {
setStore("actionError", formatError(err, language.t)) setStore("actionError", formatError(err, language.t))

View file

@ -366,7 +366,7 @@ export default function Layout(props: ParentProps) {
const useUpdatePolling = () => const useUpdatePolling = () =>
onMount(() => { onMount(() => {
if (!platform.checkUpdate || !platform.update || !platform.restart) return if (!platform.checkUpdate || !platform.updateAndRestart) return
let toastId: number | undefined let toastId: number | undefined
let interval: ReturnType<typeof setInterval> | undefined let interval: ReturnType<typeof setInterval> | undefined
@ -384,8 +384,7 @@ export default function Layout(props: ParentProps) {
{ {
label: language.t("toast.update.action.installRestart"), label: language.t("toast.update.action.installRestart"),
onClick: async () => { onClick: async () => {
await platform.update!() await platform.updateAndRestart!()
await platform.restart!()
}, },
}, },
{ {

View file

@ -337,11 +337,16 @@ function setupAutoUpdater() {
}) })
} }
let updateReady = false let downloadedUpdateVersion: string | undefined
async function checkUpdate() { async function checkUpdate() {
if (!UPDATER_ENABLED) return { updateAvailable: false } if (!UPDATER_ENABLED) return { updateAvailable: false }
updateReady = false if (downloadedUpdateVersion) {
logger.log("returning cached downloaded update", {
version: downloadedUpdateVersion,
})
return { updateAvailable: true, version: downloadedUpdateVersion }
}
logger.log("checking for updates", { logger.log("checking for updates", {
currentVersion: app.getVersion(), currentVersion: app.getVersion(),
channel: autoUpdater.channel, channel: autoUpdater.channel,
@ -367,7 +372,7 @@ async function checkUpdate() {
logger.log("update available", { version }) logger.log("update available", { version })
await autoUpdater.downloadUpdate() await autoUpdater.downloadUpdate()
logger.log("update download completed", { version }) logger.log("update download completed", { version })
updateReady = true downloadedUpdateVersion = version
return { updateAvailable: true, version } return { updateAvailable: true, version }
} catch (error) { } catch (error) {
logger.error("update check failed", error) logger.error("update check failed", error)
@ -376,7 +381,15 @@ async function checkUpdate() {
} }
async function installUpdate() { async function installUpdate() {
if (!updateReady) return if (!downloadedUpdateVersion) {
logger.log("install update skipped", {
reason: "no downloaded update ready",
})
return
}
logger.log("installing downloaded update", {
version: downloadedUpdateVersion,
})
killSidecar() killSidecar()
autoUpdater.quitAndInstall() autoUpdater.quitAndInstall()
} }

View file

@ -170,7 +170,7 @@ const createPlatform = (): Platform => {
return window.api.checkUpdate() return window.api.checkUpdate()
}, },
update: async () => { updateAndRestart: async () => {
const config = await window.api.getWindowConfig().catch(() => ({ updaterEnabled: false })) const config = await window.api.getWindowConfig().catch(() => ({ updaterEnabled: false }))
if (!config.updaterEnabled) return if (!config.updaterEnabled) return
await window.api.installUpdate() await window.api.installUpdate()

View file

@ -297,10 +297,15 @@ const createPlatform = (): Platform => {
return { updateAvailable: true, version: next.version } return { updateAvailable: true, version: next.version }
}, },
update: async () => { updateAndRestart: async () => {
if (!UPDATER_ENABLED || !update) return if (!UPDATER_ENABLED || !update) return
if (ostype() === "windows") await commands.killSidecar().catch(() => undefined) if (ostype() === "windows") await commands.killSidecar().catch(() => undefined)
await update.install().catch(() => undefined) const installed = await update
.install()
.then(() => true)
.catch(() => false)
if (!installed) return
await relaunch()
}, },
restart: async () => { restart: async () => {