diff --git a/backend-golang/file.go b/backend-golang/file.go index 7edb128..ed14736 100644 --- a/backend-golang/file.go +++ b/backend-golang/file.go @@ -94,6 +94,14 @@ func (a *App) DownloadFile(path string, url string) error { return nil } +func (a *App) DeleteFile(path string) error { + err := os.Remove(path) + if err != nil { + return err + } + return nil +} + func (a *App) OpenFileFolder(path string) error { absPath, err := filepath.Abs(path) if err != nil { diff --git a/frontend/src/_locales/zh-hans/main.json b/frontend/src/_locales/zh-hans/main.json index 6fc41b5..9dda156 100644 --- a/frontend/src/_locales/zh-hans/main.json +++ b/frontend/src/_locales/zh-hans/main.json @@ -74,5 +74,6 @@ "This tool’s API is compatible with OpenAI API. It can be used with any ChatGPT tool you like. Go to the settings of some ChatGPT tool, replace the 'https://api.openai.com' part in the API address with '": "本工具的API与OpenAI API兼容. 因此可以配合任意你喜欢的ChatGPT工具使用. 打开某个ChatGPT工具的设置, 将API地址中的'https://api.openai.com'部分替换为'", "New Version Available": "新版本可用", "Update": "更新", - "Please click the button in the top right corner to start the model": "请点击右上角的按钮启动模型" + "Please click the button in the top right corner to start the model": "请点击右上角的按钮启动模型", + "Update Error, Please restart this program": "更新出错, 请重启本程序" } \ No newline at end of file diff --git a/frontend/src/utils/index.tsx b/frontend/src/utils/index.tsx index f12edce..93ab70c 100644 --- a/frontend/src/utils/index.tsx +++ b/frontend/src/utils/index.tsx @@ -1,4 +1,5 @@ import { + DeleteFile, DownloadFile, FileExists, ListDirFiles, @@ -188,6 +189,13 @@ export function forceDownloadProgramFiles() { }); } +export function deletePythonProgramFiles() { + manifest.programFiles.forEach(({path}) => { + if (path.endsWith('.py')) + DeleteFile(path); + }); +} + export async function checkUpdate() { let updateUrl = ''; await fetch('https://api.github.com/repos/josstorer/RWKV-Runner/releases/latest').then((r) => { @@ -198,7 +206,16 @@ export async function checkUpdate() { if (versionTag.replace('v', '') > manifest.version) { updateUrl = `https://github.com/josStorer/RWKV-Runner/releases/download/${versionTag}/RWKV-Runner_windows_x64.exe`; toastWithButton(t('New Version Available') + ': ' + versionTag, t('Update'), () => { - UpdateApp(updateUrl); + deletePythonProgramFiles(); + setTimeout(() => { + UpdateApp(updateUrl).catch((e) => { + toast(t('Update Error, Please restart this program') + ' - ' + e.message, { + type: 'error', + position: 'bottom-left', + autoClose: false + }); + }); + }, 500); }); } } else { diff --git a/frontend/wailsjs/go/backend_golang/App.d.ts b/frontend/wailsjs/go/backend_golang/App.d.ts index c322908..e293a67 100644 --- a/frontend/wailsjs/go/backend_golang/App.d.ts +++ b/frontend/wailsjs/go/backend_golang/App.d.ts @@ -4,6 +4,8 @@ import {backend_golang} from '../models'; export function ConvertModel(arg1:string,arg2:string,arg3:string):Promise; +export function DeleteFile(arg1:string):Promise; + export function DownloadFile(arg1:string,arg2:string):Promise; export function FileExists(arg1:string):Promise; diff --git a/frontend/wailsjs/go/backend_golang/App.js b/frontend/wailsjs/go/backend_golang/App.js index 4c45d61..403667f 100644 --- a/frontend/wailsjs/go/backend_golang/App.js +++ b/frontend/wailsjs/go/backend_golang/App.js @@ -6,6 +6,10 @@ export function ConvertModel(arg1, arg2, arg3) { return window['go']['backend_golang']['App']['ConvertModel'](arg1, arg2, arg3); } +export function DeleteFile(arg1) { + return window['go']['backend_golang']['App']['DeleteFile'](arg1); +} + export function DownloadFile(arg1, arg2) { return window['go']['backend_golang']['App']['DownloadFile'](arg1, arg2); }