This commit is contained in:
josc146 2023-05-20 15:15:49 +08:00
parent 358705625a
commit 4a5fceb014
4 changed files with 88 additions and 64 deletions

View File

@ -88,5 +88,7 @@
"Downloads": "下载",
"Pause": "暂停",
"Continue": "继续",
"Check": "查看"
"Check": "查看",
"Model file not found": "模型文件不存在",
"Can not find download url": "找不到下载地址"
}

View File

@ -1,16 +1,16 @@
import React, {FC, MouseEventHandler, ReactElement} from 'react';
import commonStore, {ModelStatus} from '../stores/commonStore';
import {StartServer} from '../../wailsjs/go/backend_golang/App';
import {AddToDownloadList, FileExists, StartServer} from '../../wailsjs/go/backend_golang/App';
import {Button} from '@fluentui/react-components';
import {observer} from 'mobx-react-lite';
import {exit, readRoot, switchModel, updateConfig} from '../apis';
import {toast} from 'react-toastify';
import manifest from '../../../manifest.json';
import {getStrategy} from '../utils';
import {getStrategy, toastWithButton} from '../utils';
import {useTranslation} from 'react-i18next';
import {t} from 'i18next';
import {ToolTipButton} from './ToolTipButton';
import {Play16Regular, Stop16Regular} from '@fluentui/react-icons';
import {useNavigate} from 'react-router';
const mainButtonText = {
[ModelStatus.Offline]: 'Run',
@ -26,8 +26,36 @@ const iconModeButtonIcon: { [modelStatus: number]: ReactElement } = {
[ModelStatus.Working]: <Stop16Regular/>
};
export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean }>
= observer(({
onClickRun,
iconMode
}) => {
const {t} = useTranslation();
const navigate = useNavigate();
const onClickMainButton = async () => {
const modelConfig = commonStore.getCurrentModelConfig();
const modelName = modelConfig.modelParameters.modelName;
const modelPath = `./${manifest.localModelDir}/${modelName}`;
if (!await FileExists(modelPath)) {
toastWithButton(t('Model file not found'), t('Download'), () => {
const downloadUrl = commonStore.modelSourceList.find(item => item.name === modelName)?.downloadUrl;
if (downloadUrl) {
toastWithButton(`${t('Downloading')} ${modelName}`, t('Check'), () => {
navigate({pathname: '/downloads'});
},
{autoClose: 3000});
AddToDownloadList(modelPath, downloadUrl);
} else {
toast(t('Can not find download url'), {type: 'error'});
}
});
return;
}
const port = modelConfig.apiParameters.apiPort;
if (commonStore.modelStatus === ModelStatus.Offline) {
@ -83,13 +111,6 @@ const onClickMainButton = async () => {
}
};
export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean }>
= observer(({
onClickRun,
iconMode
}) => {
const {t} = useTranslation();
const onClick = async (e: any) => {
if (commonStore.modelStatus === ModelStatus.Offline)
await onClickRun?.(e);

View File

@ -138,7 +138,7 @@ const columns: TableColumnDefinition<ModelSourceItem>[] = [
toastWithButton(`${t('Downloading')} ${item.name}`, t('Check'), () => {
navigate({pathname: '/downloads'});
},
{autoClose: 3000, position: 'top-center'});
{autoClose: 3000});
AddToDownloadList(`./${manifest.localModelDir}/${item.name}`, item.downloadUrl!);
}}/>}
{item.url && <ToolTipButton desc={t('Open Url')} icon={<Open20Regular/>} onClick={() => {

View File

@ -225,6 +225,9 @@ export async function checkUpdate() {
});
});
}, 500);
}, {
autoClose: false,
position: 'bottom-left'
});
}
} else {
@ -248,8 +251,6 @@ export function toastWithButton(text: string, buttonText: string, onClickButton:
<Button appearance="primary" onClick={onClickButton}>{buttonText}</Button>
</div>,
{
autoClose: false,
position: 'bottom-left',
type: 'info',
...options
});