forked from open-webui/open-webui
refac
This commit is contained in:
parent
3c01932a78
commit
94c845d71f
3 changed files with 33 additions and 53 deletions
|
@ -7,27 +7,7 @@ export const config = writable(undefined);
|
|||
export const user = writable(undefined);
|
||||
|
||||
// Frontend
|
||||
const rawThemeSetting = writable('system');
|
||||
export const theme = derived(rawThemeSetting, ($rawThemeSetting) => {
|
||||
if ($rawThemeSetting === 'system') {
|
||||
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
||||
}
|
||||
return $rawThemeSetting;
|
||||
});
|
||||
|
||||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
|
||||
rawThemeSetting.update((currentTheme) => {
|
||||
if (currentTheme === 'system') {
|
||||
return e.matches ? 'dark' : 'light';
|
||||
}
|
||||
return currentTheme;
|
||||
});
|
||||
});
|
||||
|
||||
export function setTheme(theme) {
|
||||
rawThemeSetting.set(theme);
|
||||
localStorage.setItem('theme', theme);
|
||||
}
|
||||
export const theme = writable('system');
|
||||
|
||||
export const chatId = writable('');
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue