From c03e16415f4ea8143dcd9b44ace15fee77f649b5 Mon Sep 17 00:00:00 2001 From: josc146 Date: Sat, 20 May 2023 10:31:20 +0800 Subject: [PATCH] toastWithButton --- frontend/src/_locales/zh-hans/main.json | 4 ++- frontend/src/utils/{index.ts => index.tsx} | 31 ++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) rename frontend/src/utils/{index.ts => index.tsx} (87%) diff --git a/frontend/src/_locales/zh-hans/main.json b/frontend/src/_locales/zh-hans/main.json index 89eaf33..a090ce9 100644 --- a/frontend/src/_locales/zh-hans/main.json +++ b/frontend/src/_locales/zh-hans/main.json @@ -71,5 +71,7 @@ "Copy": "复制", "Read Aloud": "朗读", "Hello! I'm RWKV, an open-source and commercially available large language model.": "你好! 我是RWKV, 一个开源可商用的大语言模型.", - "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'部分替换为'" + "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": "更新" } \ No newline at end of file diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.tsx similarity index 87% rename from frontend/src/utils/index.ts rename to frontend/src/utils/index.tsx index ea7519f..f12edce 100644 --- a/frontend/src/utils/index.ts +++ b/frontend/src/utils/index.tsx @@ -1,8 +1,17 @@ -import {DownloadFile, FileExists, ListDirFiles, ReadJson, SaveJson} from '../../wailsjs/go/backend_golang/App'; +import { + DownloadFile, + FileExists, + ListDirFiles, + ReadJson, + SaveJson, + UpdateApp +} 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'; +import {ToastOptions} from 'react-toastify/dist/types'; +import {Button} from '@fluentui/react-components'; export const Languages = { dev: 'English', // i18n default @@ -186,8 +195,12 @@ export async function checkUpdate() { r.json().then((data) => { if (data.tag_name) { const versionTag = data.tag_name; - if (versionTag.replace('v', '') > manifest.version) + 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); + }); + } } else { throw new Error('Invalid response.'); } @@ -200,4 +213,18 @@ export async function checkUpdate() { toast(t('Updates Check Error') + ' - ' + e.message, {type: 'error', position: 'bottom-left'}); }); return updateUrl; +} + +export function toastWithButton(text: string, buttonText: string, onClickButton: () => void, options?: ToastOptions) { + return toast( +
+
{text}
+ +
, + { + autoClose: false, + position: 'bottom-left', + type: 'info', + ...options + }); } \ No newline at end of file