fix(updater): retry slow update downloads from other sources and honour cancel

This commit is contained in:
wonfen
2026-10-06 14:21:09 +08:00
parent c341b9b238
commit dba0f471bf
6 changed files with 196 additions and 42 deletions
+13 -5
View File
@@ -15,7 +15,11 @@ import type { Options as ReactMarkdownOptions } from 'react-markdown'
import { BaseDialog, DialogRef } from '@/components/base'
import { useUpdate } from '@/hooks/use-update'
import { installCachedUpdate, restartApp } from '@/services/cmds'
import {
cancelUpdateDownload,
installUpdate,
restartApp,
} from '@/services/cmds'
import { showNotice } from '@/services/notice-service'
import { useSetUpdateState, useUpdateState } from '@/services/states'
import { openExternalUrl } from '@/utils/open-external-url'
@@ -270,10 +274,9 @@ export function UpdateViewer({ ref }: { ref?: Ref<DialogRef> }) {
}
try {
if (!(await installCachedUpdate(updateInfo.version))) {
await updateInfo.downloadAndInstall(onDownloadEvent)
if (await installUpdate(updateInfo.version, onDownloadEvent)) {
await restartApp()
}
await restartApp()
} catch (err: any) {
showNotice.error(err)
} finally {
@@ -336,7 +339,12 @@ export function UpdateViewer({ ref }: { ref?: Ref<DialogRef> }) {
okBtn={t('settings.modals.update.actions.update')}
cancelBtn={t('shared.actions.cancel')}
onClose={() => setOpen(false)}
onCancel={() => setOpen(false)}
onCancel={() => {
if (updateState) {
void cancelUpdateDownload().catch(showNotice.error)
}
setOpen(false)
}}
onOk={onUpdate}
>
<Box