From c5b3246154ec61c2335778575f04d284da654f88 Mon Sep 17 00:00:00 2001 From: josc146 Date: Fri, 19 May 2023 23:14:32 +0800 Subject: [PATCH] updates check --- frontend/src/_locales/zh-hans/main.json | 1 + frontend/src/pages/Settings.tsx | 5 ++--- frontend/src/startup.ts | 5 ++++- frontend/src/utils/index.ts | 25 +++++++++++++++++++++++++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/frontend/src/_locales/zh-hans/main.json b/frontend/src/_locales/zh-hans/main.json index 01f17f8..89eaf33 100644 --- a/frontend/src/_locales/zh-hans/main.json +++ b/frontend/src/_locales/zh-hans/main.json @@ -43,6 +43,7 @@ "Open Folder": "打开文件夹", "Configs": "配置", "Automatic Updates Check": "自动检查更新", + "Updates Check Error": "检查更新失败", "Introduction": "介绍", "Dark Mode": "深色模式", "Language": "语言", diff --git a/frontend/src/pages/Settings.tsx b/frontend/src/pages/Settings.tsx index 7c08dac..326dfb0 100644 --- a/frontend/src/pages/Settings.tsx +++ b/frontend/src/pages/Settings.tsx @@ -4,9 +4,8 @@ import {Dropdown, Option, Switch} from '@fluentui/react-components'; import {Labeled} from '../components/Labeled'; import commonStore from '../stores/commonStore'; import {observer} from 'mobx-react-lite'; -import {UpdateApp} from '../../wailsjs/go/backend_golang/App'; import {useTranslation} from 'react-i18next'; -import {Language, Languages} from '../utils'; +import {checkUpdate, Language, Languages} from '../utils'; export const Settings: FC = observer(() => { const {t, i18n} = useTranslation(); @@ -48,7 +47,7 @@ export const Settings: FC = observer(() => { autoUpdatesCheck: data.checked }); if (data.checked) - UpdateApp('http://localhost:34115/dist/RWKV-Runner.exe'); //TODO + checkUpdate(); }}/> }/> diff --git a/frontend/src/startup.ts b/frontend/src/startup.ts index eebc578..b516f2c 100644 --- a/frontend/src/startup.ts +++ b/frontend/src/startup.ts @@ -1,6 +1,6 @@ import commonStore, {defaultModelConfigs} from './stores/commonStore'; import {ReadJson} from '../wailsjs/go/backend_golang/App'; -import {downloadProgramFiles, LocalConfig, refreshModels} from './utils'; +import {checkUpdate, downloadProgramFiles, LocalConfig, refreshModels} from './utils'; import {getStatus} from './apis'; export async function startup() { @@ -10,6 +10,9 @@ export async function startup() { initCache(); await initConfig(); + if (commonStore.settings.autoUpdatesCheck) + checkUpdate(); + getStatus(500).then(status => { if (status) commonStore.setModelStatus(status); diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts index 74f713c..ea7519f 100644 --- a/frontend/src/utils/index.ts +++ b/frontend/src/utils/index.ts @@ -1,6 +1,8 @@ import {DownloadFile, FileExists, ListDirFiles, ReadJson, SaveJson} from '../../wailsjs/go/backend_golang/App'; import manifest from '../../../manifest.json'; import commonStore, {ModelConfig, ModelParameters, ModelSourceItem} from '../stores/commonStore'; +import {toast} from 'react-toastify'; +import {t} from 'i18next'; export const Languages = { dev: 'English', // i18n default @@ -175,4 +177,27 @@ export function forceDownloadProgramFiles() { manifest.programFiles.forEach(({url, path}) => { DownloadFile(path, url); }); +} + +export async function checkUpdate() { + let updateUrl = ''; + await fetch('https://api.github.com/repos/josstorer/RWKV-Runner/releases/latest').then((r) => { + if (r.ok) { + r.json().then((data) => { + if (data.tag_name) { + const versionTag = data.tag_name; + if (versionTag.replace('v', '') > manifest.version) + updateUrl = `https://github.com/josStorer/RWKV-Runner/releases/download/${versionTag}/RWKV-Runner_windows_x64.exe`; + } else { + throw new Error('Invalid response.'); + } + }); + } else { + throw new Error('Network response was not ok.'); + } + } + ).catch((e) => { + toast(t('Updates Check Error') + ' - ' + e.message, {type: 'error', position: 'bottom-left'}); + }); + return updateUrl; } \ No newline at end of file