mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-27 07:40:05 +08:00
fix(updater): unify install lifecycle across startup and dialog paths
This commit is contained in:
@@ -267,6 +267,9 @@ export function UpdateViewer({ ref }: { ref?: Ref<UpdateViewerRef> }) {
|
||||
})
|
||||
const { downloaded, total } = download
|
||||
|
||||
// Install cannot be cancelled; only the download can.
|
||||
const [installing, setInstalling] = useState(false)
|
||||
|
||||
const progress = total <= 0 ? 0 : Math.min((downloaded / total) * 100, 100)
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
@@ -333,6 +336,8 @@ export function UpdateViewer({ ref }: { ref?: Ref<UpdateViewerRef> }) {
|
||||
...prev,
|
||||
total: prev.total || prev.downloaded,
|
||||
}))
|
||||
} else if (event.event === 'Installing') {
|
||||
setInstalling(true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,6 +371,7 @@ export function UpdateViewer({ ref }: { ref?: Ref<UpdateViewerRef> }) {
|
||||
} finally {
|
||||
setUpdateState(false)
|
||||
setDownload({ downloaded: 0, total: 0 })
|
||||
setInstalling(false)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -419,6 +425,7 @@ export function UpdateViewer({ ref }: { ref?: Ref<UpdateViewerRef> }) {
|
||||
}}
|
||||
okBtn={t('settings.modals.update.actions.update')}
|
||||
cancelBtn={t('shared.actions.cancel')}
|
||||
disableCancel={installing}
|
||||
onClose={() => setOpen(false)}
|
||||
onCancel={() => {
|
||||
if (updateState) {
|
||||
@@ -560,7 +567,7 @@ export function UpdateViewer({ ref }: { ref?: Ref<UpdateViewerRef> }) {
|
||||
</Box>
|
||||
{updateState && (
|
||||
<LinearProgress
|
||||
variant={total > 0 ? 'determinate' : 'indeterminate'}
|
||||
variant={total > 0 && !installing ? 'determinate' : 'indeterminate'}
|
||||
value={progress}
|
||||
sx={{ mt: 1 }}
|
||||
/>
|
||||
|
||||
@@ -260,10 +260,16 @@ export type DnsOverrideOutcome =
|
||||
| { status: 'applied' }
|
||||
| { status: 'confirmation_required'; source: string }
|
||||
|
||||
/** Same wire shape as the updater plugin's JS `DownloadEvent`. */
|
||||
/**
|
||||
* Same wire shape as the updater plugin's JS `DownloadEvent`, plus `Installing` when the
|
||||
* install starts.
|
||||
*/
|
||||
export type DownloadEvent = DownloadEvent_Serialize | DownloadEvent_Deserialize
|
||||
|
||||
/** Same wire shape as the updater plugin's JS `DownloadEvent`. */
|
||||
/**
|
||||
* Same wire shape as the updater plugin's JS `DownloadEvent`, plus `Installing` when the
|
||||
* install starts.
|
||||
*/
|
||||
export type DownloadEvent_Deserialize =
|
||||
| {
|
||||
event: 'Started'
|
||||
@@ -278,8 +284,12 @@ export type DownloadEvent_Deserialize =
|
||||
}
|
||||
}
|
||||
| { event: 'Finished' }
|
||||
| { event: 'Installing' }
|
||||
|
||||
/** Same wire shape as the updater plugin's JS `DownloadEvent`. */
|
||||
/**
|
||||
* Same wire shape as the updater plugin's JS `DownloadEvent`, plus `Installing` when the
|
||||
* install starts.
|
||||
*/
|
||||
export type DownloadEvent_Serialize =
|
||||
| {
|
||||
event: 'Started'
|
||||
@@ -294,6 +304,7 @@ export type DownloadEvent_Serialize =
|
||||
}
|
||||
}
|
||||
| { event: 'Finished' }
|
||||
| { event: 'Installing' }
|
||||
|
||||
/** Operation associated with a pending failure. */
|
||||
export type FailedOperation =
|
||||
|
||||
Reference in New Issue
Block a user