add giteeUpdatesSource

This commit is contained in:
josc146 2023-05-22 00:04:18 +08:00
parent b2960052d9
commit c98c32f2f6
4 changed files with 119 additions and 100 deletions

View File

@ -96,5 +96,6 @@
"Install": "安装", "Install": "安装",
"This is the latest version": "已是最新版", "This is the latest version": "已是最新版",
"Use Tsinghua Pip Mirrors": "使用清华大学Pip镜像源", "Use Tsinghua Pip Mirrors": "使用清华大学Pip镜像源",
"Model Config Exception": "模型配置异常" "Model Config Exception": "模型配置异常",
"Use Gitee Updates Source": "使用Gitee更新源"
} }

View File

@ -1,11 +1,11 @@
import React, {FC} from 'react'; import React, { FC } from 'react';
import {Page} from '../components/Page'; import { Page } from '../components/Page';
import {Dropdown, Option, Switch} from '@fluentui/react-components'; import { Dropdown, Option, Switch } from '@fluentui/react-components';
import {Labeled} from '../components/Labeled'; import { Labeled } from '../components/Labeled';
import commonStore from '../stores/commonStore'; import commonStore from '../stores/commonStore';
import {observer} from 'mobx-react-lite'; import { observer } from 'mobx-react-lite';
import {useTranslation} from 'react-i18next'; import { useTranslation } from 'react-i18next';
import {checkUpdate} from '../utils'; import { checkUpdate } from '../utils';
export const Languages = { export const Languages = {
dev: 'English', // i18n default dev: 'English', // i18n default
@ -18,64 +18,76 @@ export type SettingsType = {
language: Language, language: Language,
darkMode: boolean darkMode: boolean
autoUpdatesCheck: boolean autoUpdatesCheck: boolean
giteeUpdatesSource: boolean
cnMirror: boolean cnMirror: boolean
} }
export const Settings: FC = observer(() => { export const Settings: FC = observer(() => {
const {t, i18n} = useTranslation(); const { t, i18n } = useTranslation();
return ( return (
<Page title={t('Settings')} content={ <Page title={t('Settings')} content={
<div className="flex flex-col gap-2 overflow-hidden"> <div className="flex flex-col gap-2 overflow-hidden">
<Labeled label={t('Language')} flex spaceBetween content={ <Labeled label={t('Language')} flex spaceBetween content={
<Dropdown style={{minWidth: 0}} listbox={{style: {minWidth: 0}}} <Dropdown style={{ minWidth: 0 }} listbox={{ style: { minWidth: 0 } }}
value={Languages[commonStore.settings.language]} value={Languages[commonStore.settings.language]}
selectedOptions={[commonStore.settings.language]} selectedOptions={[commonStore.settings.language]}
onOptionSelect={(_, data) => { onOptionSelect={(_, data) => {
if (data.optionValue) { if (data.optionValue) {
const lang = data.optionValue as Language; const lang = data.optionValue as Language;
commonStore.setSettings({ commonStore.setSettings({
language: lang language: lang
}); });
i18n.changeLanguage(lang); i18n.changeLanguage(lang);
} }
}}> }}>
{ {
Object.entries(Languages).map(([langKey, desc]) => Object.entries(Languages).map(([langKey, desc]) =>
<Option key={langKey} value={langKey}>{desc}</Option>) <Option key={langKey} value={langKey}>{desc}</Option>)
} }
</Dropdown> </Dropdown>
}/> } />
<Labeled label={t('Dark Mode')} flex spaceBetween content={ <Labeled label={t('Dark Mode')} flex spaceBetween content={
<Switch checked={commonStore.settings.darkMode} <Switch checked={commonStore.settings.darkMode}
onChange={(e, data) => { onChange={(e, data) => {
commonStore.setSettings({ commonStore.setSettings({
darkMode: data.checked darkMode: data.checked
}); });
}}/> }} />
}/> } />
<Labeled label={t('Automatic Updates Check')} flex spaceBetween content={ <Labeled label={t('Automatic Updates Check')} flex spaceBetween content={
<Switch checked={commonStore.settings.autoUpdatesCheck} <Switch checked={commonStore.settings.autoUpdatesCheck}
onChange={(e, data) => { onChange={(e, data) => {
commonStore.setSettings({ commonStore.setSettings({
autoUpdatesCheck: data.checked autoUpdatesCheck: data.checked
}); });
if (data.checked) if (data.checked)
checkUpdate(true); checkUpdate(true);
}}/> }} />
}/> } />
{
commonStore.settings.language === 'zh' &&
<Labeled label={t('Use Gitee Updates Source')} flex spaceBetween content={
<Switch checked={commonStore.settings.giteeUpdatesSource}
onChange={(e, data) => {
commonStore.setSettings({
giteeUpdatesSource: data.checked
});
}} />
} />
}
{ {
commonStore.settings.language === 'zh' && commonStore.settings.language === 'zh' &&
<Labeled label={t('Use Tsinghua Pip Mirrors')} flex spaceBetween content={ <Labeled label={t('Use Tsinghua Pip Mirrors')} flex spaceBetween content={
<Switch checked={commonStore.settings.cnMirror} <Switch checked={commonStore.settings.cnMirror}
onChange={(e, data) => { onChange={(e, data) => {
commonStore.setSettings({ commonStore.setSettings({
cnMirror: data.checked cnMirror: data.checked
}); });
}}/> }} />
}/> } />
} }
</div> </div>
}/> } />
); );
}); });

View File

@ -1,14 +1,14 @@
import {makeAutoObservable} from 'mobx'; import { makeAutoObservable } from 'mobx';
import {getUserLanguage, isSystemLightMode, saveConfigs} from '../utils'; import { getUserLanguage, isSystemLightMode, saveConfigs } from '../utils';
import {WindowSetDarkTheme, WindowSetLightTheme} from '../../wailsjs/runtime'; import { WindowSetDarkTheme, WindowSetLightTheme } from '../../wailsjs/runtime';
import manifest from '../../../manifest.json'; import manifest from '../../../manifest.json';
import {defaultModelConfigs, ModelConfig} from '../pages/Configs'; import { defaultModelConfigs, ModelConfig } from '../pages/Configs';
import {Conversations} from '../pages/Chat'; import { Conversations } from '../pages/Chat';
import {ModelSourceItem} from '../pages/Models'; import { ModelSourceItem } from '../pages/Models';
import {DownloadStatus} from '../pages/Downloads'; import { DownloadStatus } from '../pages/Downloads';
import {SettingsType} from '../pages/Settings'; import { SettingsType } from '../pages/Settings';
import {IntroductionContent} from '../pages/Home'; import { IntroductionContent } from '../pages/Home';
import {AboutContent} from '../pages/About'; import { AboutContent } from '../pages/About';
import i18n from 'i18next'; import i18n from 'i18next';
export enum ModelStatus { export enum ModelStatus {
@ -50,6 +50,7 @@ class CommonStore {
language: getUserLanguage(), language: getUserLanguage(),
darkMode: !isSystemLightMode(), darkMode: !isSystemLightMode(),
autoUpdatesCheck: true, autoUpdatesCheck: true,
giteeUpdatesSource: getUserLanguage() === 'zh',
cnMirror: getUserLanguage() === 'zh' cnMirror: getUserLanguage() === 'zh'
}; };
@ -114,7 +115,7 @@ class CommonStore {
}; };
setSettings = (value: Partial<SettingsType>, saveConfig: boolean = true) => { setSettings = (value: Partial<SettingsType>, saveConfig: boolean = true) => {
this.settings = {...this.settings, ...value}; this.settings = { ...this.settings, ...value };
if (this.settings.darkMode) if (this.settings.darkMode)
WindowSetDarkTheme(); WindowSetDarkTheme();

View File

@ -10,15 +10,15 @@ import {
} from '../../wailsjs/go/backend_golang/App'; } from '../../wailsjs/go/backend_golang/App';
import manifest from '../../../manifest.json'; import manifest from '../../../manifest.json';
import commonStore from '../stores/commonStore'; import commonStore from '../stores/commonStore';
import {toast} from 'react-toastify'; import { toast } from 'react-toastify';
import {t} from 'i18next'; import { t } from 'i18next';
import {ToastOptions} from 'react-toastify/dist/types'; import { ToastOptions } from 'react-toastify/dist/types';
import {Button} from '@fluentui/react-components'; import { Button } from '@fluentui/react-components';
import {Language, Languages, SettingsType} from '../pages/Settings'; import { Language, Languages, SettingsType } from '../pages/Settings';
import {ModelSourceItem} from '../pages/Models'; import { ModelSourceItem } from '../pages/Models';
import {ModelConfig, ModelParameters} from '../pages/Configs'; import { ModelConfig, ModelParameters } from '../pages/Configs';
import {IntroductionContent} from '../pages/Home'; import { IntroductionContent } from '../pages/Home';
import {AboutContent} from '../pages/About'; import { AboutContent } from '../pages/About';
export type Cache = { export type Cache = {
models: ModelSourceItem[] models: ModelSourceItem[]
@ -35,7 +35,7 @@ export type LocalConfig = {
} }
export async function refreshBuiltInModels(readCache: boolean = false) { export async function refreshBuiltInModels(readCache: boolean = false) {
let cache: { models: ModelSourceItem[] } = {models: []}; let cache: { models: ModelSourceItem[] } = { models: [] };
if (readCache) if (readCache)
await ReadJson('cache.json').then((cacheData: Cache) => { await ReadJson('cache.json').then((cacheData: Cache) => {
if (cacheData.models) if (cacheData.models)
@ -99,7 +99,7 @@ export async function refreshLocalModels(cache: { models: ModelSourceItem[] }, f
export async function refreshRemoteModels(cache: { models: ModelSourceItem[] }) { export async function refreshRemoteModels(cache: { models: ModelSourceItem[] }) {
const manifestUrls = commonStore.modelSourceManifestList.split(/[,;\n]/); const manifestUrls = commonStore.modelSourceManifestList.split(/[,;\n]/);
const requests = manifestUrls.filter(url => url.endsWith('.json')).map( const requests = manifestUrls.filter(url => url.endsWith('.json')).map(
url => fetch(url, {cache: 'no-cache'}).then(r => r.json())); url => fetch(url, { cache: 'no-cache' }).then(r => r.json()));
await Promise.allSettled(requests) await Promise.allSettled(requests)
.then((data: PromiseSettledResult<Cache>[]) => { .then((data: PromiseSettledResult<Cache>[]) => {
@ -175,7 +175,7 @@ export function isSystemLightMode() {
} }
export function downloadProgramFiles() { export function downloadProgramFiles() {
manifest.programFiles.forEach(({url, path}) => { manifest.programFiles.forEach(({ url, path }) => {
FileExists(path).then(exists => { FileExists(path).then(exists => {
if (!exists) if (!exists)
AddToDownloadList(path, url); AddToDownloadList(path, url);
@ -184,13 +184,13 @@ export function downloadProgramFiles() {
} }
export function forceDownloadProgramFiles() { export function forceDownloadProgramFiles() {
manifest.programFiles.forEach(({url, path}) => { manifest.programFiles.forEach(({ url, path }) => {
DownloadFile(path, url); DownloadFile(path, url);
}); });
} }
export function deletePythonProgramFiles() { export function deletePythonProgramFiles() {
manifest.programFiles.forEach(({path}) => { manifest.programFiles.forEach(({ path }) => {
if (path.endsWith('.py') && !path.includes('get-pip.py')) if (path.endsWith('.py') && !path.includes('get-pip.py'))
DeleteFile(path); DeleteFile(path);
}); });
@ -210,43 +210,48 @@ export function bytesToKb(size: number) {
export async function checkUpdate(notifyEvenLatest: boolean = false) { export async function checkUpdate(notifyEvenLatest: boolean = false) {
let updateUrl = ''; let updateUrl = '';
await fetch('https://api.github.com/repos/josstorer/RWKV-Runner/releases/latest').then((r) => { await fetch(!commonStore.settings.giteeUpdatesSource ?
if (r.ok) { 'https://api.github.com/repos/josstorer/RWKV-Runner/releases/latest' :
r.json().then((data) => { 'https://gitee.com/api/v5/repos/josc146/RWKV-Runner/releases/latest'
if (data.tag_name) { ).then((r) => {
const versionTag = data.tag_name; if (r.ok) {
if (versionTag.replace('v', '') > manifest.version) { r.json().then((data) => {
updateUrl = `https://github.com/josStorer/RWKV-Runner/releases/download/${versionTag}/RWKV-Runner_windows_x64.exe`; if (data.tag_name) {
toastWithButton(t('New Version Available') + ': ' + versionTag, t('Update'), () => { const versionTag = data.tag_name;
deletePythonProgramFiles(); if (versionTag.replace('v', '') > manifest.version) {
setTimeout(() => { updateUrl = !commonStore.settings.giteeUpdatesSource ?
UpdateApp(updateUrl).catch((e) => { `https://github.com/josStorer/RWKV-Runner/releases/download/${versionTag}/RWKV-Runner_windows_x64.exe` :
toast(t('Update Error, Please restart this program') + ' - ' + e.message || e, { `https://gitee.com/josc146/RWKV-Runner/releases/download/${versionTag}/RWKV-Runner_windows_x64.exe`;
type: 'error', toastWithButton(t('New Version Available') + ': ' + versionTag, t('Update'), () => {
position: 'bottom-left', deletePythonProgramFiles();
autoClose: false setTimeout(() => {
}); UpdateApp(updateUrl).catch((e) => {
toast(t('Update Error, Please restart this program') + ' - ' + e.message || e, {
type: 'error',
position: 'bottom-left',
autoClose: false
}); });
}, 500); });
}, { }, 500);
autoClose: false, }, {
position: 'bottom-left' autoClose: false,
}); position: 'bottom-left'
} else { });
if (notifyEvenLatest) {
toast(t('This is the latest version'), {type: 'success', position: 'bottom-left', autoClose: 2000});
}
}
} else { } else {
throw new Error('Invalid response.'); if (notifyEvenLatest) {
toast(t('This is the latest version'), { type: 'success', position: 'bottom-left', autoClose: 2000 });
}
} }
}); } else {
} else { throw new Error('Invalid response.');
throw new Error('Network response was not ok.'); }
} });
} else {
throw new Error('Network response was not ok.');
} }
}
).catch((e) => { ).catch((e) => {
toast(t('Updates Check Error') + ' - ' + e.message || e, {type: 'error', position: 'bottom-left'}); toast(t('Updates Check Error') + ' - ' + e.message || e, { type: 'error', position: 'bottom-left' });
}); });
return updateUrl; return updateUrl;
} }