mirror of
https://github.com/immich-app/immich.git
synced 2026-03-01 18:19:10 +03:00
fix: ensure theme stays in sync with @immich/ui (#25922)
This commit is contained in:
@@ -2,7 +2,7 @@ import { browser } from '$app/environment';
|
|||||||
import { Theme } from '$lib/constants';
|
import { Theme } from '$lib/constants';
|
||||||
import { eventManager } from '$lib/managers/event-manager.svelte';
|
import { eventManager } from '$lib/managers/event-manager.svelte';
|
||||||
import { PersistedLocalStorage } from '$lib/utils/persisted';
|
import { PersistedLocalStorage } from '$lib/utils/persisted';
|
||||||
import { theme as uiTheme, type Theme as UiTheme } from '@immich/ui';
|
import { onThemeChange as onUiThemeChange, theme as uiTheme, type Theme as UiTheme } from '@immich/ui';
|
||||||
|
|
||||||
export interface ThemeSetting {
|
export interface ThemeSetting {
|
||||||
value: Theme;
|
value: Theme;
|
||||||
@@ -55,15 +55,14 @@ class ThemeManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#onAppInit() {
|
#onAppInit() {
|
||||||
globalThis.matchMedia('(prefers-color-scheme: dark)').addEventListener(
|
const syncSystemTheme = () => {
|
||||||
'change',
|
this.#update(this.theme.system ? 'system' : this.theme.value);
|
||||||
() => {
|
};
|
||||||
if (this.theme.system) {
|
|
||||||
this.#update('system');
|
syncSystemTheme();
|
||||||
}
|
globalThis.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', syncSystemTheme, {
|
||||||
},
|
passive: true,
|
||||||
{ passive: true },
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#update(value: Theme | 'system') {
|
#update(value: Theme | 'system') {
|
||||||
@@ -75,6 +74,7 @@ class ThemeManager {
|
|||||||
this.#theme.current = theme;
|
this.#theme.current = theme;
|
||||||
|
|
||||||
uiTheme.value = theme.value as unknown as UiTheme;
|
uiTheme.value = theme.value as unknown as UiTheme;
|
||||||
|
onUiThemeChange();
|
||||||
|
|
||||||
eventManager.emit('ThemeChange', theme);
|
eventManager.emit('ThemeChange', theme);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user