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

View File

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

View File

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