Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion extensions/llamacpp-extension/src/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down
42 changes: 26 additions & 16 deletions web-app/src/containers/DownloadManegement.tsx
Original file line number Diff line number Diff line change
@@ -1,88 +1,88 @@
import {

Check warning on line 1 in web-app/src/containers/DownloadManegement.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

1 line is not covered with tests
Popover,
PopoverContent,
PopoverTrigger,
} from '@/components/ui/popover'
import { Progress } from '@/components/ui/progress'
import { useDownloadStore } from '@/hooks/useDownloadStore'
import { useLeftPanel } from '@/hooks/useLeftPanel'
import { useAppUpdater } from '@/hooks/useAppUpdater'
import { useServiceHub } from '@/hooks/useServiceHub'
import { DownloadEvent, DownloadState, events, AppEvent } from '@janhq/core'
import { IconDownload, IconX } from '@tabler/icons-react'
import { useCallback, useEffect, useMemo, useState } from 'react'
import { toast } from 'sonner'
import { useTranslation } from '@/i18n/react-i18next-compat'

Check warning on line 15 in web-app/src/containers/DownloadManegement.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

6-15 lines are not covered with tests

export function DownloadManagement() {
const { t } = useTranslation()
const { open: isLeftPanelOpen } = useLeftPanel()
const [isPopoverOpen, setIsPopoverOpen] = useState(false)
const serviceHub = useServiceHub()
const {
downloads,
updateProgress,
localDownloadingModels,
removeDownload,
removeLocalDownloadingModel,
} = useDownloadStore()
const { updateState } = useAppUpdater()

Check warning on line 29 in web-app/src/containers/DownloadManegement.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

17-29 lines are not covered with tests

const [appUpdateState, setAppUpdateState] = useState({
isDownloading: false,
downloadProgress: 0,
downloadedBytes: 0,
totalBytes: 0,
})

Check warning on line 36 in web-app/src/containers/DownloadManegement.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

31-36 lines are not covered with tests

useEffect(() => {
setAppUpdateState({
isDownloading: updateState.isDownloading,
downloadProgress: updateState.downloadProgress,
downloadedBytes: updateState.downloadedBytes,
totalBytes: updateState.totalBytes,
})
}, [updateState])

Check warning on line 45 in web-app/src/containers/DownloadManegement.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

38-45 lines are not covered with tests

const onAppUpdateDownloadUpdate = useCallback(
(data: {

Check warning on line 48 in web-app/src/containers/DownloadManegement.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

47-48 lines are not covered with tests
progress?: number
downloadedBytes?: number
totalBytes?: number
}) => {
setAppUpdateState((prev) => ({
...prev,
isDownloading: true,
downloadProgress: data.progress || 0,
downloadedBytes: data.downloadedBytes || 0,
totalBytes: data.totalBytes || 0,
}))
},
[]
)

Check warning on line 62 in web-app/src/containers/DownloadManegement.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

52-62 lines are not covered with tests

const onAppUpdateDownloadSuccess = useCallback(() => {
setAppUpdateState((prev) => ({
...prev,
isDownloading: false,
downloadProgress: 1,
}))
toast.success(t('common:toast.appUpdateDownloaded.title'), {
description: t('common:toast.appUpdateDownloaded.description'),
})
}, [t])

Check warning on line 73 in web-app/src/containers/DownloadManegement.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

64-73 lines are not covered with tests

const onAppUpdateDownloadError = useCallback(() => {
setAppUpdateState((prev) => ({
...prev,
isDownloading: false,
}))
toast.error(t('common:toast.appUpdateDownloadFailed.title'), {
description: t('common:toast.appUpdateDownloadFailed.description'),
})
}, [t])

Check warning on line 83 in web-app/src/containers/DownloadManegement.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

75-83 lines are not covered with tests

const downloadProcesses = useMemo(() => {

Check warning on line 85 in web-app/src/containers/DownloadManegement.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

85 line is not covered with tests
// Get downloads with progress data
const downloadsWithProgress = Object.values(downloads).map((download) => ({
id: download.name,
Expand Down Expand Up @@ -400,23 +400,33 @@
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>
Expand Down
Loading