improve theme

This commit is contained in:
josc146 2024-03-13 15:36:13 +08:00
parent 3a637a973c
commit cd40261de6
4 changed files with 16 additions and 6 deletions

View File

@ -149,8 +149,8 @@ const ChatMessageItem: FC<{
className={classnames( className={classnames(
'flex p-2 rounded-lg overflow-hidden', 'flex p-2 rounded-lg overflow-hidden',
editing ? 'grow' : '', editing ? 'grow' : '',
messageItem.side === 'left' ? 'bg-gray-200' : 'bg-blue-500', commonStore.settings.darkMode ? 'bg-neutral-800 border-neutral-600 border-[1px]' : (messageItem.side === 'left' ? 'bg-gray-200' : 'bg-blue-500'),
messageItem.side === 'left' ? 'text-gray-600' : 'text-white' commonStore.settings.darkMode ? 'text-white' : (messageItem.side === 'left' ? 'text-gray-600' : 'text-white')
)} )}
> >
{!editing ? {!editing ?

View File

@ -81,6 +81,7 @@ async function initConfig() {
}).catch(() => { }).catch(() => {
commonStore.setModelConfigs(commonStore.platform !== 'darwin' ? defaultModelConfigs : defaultModelConfigsMac, true); commonStore.setModelConfigs(commonStore.platform !== 'darwin' ? defaultModelConfigs : defaultModelConfigsMac, true);
}); });
commonStore.setSettings({}, false); // to activate side effects
} }
async function initCache(initUnfinishedModels: boolean) { async function initCache(initUnfinishedModels: boolean) {

View File

@ -259,13 +259,18 @@ 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();
else document.documentElement.setAttribute('style', 'color-scheme: dark;');
} else {
WindowSetLightTheme(); WindowSetLightTheme();
document.documentElement.setAttribute('style', 'color-scheme: light;');
}
if (this.settings.language) if (this.settings.language) {
i18n.changeLanguage(this.settings.language); i18n.changeLanguage(this.settings.language);
document.documentElement.setAttribute('lang', this.settings.language === 'dev' ? 'en' : this.settings.language);
}
if (saveConfig) if (saveConfig)
saveConfigs(); saveConfigs();

View File

@ -127,7 +127,11 @@ if (!window.go) {
return '' return ''
}) })
defineApp('ReadJson', async (fileName) => { defineApp('ReadJson', async (fileName) => {
return JSON.parse(localStorage.getItem(fileName)) const data = JSON.parse(localStorage.getItem(fileName))
if (data)
return data
else
throw new Error('File not found')
}) })
defineApp('SaveJson', async (fileName, data) => { defineApp('SaveJson', async (fileName, data) => {
localStorage.setItem(fileName, JSON.stringify(data)) localStorage.setItem(fileName, JSON.stringify(data))