improve updates

This commit is contained in:
josc146 2023-05-20 10:52:25 +08:00
parent 66a5a903c5
commit 1573c09db0
5 changed files with 34 additions and 2 deletions

View File

@ -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 {

View File

@ -74,5 +74,6 @@
"This tools 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": "更新出错, 请重启本程序"
}

View File

@ -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 {

View File

@ -4,6 +4,8 @@ import {backend_golang} from '../models';
export function ConvertModel(arg1:string,arg2:string,arg3:string):Promise<string>;
export function DeleteFile(arg1:string):Promise<void>;
export function DownloadFile(arg1:string,arg2:string):Promise<void>;
export function FileExists(arg1:string):Promise<boolean>;

View File

@ -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);
}