download list

This commit is contained in:
josc146
2023-05-20 13:00:08 +08:00
parent 4f8e35ce62
commit 0761df8df5
8 changed files with 104 additions and 12 deletions

View File

@@ -17,7 +17,7 @@ import {ArrowClockwise20Regular, ArrowDownload20Regular, Folder20Regular, Open20
import {observer} from 'mobx-react-lite';
import commonStore, {ModelSourceItem} from '../stores/commonStore';
import {BrowserOpenURL} from '../../wailsjs/runtime';
import {DownloadFile, OpenFileFolder} from '../../wailsjs/go/backend_golang/App';
import {AddToDownloadList, OpenFileFolder} from '../../wailsjs/go/backend_golang/App';
import manifest from '../../../manifest.json';
import {toast} from 'react-toastify';
import {Page} from '../components/Page';
@@ -135,7 +135,7 @@ const columns: TableColumnDefinition<ModelSourceItem>[] = [
{item.downloadUrl && !item.isLocal &&
<ToolTipButton desc={t('Download')} icon={<ArrowDownload20Regular/>} onClick={() => {
toast(`${t('Downloading')} ${item.name}`, {type: 'info'});
DownloadFile(`./${manifest.localModelDir}/${item.name}`, item.downloadUrl!);
AddToDownloadList(`./${manifest.localModelDir}/${item.name}`, item.downloadUrl!);
}}/>}
{item.url && <ToolTipButton desc={t('Open Url')} icon={<Open20Regular/>} onClick={() => {
BrowserOpenURL(item.url!);

View File

@@ -2,6 +2,7 @@ import commonStore, {defaultModelConfigs} from './stores/commonStore';
import {ReadJson} from '../wailsjs/go/backend_golang/App';
import {checkUpdate, downloadProgramFiles, LocalConfig, refreshModels} from './utils';
import {getStatus} from './apis';
import {EventsOn} from '../wailsjs/runtime';
export async function startup() {
downloadProgramFiles();
@@ -17,6 +18,11 @@ export async function startup() {
if (status)
commonStore.setModelStatus(status);
});
EventsOn('downloadList', (data) => {
if (data)
commonStore.setDownloadList(data);
});
}
async function initRemoteText() {

View File

@@ -52,6 +52,17 @@ export type ModelConfig = {
modelParameters: ModelParameters
}
export type DownloadStatus = {
name: string;
path: string;
url: string;
transferred: number;
size: number;
speed: number;
progress: number;
done: boolean;
}
export const defaultModelConfigs: ModelConfig[] = [
{
name: 'Default',
@@ -91,6 +102,7 @@ class CommonStore {
};
introduction: { [lang: string]: string } = manifest.introduction;
about: { [lang: string]: string } = manifest.about;
downloadList: DownloadStatus[] = [];
getCurrentModelConfig = () => {
return this.modelConfigs[this.currentModelConfigIndex];
@@ -168,6 +180,10 @@ class CommonStore {
setAbout = (value: { [lang: string]: string }) => {
this.about = value;
};
setDownloadList = (value: DownloadStatus[]) => {
this.downloadList = value;
};
}
export default new CommonStore();