mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-13 06:02:08 +08:00
fix(updater): retry slow update downloads from other sources and honour cancel
This commit is contained in:
@@ -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
|
||||
|
||||
+13
-3
@@ -1,4 +1,5 @@
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import { Channel, invoke } from '@tauri-apps/api/core'
|
||||
import type { DownloadEvent } from '@tauri-apps/plugin-updater'
|
||||
import dayjs from 'dayjs'
|
||||
|
||||
import type { CommandFailure } from '@/services/notice-service'
|
||||
@@ -269,8 +270,17 @@ export async function restartApp() {
|
||||
return invoke<void>('restart_app')
|
||||
}
|
||||
|
||||
export async function installCachedUpdate(version: string) {
|
||||
return invoke<boolean>('install_cached_update', { version })
|
||||
export async function installUpdate(
|
||||
version: string,
|
||||
onEvent: (event: DownloadEvent) => void,
|
||||
) {
|
||||
const channel = new Channel<DownloadEvent>()
|
||||
channel.onmessage = onEvent
|
||||
return invoke<boolean>('install_update', { version, onEvent: channel })
|
||||
}
|
||||
|
||||
export async function cancelUpdateDownload() {
|
||||
return invoke<void>('cancel_update_download')
|
||||
}
|
||||
|
||||
export async function getAppDir() {
|
||||
|
||||
Reference in New Issue
Block a user