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(
'flex p-2 rounded-lg overflow-hidden',
editing ? 'grow' : '',
messageItem.side === 'left' ? 'bg-gray-200' : 'bg-blue-500',
messageItem.side === 'left' ? 'text-gray-600' : 'text-white'
commonStore.settings.darkMode ? 'bg-neutral-800 border-neutral-600 border-[1px]' : (messageItem.side === 'left' ? 'bg-gray-200' : 'bg-blue-500'),
commonStore.settings.darkMode ? 'text-white' : (messageItem.side === 'left' ? 'text-gray-600' : 'text-white')
)}
>
{!editing ?

View File

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

View File

@ -259,13 +259,18 @@ class CommonStore {
setSettings = (value: Partial<SettingsType>, saveConfig: boolean = true) => {
this.settings = { ...this.settings, ...value };
if (this.settings.darkMode)
if (this.settings.darkMode) {
WindowSetDarkTheme();
else
document.documentElement.setAttribute('style', 'color-scheme: dark;');
} else {
WindowSetLightTheme();
document.documentElement.setAttribute('style', 'color-scheme: light;');
}
if (this.settings.language)
if (this.settings.language) {
i18n.changeLanguage(this.settings.language);
document.documentElement.setAttribute('lang', this.settings.language === 'dev' ? 'en' : this.settings.language);
}
if (saveConfig)
saveConfigs();

View File

@ -127,7 +127,11 @@ if (!window.go) {
return ''
})
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) => {
localStorage.setItem(fileName, JSON.stringify(data))