This commit is contained in:
josc146 2023-05-18 22:48:37 +08:00
parent 18db41fd76
commit de7d6b3417
6 changed files with 38 additions and 20 deletions

View File

@ -39,12 +39,9 @@ func (a *App) ReadJson(fileName string) (any, error) {
return data, nil return data, nil
} }
func (a *App) FileExists(fileName string) (bool, error) { func (a *App) FileExists(fileName string) bool {
_, err := os.Stat(fileName) _, err := os.Stat(fileName)
if err == nil { return err == nil
return true, nil
}
return false, err
} }
type FileInfo struct { type FileInfo struct {

View File

@ -59,5 +59,6 @@
"Failed to switch model": "切换模型失败", "Failed to switch model": "切换模型失败",
"Start Converting": "开始转换", "Start Converting": "开始转换",
"Convert Success": "转换成功", "Convert Success": "转换成功",
"Convert Failed": "转换失败" "Convert Failed": "转换失败",
"Model Not Found": "模型不存在"
} }

View File

@ -13,7 +13,7 @@ import {Page} from '../components/Page';
import {useNavigate} from 'react-router'; import {useNavigate} from 'react-router';
import {RunButton} from '../components/RunButton'; import {RunButton} from '../components/RunButton';
import {updateConfig} from '../apis'; import {updateConfig} from '../apis';
import {ConvertModel} from '../../wailsjs/go/backend_golang/App'; import {ConvertModel, FileExists} from '../../wailsjs/go/backend_golang/App';
import manifest from '../../../manifest.json'; import manifest from '../../../manifest.json';
import {getStrategy, refreshLocalModels} from '../utils'; import {getStrategy, refreshLocalModels} from '../utils';
import {useTranslation} from 'react-i18next'; import {useTranslation} from 'react-i18next';
@ -178,8 +178,9 @@ export const Configs: FC = observer(() => {
}}/> }}/>
</div> </div>
}/> }/>
<ToolTipButton text={t('Convert')} desc={t('Convert model with these configs')} onClick={() => { <ToolTipButton text={t('Convert')} desc={t('Convert model with these configs')} onClick={async () => {
const modelPath = `${manifest.localModelDir}/${selectedConfig.modelParameters.modelName}`; const modelPath = `${manifest.localModelDir}/${selectedConfig.modelParameters.modelName}`;
if (await FileExists(modelPath)) {
const strategy = getStrategy(selectedConfig); const strategy = getStrategy(selectedConfig);
const newModelPath = modelPath + '-' + strategy.replace(/[> *+]/g, '-'); const newModelPath = modelPath + '-' + strategy.replace(/[> *+]/g, '-');
toast(t('Start Converting'), {autoClose: 1000, type: 'info'}); toast(t('Start Converting'), {autoClose: 1000, type: 'info'});
@ -189,6 +190,9 @@ export const Configs: FC = observer(() => {
}).catch(e => { }).catch(e => {
toast(`${t('Convert Failed')} - ${e}`, {type: 'error'}); toast(`${t('Convert Failed')} - ${e}`, {type: 'error'});
}); });
} else {
toast(`${t('Model Not Found')} - ${modelPath}`, {type: 'error'});
}
}}/> }}/>
<Labeled label={t('Device')} content={ <Labeled label={t('Device')} content={
<Dropdown style={{minWidth: 0}} className="grow" value={selectedConfig.modelParameters.device} <Dropdown style={{minWidth: 0}} className="grow" value={selectedConfig.modelParameters.device}

View File

@ -1,8 +1,9 @@
import commonStore, {defaultModelConfigs} from './stores/commonStore'; import commonStore, {defaultModelConfigs} from './stores/commonStore';
import {ReadJson} from '../wailsjs/go/backend_golang/App'; import {ReadJson} from '../wailsjs/go/backend_golang/App';
import {LocalConfig, refreshModels} from './utils'; import {downloadProgramFiles, LocalConfig, refreshModels} from './utils';
export async function startup() { export async function startup() {
downloadProgramFiles();
initCache(); initCache();
await initConfig(); await initConfig();
} }

View File

@ -1,4 +1,4 @@
import {ListDirFiles, ReadJson, SaveJson} from '../../wailsjs/go/backend_golang/App'; import {DownloadFile, FileExists, ListDirFiles, ReadJson, SaveJson} from '../../wailsjs/go/backend_golang/App';
import manifest from '../../../manifest.json'; import manifest from '../../../manifest.json';
import commonStore, {ModelConfig, ModelParameters, ModelSourceItem} from '../stores/commonStore'; import commonStore, {ModelConfig, ModelParameters, ModelSourceItem} from '../stores/commonStore';
@ -161,3 +161,18 @@ export function getUserLanguage(): Language {
export function isSystemLightMode() { export function isSystemLightMode() {
return window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches; return window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches;
} }
export function downloadProgramFiles() {
manifest.programFiles.forEach(({url, path}) => {
FileExists(path).then(exists => {
if (!exists)
DownloadFile(path, url);
});
});
}
export function forceDownloadProgramFiles() {
manifest.programFiles.forEach(({url, path}) => {
DownloadFile(path, url);
});
}

View File

@ -3,7 +3,7 @@
"localModelDir": "models", "localModelDir": "models",
"programFiles": [ "programFiles": [
{ {
"url": "https://cdn.jsdelivr.net/gh/josstorer/RWKV-Runner/cmd-helper.bat", "url": "https://raw.githubusercontent.com/josStorer/RWKV-Runner/master/cmd-helper.bat",
"path": "cmd-helper.bat" "path": "cmd-helper.bat"
}, },
{ {