This commit is contained in:
josc146 2023-05-20 14:53:52 +08:00
parent 0f0281dd63
commit 361d7a5619
8 changed files with 25 additions and 14 deletions

View File

@ -102,6 +102,8 @@ func (a *App) AddToDownloadList(path string, url string) {
Downloading: true, Downloading: true,
Done: false, Done: false,
}) })
} else {
a.ContinueDownload(url)
} }
} }

View File

@ -87,5 +87,6 @@
"Whether to use CPU to calculate the last output layer of the neural network with FP32 precision to obtain better quality.": "是否使用cpu以fp32精度计算神经网络的最后一层输出层, 以获得更好的质量", "Whether to use CPU to calculate the last output layer of the neural network with FP32 precision to obtain better quality.": "是否使用cpu以fp32精度计算神经网络的最后一层输出层, 以获得更好的质量",
"Downloads": "下载", "Downloads": "下载",
"Pause": "暂停", "Pause": "暂停",
"Continue": "继续" "Continue": "继续",
"Check": "查看"
} }

View File

@ -203,7 +203,7 @@ export const Configs: FC = observer(() => {
toast(t('Start Converting'), {autoClose: 1000, type: 'info'}); toast(t('Start Converting'), {autoClose: 1000, type: 'info'});
ConvertModel(modelPath, strategy, newModelPath).then(() => { ConvertModel(modelPath, strategy, newModelPath).then(() => {
toast(`${t('Convert Success')} - ${newModelPath}`, {type: 'success'}); toast(`${t('Convert Success')} - ${newModelPath}`, {type: 'success'});
refreshLocalModels({models: commonStore.modelSourceList}); refreshLocalModels({models: commonStore.modelSourceList}, false);
}).catch(e => { }).catch(e => {
toast(`${t('Convert Failed')} - ${e}`, {type: 'error'}); toast(`${t('Convert Failed')} - ${e}`, {type: 'error'});
}); });

View File

@ -1,24 +1,28 @@
import React, {FC} from 'react'; import React, {FC, useEffect} from 'react';
import {useTranslation} from 'react-i18next'; import {useTranslation} from 'react-i18next';
import {Page} from '../components/Page'; import {Page} from '../components/Page';
import {observer} from 'mobx-react-lite'; import {observer} from 'mobx-react-lite';
import commonStore from '../stores/commonStore'; import commonStore from '../stores/commonStore';
import {Divider, Field, ProgressBar} from '@fluentui/react-components'; import {Divider, Field, ProgressBar} from '@fluentui/react-components';
import {bytesToGb, bytesToMb} from '../utils'; import {bytesToGb, bytesToMb, refreshLocalModels} from '../utils';
import {ToolTipButton} from '../components/ToolTipButton'; import {ToolTipButton} from '../components/ToolTipButton';
import {Folder20Regular, Pause20Regular, Play20Regular} from '@fluentui/react-icons'; import {Folder20Regular, Pause20Regular, Play20Regular} from '@fluentui/react-icons';
import {ContinueDownload, OpenFileFolder, PauseDownload} from '../../wailsjs/go/backend_golang/App'; import {ContinueDownload, OpenFileFolder, PauseDownload} from '../../wailsjs/go/backend_golang/App';
export const Downloads: FC = observer(() => { export const Downloads: FC = observer(() => {
const {t} = useTranslation(); const {t} = useTranslation();
const finishedDownloads = commonStore.downloadList.filter((status) => status.done).length;
useEffect(() => {
refreshLocalModels({models: commonStore.modelSourceList}, false);
console.log('finishedDownloads:', finishedDownloads);
}, [finishedDownloads]);
return ( return (
<Page title={t('Downloads')} content={ <Page title={t('Downloads')} content={
<div className="flex flex-col gap-2 overflow-y-auto overflow-x-hidden p-1"> <div className="flex flex-col gap-2 overflow-y-auto overflow-x-hidden p-1">
{commonStore.downloadList.map((status, index) => ( {commonStore.downloadList.map((status, index) => (
<div className="flex flex-col gap-1"> <div className="flex flex-col gap-1" key={index}>
<Field <Field
key={index}
label={`${status.downloading ? (t('Downloading') + ': ') : ''}${status.name}`} label={`${status.downloading ? (t('Downloading') + ': ') : ''}${status.name}`}
validationMessage={`${status.progress.toFixed(2)}% - ${bytesToGb(status.transferred) + 'GB'}/${bytesToGb(status.size) + 'GB'} - ${status.downloading ? bytesToMb(status.speed) : 0}MB/s - ${status.url}`} validationMessage={`${status.progress.toFixed(2)}% - ${bytesToGb(status.transferred) + 'GB'}/${bytesToGb(status.size) + 'GB'} - ${status.downloading ? bytesToMb(status.speed) : 0}MB/s - ${status.url}`}
validationState={status.done ? 'success' : 'none'} validationState={status.done ? 'success' : 'none'}

View File

@ -19,10 +19,10 @@ import commonStore, {ModelSourceItem} from '../stores/commonStore';
import {BrowserOpenURL} from '../../wailsjs/runtime'; import {BrowserOpenURL} from '../../wailsjs/runtime';
import {AddToDownloadList, OpenFileFolder} from '../../wailsjs/go/backend_golang/App'; import {AddToDownloadList, OpenFileFolder} from '../../wailsjs/go/backend_golang/App';
import manifest from '../../../manifest.json'; import manifest from '../../../manifest.json';
import {toast} from 'react-toastify';
import {Page} from '../components/Page'; import {Page} from '../components/Page';
import {bytesToGb, refreshModels, saveConfigs} from '../utils'; import {bytesToGb, refreshModels, saveConfigs, toastWithButton} from '../utils';
import {useTranslation} from 'react-i18next'; import {useTranslation} from 'react-i18next';
import {useNavigate} from 'react-router';
const columns: TableColumnDefinition<ModelSourceItem>[] = [ const columns: TableColumnDefinition<ModelSourceItem>[] = [
createTableColumn<ModelSourceItem>({ createTableColumn<ModelSourceItem>({
@ -113,7 +113,7 @@ const columns: TableColumnDefinition<ModelSourceItem>[] = [
createTableColumn<ModelSourceItem>({ createTableColumn<ModelSourceItem>({
columnId: 'actions', columnId: 'actions',
compare: (a, b) => { compare: (a, b) => {
return a.isDownloading ? 0 : a.isLocal ? -1 : 1; return a.isLocal ? -1 : 1;
}, },
renderHeaderCell: () => { renderHeaderCell: () => {
const {t} = useTranslation(); const {t} = useTranslation();
@ -122,6 +122,7 @@ const columns: TableColumnDefinition<ModelSourceItem>[] = [
}, },
renderCell: (item) => { renderCell: (item) => {
const {t} = useTranslation(); const {t} = useTranslation();
const navigate = useNavigate();
return ( return (
<TableCellLayout> <TableCellLayout>
@ -134,7 +135,10 @@ const columns: TableColumnDefinition<ModelSourceItem>[] = [
} }
{item.downloadUrl && !item.isLocal && {item.downloadUrl && !item.isLocal &&
<ToolTipButton desc={t('Download')} icon={<ArrowDownload20Regular/>} onClick={() => { <ToolTipButton desc={t('Download')} icon={<ArrowDownload20Regular/>} onClick={() => {
toast(`${t('Downloading')} ${item.name}`, {type: 'info'}); toastWithButton(`${t('Downloading')} ${item.name}`, t('Check'), () => {
navigate({pathname: '/downloads'});
},
{autoClose: 3000, position: 'top-center'});
AddToDownloadList(`./${manifest.localModelDir}/${item.name}`, item.downloadUrl!); AddToDownloadList(`./${manifest.localModelDir}/${item.name}`, item.downloadUrl!);
}}/>} }}/>}
{item.url && <ToolTipButton desc={t('Open Url')} icon={<Open20Regular/>} onClick={() => { {item.url && <ToolTipButton desc={t('Open Url')} icon={<Open20Regular/>} onClick={() => {

View File

@ -55,5 +55,5 @@ async function initConfig() {
} }
async function initCache() { async function initCache() {
await refreshModels(true); await refreshModels(false);
} }

View File

@ -19,7 +19,6 @@ export type ModelSourceItem = {
url?: string; url?: string;
downloadUrl?: string; downloadUrl?: string;
isLocal?: boolean; isLocal?: boolean;
isDownloading?: boolean;
lastUpdatedMs?: number; lastUpdatedMs?: number;
}; };

View File

@ -56,8 +56,9 @@ export async function refreshBuiltInModels(readCache: boolean = false) {
return cache; return cache;
} }
export async function refreshLocalModels(cache: Cache) { export async function refreshLocalModels(cache: Cache, filter: boolean = true) {
cache.models = cache.models.filter(m => !m.isLocal); if (filter)
cache.models = cache.models.filter(m => !m.isLocal); //TODO BUG cause local but in manifest files to be removed, so currently cache is disabled
await ListDirFiles(manifest.localModelDir).then((data) => { await ListDirFiles(manifest.localModelDir).then((data) => {
cache.models.push(...data.flatMap(d => { cache.models.push(...data.flatMap(d => {