fix: allow users cancel backend download (#6582)

* fix: allow users cancel backend download

* fix: should not redownload on cancel
This commit is contained in:
Louis 2025-09-25 13:19:14 +07:00 committed by GitHub
parent d994bc8f6a
commit 7fe58d6bee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 17 deletions

View File

@ -319,7 +319,10 @@ export async function downloadBackend(
events.emit('onFileDownloadSuccess', { modelId: taskId, downloadType })
} catch (error) {
// Fallback: if GitHub fails, retry once with CDN
if (source === 'github') {
if (
source === 'github' &&
error?.toString() !== 'Error: Download cancelled'
) {
console.warn(`GitHub download failed, falling back to CDN:`, error)
return await downloadBackend(backend, version, 'cdn')
}

View File

@ -400,23 +400,33 @@ export function DownloadManagement() {
className="text-main-view-fg/70 cursor-pointer"
title="Cancel download"
onClick={() => {
serviceHub
.models()
.abortDownload(download.name)
.then(() => {
toast.info(
t('common:toast.downloadCancelled.title'),
{
id: 'cancel-download',
description: t(
'common:toast.downloadCancelled.description'
),
}
// TODO: Consolidate cancellation logic
if (download.id.startsWith('llamacpp')) {
const downloadManager =
window.core.extensionManager.getByName(
'@janhq/download-extension'
)
if (downloadProcesses.length === 0) {
setIsPopoverOpen(false)
}
})
downloadManager.cancelDownload(download.id)
} else {
serviceHub
.models()
.abortDownload(download.name)
.then(() => {
toast.info(
t('common:toast.downloadCancelled.title'),
{
id: 'cancel-download',
description: t(
'common:toast.downloadCancelled.description'
),
}
)
if (downloadProcesses.length === 0) {
setIsPopoverOpen(false)
}
})
}
}}
/>
</div>