2024-06-29 15:24:51 +01:00
|
|
|
import { readable, derived, type Readable } from 'svelte/store';
|
2024-06-29 15:09:17 +01:00
|
|
|
|
|
|
|
import settings from '$lib/settings';
|
|
|
|
import { themeOptions } from '$lib/types/settings';
|
|
|
|
|
2024-06-29 15:24:51 +01:00
|
|
|
type Theme = typeof themeOptions[number];
|
|
|
|
|
|
|
|
let set: (_: Theme) => void;
|
2024-06-29 15:09:17 +01:00
|
|
|
|
|
|
|
const browserPreference = () =>
|
|
|
|
window.matchMedia('(prefers-color-scheme: light)')
|
|
|
|
.matches ? 'light' : 'dark';
|
|
|
|
|
|
|
|
const browserPreferenceReadable = readable(
|
|
|
|
browserPreference(),
|
|
|
|
_set => { set = _set }
|
|
|
|
)
|
|
|
|
|
|
|
|
const matchMedia = window.matchMedia('(prefers-color-scheme: dark)');
|
|
|
|
|
|
|
|
if (matchMedia.addEventListener) {
|
|
|
|
matchMedia.addEventListener('change', () => set(browserPreference()));
|
|
|
|
}
|
|
|
|
|
|
|
|
export default derived(
|
|
|
|
[settings, browserPreferenceReadable],
|
|
|
|
([$settings, $browserPref]) => {
|
|
|
|
if ($settings.appearance.theme !== 'auto') {
|
|
|
|
return $settings.appearance.theme;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $browserPref;
|
|
|
|
},
|
|
|
|
browserPreference()
|
2024-06-29 15:24:51 +01:00
|
|
|
) as Readable<Exclude<Theme, "auto">>
|
2024-06-29 15:09:17 +01:00
|
|
|
|
2024-06-29 15:24:51 +01:00
|
|
|
export const statusBarColors = {
|
|
|
|
"dark": "#000000",
|
|
|
|
"light": "#ffffff"
|
|
|
|
}
|