Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
94c845d7
Commit
94c845d7
authored
Mar 18, 2024
by
Timothy J. Baek
Browse files
refac
parent
3c01932a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
53 deletions
+33
-53
src/lib/components/chat/Settings/General.svelte
src/lib/components/chat/Settings/General.svelte
+30
-30
src/lib/stores/index.ts
src/lib/stores/index.ts
+1
-21
src/routes/+layout.svelte
src/routes/+layout.svelte
+2
-2
No files found.
src/lib/components/chat/Settings/General.svelte
View file @
94c845d7
...
@@ -4,8 +4,7 @@
...
@@ -4,8 +4,7 @@
import { getLanguages } from '$lib/i18n';
import { getLanguages } from '$lib/i18n';
const dispatch = createEventDispatcher();
const dispatch = createEventDispatcher();
import { models, user } from '$lib/stores';
import { models, user, theme } from '$lib/stores';
import { theme, setTheme } from '../../../stores/index';
const i18n = getContext('i18n');
const i18n = getContext('i18n');
...
@@ -27,27 +26,6 @@
...
@@ -27,27 +26,6 @@
let showAdvanced = false;
let showAdvanced = false;
function applyTheme(theme: string) {
let themeToApply = theme;
if (theme === 'system') {
themeToApply = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
}
themes
.filter((e) => e !== themeToApply)
.forEach((e) => {
e.split(' ').forEach((e) => {
document.documentElement.classList.remove(e);
});
});
themeToApply.split(' ').forEach((e) => {
document.documentElement.classList.add(e);
});
console.log(theme);
}
const toggleNotification = async () => {
const toggleNotification = async () => {
const permission = await Notification.requestPermission();
const permission = await Notification.requestPermission();
...
@@ -115,12 +93,34 @@
...
@@ -115,12 +93,34 @@
options.stop = (settings?.options?.stop ?? []).join(',');
options.stop = (settings?.options?.stop ?? []).join(',');
});
});
function handleThemeChange(newTheme: string) {
const applyTheme = (_theme: string) => {
selectedTheme = newTheme;
let themeToApply = _theme;
setTheme(newTheme);
localStorage.setItem('theme', newTheme);
if (_theme === 'system') {
applyTheme(newTheme);
themeToApply = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
}
}
themes
.filter((e) => e !== themeToApply)
.forEach((e) => {
e.split(' ').forEach((e) => {
document.documentElement.classList.remove(e);
});
});
themeToApply.split(' ').forEach((e) => {
document.documentElement.classList.add(e);
});
console.log(_theme);
};
const themeChangeHandler = (_theme: string) => {
theme.set(_theme);
localStorage.setItem('theme', _theme);
applyTheme(_theme);
};
</script>
</script>
<div class="flex flex-col h-full justify-between text-sm">
<div class="flex flex-col h-full justify-between text-sm">
...
@@ -135,7 +135,7 @@
...
@@ -135,7 +135,7 @@
class=" dark:bg-gray-900 w-fit pr-8 rounded py-2 px-2 text-xs bg-transparent outline-none text-right"
class=" dark:bg-gray-900 w-fit pr-8 rounded py-2 px-2 text-xs bg-transparent outline-none text-right"
bind:value={selectedTheme}
bind:value={selectedTheme}
placeholder="Select a theme"
placeholder="Select a theme"
on:change={() =>
handleT
hemeChange(selectedTheme)}
on:change={() =>
t
hemeChange
Handler
(selectedTheme)}
>
>
<option value="system">⚙️ {$i18n.t('System')}</option>
<option value="system">⚙️ {$i18n.t('System')}</option>
<option value="dark">🌑 {$i18n.t('Dark')}</option>
<option value="dark">🌑 {$i18n.t('Dark')}</option>
...
...
src/lib/stores/index.ts
View file @
94c845d7
...
@@ -7,27 +7,7 @@ export const config = writable(undefined);
...
@@ -7,27 +7,7 @@ export const config = writable(undefined);
export
const
user
=
writable
(
undefined
);
export
const
user
=
writable
(
undefined
);
// Frontend
// Frontend
const
rawThemeSetting
=
writable
(
'
system
'
);
export
const
theme
=
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
chatId
=
writable
(
''
);
export
const
chatId
=
writable
(
''
);
...
...
src/routes/+layout.svelte
View file @
94c845d7
<script>
<script>
import { onMount, tick, setContext } from 'svelte';
import { onMount, tick, setContext } from 'svelte';
import { config, user,
setT
heme, WEBUI_NAME } from '$lib/stores';
import { config, user,
t
heme, WEBUI_NAME } from '$lib/stores';
import { goto } from '$app/navigation';
import { goto } from '$app/navigation';
import { Toaster, toast } from 'svelte-sonner';
import { Toaster, toast } from 'svelte-sonner';
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
let loaded = false;
let loaded = false;
onMount(async () => {
onMount(async () => {
setTheme
(localStorage.theme);
theme.set
(localStorage.theme);
// Check Backend Status
// Check Backend Status
const backendConfig = await getBackendConfig();
const backendConfig = await getBackendConfig();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment