introduction and about cache
This commit is contained in:
parent
ca33d75f19
commit
8c79f206e6
@ -5,6 +5,8 @@ import MarkdownRender from '../components/MarkdownRender';
|
||||
import {observer} from 'mobx-react-lite';
|
||||
import commonStore from '../stores/commonStore';
|
||||
|
||||
export type AboutContent = { [lang: string]: string }
|
||||
|
||||
export const About: FC = observer(() => {
|
||||
const {t} = useTranslation();
|
||||
const lang: string = commonStore.settings.language;
|
||||
|
@ -17,6 +17,8 @@ import {ConfigSelector} from '../components/ConfigSelector';
|
||||
import MarkdownRender from '../components/MarkdownRender';
|
||||
import commonStore from '../stores/commonStore';
|
||||
|
||||
export type IntroductionContent = { [lang: string]: string }
|
||||
|
||||
type NavCard = {
|
||||
label: string;
|
||||
desc: string;
|
||||
|
@ -14,7 +14,7 @@ export const Languages = {
|
||||
|
||||
export type Language = keyof typeof Languages;
|
||||
|
||||
export type Settings = {
|
||||
export type SettingsType = {
|
||||
language: Language,
|
||||
darkMode: boolean
|
||||
autoUpdatesCheck: boolean
|
||||
|
@ -1,6 +1,6 @@
|
||||
import commonStore from './stores/commonStore';
|
||||
import {ReadJson} from '../wailsjs/go/backend_golang/App';
|
||||
import {checkUpdate, downloadProgramFiles, LocalConfig, refreshModels} from './utils';
|
||||
import {Cache, checkUpdate, downloadProgramFiles, LocalConfig, refreshModels} from './utils';
|
||||
import {getStatus} from './apis';
|
||||
import {EventsOn} from '../wailsjs/runtime';
|
||||
import {defaultModelConfigs} from './pages/Configs';
|
||||
@ -56,5 +56,12 @@ async function initConfig() {
|
||||
}
|
||||
|
||||
async function initCache() {
|
||||
await ReadJson('cache.json').then((cacheData: Cache) => {
|
||||
if (cacheData.introduction)
|
||||
commonStore.setIntroduction(cacheData.introduction);
|
||||
if (cacheData.about)
|
||||
commonStore.setAbout(cacheData.about);
|
||||
}).catch(() => {
|
||||
});
|
||||
await refreshModels(false);
|
||||
}
|
@ -6,7 +6,9 @@ import {defaultModelConfigs, ModelConfig} from '../pages/Configs';
|
||||
import {Conversations} from '../pages/Chat';
|
||||
import {ModelSourceItem} from '../pages/Models';
|
||||
import {DownloadStatus} from '../pages/Downloads';
|
||||
import {Settings} from '../pages/Settings';
|
||||
import {SettingsType} from '../pages/Settings';
|
||||
import {IntroductionContent} from '../pages/Home';
|
||||
import {AboutContent} from '../pages/About';
|
||||
|
||||
export enum ModelStatus {
|
||||
Offline,
|
||||
@ -24,7 +26,7 @@ class CommonStore {
|
||||
modelStatus: ModelStatus = ModelStatus.Offline;
|
||||
|
||||
// home
|
||||
introduction: { [lang: string]: string } = manifest.introduction;
|
||||
introduction: IntroductionContent = manifest.introduction;
|
||||
|
||||
// chat
|
||||
conversations: Conversations = {};
|
||||
@ -42,14 +44,14 @@ class CommonStore {
|
||||
downloadList: DownloadStatus[] = [];
|
||||
|
||||
// settings
|
||||
settings: Settings = {
|
||||
settings: SettingsType = {
|
||||
language: getUserLanguage(),
|
||||
darkMode: !isSystemLightMode(),
|
||||
autoUpdatesCheck: true
|
||||
};
|
||||
|
||||
// about
|
||||
about: { [lang: string]: string } = manifest.about;
|
||||
about: AboutContent = manifest.about;
|
||||
|
||||
getCurrentModelConfig = () => {
|
||||
return this.modelConfigs[this.currentModelConfigIndex];
|
||||
@ -108,7 +110,7 @@ class CommonStore {
|
||||
this.modelSourceList = value;
|
||||
};
|
||||
|
||||
setSettings = (value: Partial<Settings>, saveConfig: boolean = true) => {
|
||||
setSettings = (value: Partial<SettingsType>, saveConfig: boolean = true) => {
|
||||
this.settings = {...this.settings, ...value};
|
||||
|
||||
if (this.settings.darkMode)
|
||||
@ -120,11 +122,11 @@ class CommonStore {
|
||||
saveConfigs();
|
||||
};
|
||||
|
||||
setIntroduction = (value: { [lang: string]: string }) => {
|
||||
setIntroduction = (value: IntroductionContent) => {
|
||||
this.introduction = value;
|
||||
};
|
||||
|
||||
setAbout = (value: { [lang: string]: string }) => {
|
||||
setAbout = (value: AboutContent) => {
|
||||
this.about = value;
|
||||
};
|
||||
|
||||
|
@ -13,32 +13,36 @@ 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, Settings} from '../pages/Settings';
|
||||
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[]
|
||||
introduction: IntroductionContent,
|
||||
about: AboutContent
|
||||
}
|
||||
|
||||
export type LocalConfig = {
|
||||
modelSourceManifestList: string
|
||||
currentModelConfigIndex: number
|
||||
modelConfigs: ModelConfig[]
|
||||
settings: Settings
|
||||
settings: SettingsType
|
||||
}
|
||||
|
||||
export async function refreshBuiltInModels(readCache: boolean = false) {
|
||||
let cache: Cache = {models: []};
|
||||
let cache: { models: ModelSourceItem[] } = {models: []};
|
||||
if (readCache)
|
||||
await ReadJson('cache.json').then((cacheData: Cache) => {
|
||||
cache = cacheData;
|
||||
}).catch(
|
||||
async () => {
|
||||
cache = {models: manifest.models};
|
||||
}
|
||||
);
|
||||
else cache = {models: manifest.models};
|
||||
if (cacheData.models)
|
||||
cache.models = cacheData.models;
|
||||
else cache.models = manifest.models;
|
||||
}).catch(() => {
|
||||
cache.models = manifest.models;
|
||||
});
|
||||
else cache.models = manifest.models;
|
||||
|
||||
commonStore.setModelSourceList(cache.models);
|
||||
await saveCache().catch(() => {
|
||||
@ -46,7 +50,7 @@ export async function refreshBuiltInModels(readCache: boolean = false) {
|
||||
return cache;
|
||||
}
|
||||
|
||||
export async function refreshLocalModels(cache: Cache, filter: boolean = true) {
|
||||
export async function refreshLocalModels(cache: { models: ModelSourceItem[] }, filter: boolean = true) {
|
||||
if (filter)
|
||||
cache.models = cache.models.filter(m => !m.isLocal); //TODO BUG cause local but in manifest files to be removed, so currently cache is disabled
|
||||
|
||||
@ -90,7 +94,7 @@ export async function refreshLocalModels(cache: Cache, filter: boolean = true) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function refreshRemoteModels(cache: Cache) {
|
||||
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()));
|
||||
@ -147,7 +151,9 @@ export const saveConfigs = async () => {
|
||||
|
||||
export const saveCache = async () => {
|
||||
const data: Cache = {
|
||||
models: commonStore.modelSourceList
|
||||
models: commonStore.modelSourceList,
|
||||
introduction: commonStore.introduction,
|
||||
about: commonStore.about
|
||||
};
|
||||
return SaveJson('cache.json', data);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user