import React, { FC, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { Page } from '../components/Page'; import { observer } from 'mobx-react-lite'; import commonStore from '../stores/commonStore'; import { Divider, Field, ProgressBar } from '@fluentui/react-components'; import { bytesToGb, bytesToKb, bytesToMb, refreshLocalModels } from '../utils'; import { ToolTipButton } from '../components/ToolTipButton'; import { Folder20Regular, Pause20Regular, Play20Regular } from '@fluentui/react-icons'; import { ContinueDownload, OpenFileFolder, PauseDownload } from '../../wailsjs/go/backend_golang/App'; export type DownloadStatus = { name: string; path: string; url: string; transferred: number; size: number; speed: number; progress: number; downloading: boolean; done: boolean; } export const Downloads: FC = observer(() => { const { t } = useTranslation(); const finishedModelsLen = commonStore.downloadList.filter((status) => status.done && status.name.endsWith('.pth')).length; useEffect(() => { if (finishedModelsLen > 0) refreshLocalModels({ models: commonStore.modelSourceList }, false); console.log('finishedModelsLen:', finishedModelsLen); }, [finishedModelsLen]); return ( {commonStore.downloadList.slice().reverse().map((status, index) => { const downloadProgress = `${status.progress.toFixed(2)}%`; const downloadSpeed = `${status.downloading ? bytesToMb(status.speed) : '0'}MB/s`; let downloadDetails: string; if (status.size < 1024 * 1024) downloadDetails = `${bytesToKb(status.transferred) + 'KB'}/${bytesToKb(status.size) + 'KB'}`; else if (status.size < 1024 * 1024 * 1024) downloadDetails = `${bytesToMb(status.transferred) + 'MB'}/${bytesToMb(status.size) + 'MB'}`; else downloadDetails = `${bytesToGb(status.transferred) + 'GB'}/${bytesToGb(status.size) + 'GB'}`; return
{!status.done && : } onClick={() => { if (status.downloading) PauseDownload(status.url); else ContinueDownload(status.url); }} />} } onClick={() => { OpenFileFolder(`${commonStore.settings.customModelsPath}/${status.name}`); }} />
; }) } } /> ); });