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