From 5192e31bac2247887b47c844f348ce0a9744f46e Mon Sep 17 00:00:00 2001 From: josc146 Date: Wed, 24 May 2023 23:05:19 +0800 Subject: [PATCH] improve upgrade process --- frontend/src/components/RunButton.tsx | 8 ++++++-- frontend/src/startup.ts | 7 ++++--- frontend/src/utils/index.tsx | 10 ++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/RunButton.tsx b/frontend/src/components/RunButton.tsx index 0039723..0fbbe7a 100644 --- a/frontend/src/components/RunButton.tsx +++ b/frontend/src/components/RunButton.tsx @@ -144,8 +144,12 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean if (!exist) CopyFile('./backend-python/wkv_cuda_utils/wkv_cuda_model.py', './py310/Lib/site-packages/rwkv/model.py'); }); await CopyFile(customCudaFile, './py310/Lib/site-packages/rwkv/wkv_cuda.pyd').catch(() => { - customCudaFile = ''; - toast(t('Failed to copy custom cuda file'), { type: 'error' }); + FileExists('./py310/Lib/site-packages/rwkv/wkv_cuda.pyd').then((exist) => { + if (!exist) { + customCudaFile = ''; + toast(t('Failed to copy custom cuda file'), { type: 'error' }); + } + }); }); } else toast(t('Supported custom cuda file not found'), { type: 'warning' }); diff --git a/frontend/src/startup.ts b/frontend/src/startup.ts index 08d7aab..a5a3596 100644 --- a/frontend/src/startup.ts +++ b/frontend/src/startup.ts @@ -3,8 +3,8 @@ import { FileExists, ReadJson } from '../wailsjs/go/backend_golang/App'; import { Cache, checkUpdate, + deleteDynamicProgramFiles, downloadProgramFiles, - forceDownloadProgramFiles, LocalConfig, refreshModels, saveCache @@ -17,8 +17,9 @@ export async function startup() { FileExists('cache.json').then((exists) => { if (exists) downloadProgramFiles(); - else - forceDownloadProgramFiles(); + else { + deleteDynamicProgramFiles().then(downloadProgramFiles); + } }); EventsOn('downloadList', (data) => { if (data) diff --git a/frontend/src/utils/index.tsx b/frontend/src/utils/index.tsx index 19980e5..4ae0a29 100644 --- a/frontend/src/utils/index.tsx +++ b/frontend/src/utils/index.tsx @@ -188,6 +188,16 @@ export function forceDownloadProgramFiles() { }); } +export async function deleteDynamicProgramFiles() { + let promises: Promise[] = []; + manifest.programFiles.forEach(({ path }) => { + if ((path.endsWith('.py') && !path.includes('get-pip.py')) || path.includes('requirements') || path.endsWith('.pyd')) + promises.push(DeleteFile(path)); + }); + return await Promise.allSettled(promises).catch(() => { + }); +} + export function bytesToGb(size: number) { return (size / 1024 / 1024 / 1024).toFixed(2); }