2023-09-02 15:55:38 +08:00
|
|
|
import { makePersisted } from '@solid-primitives/storage'
|
|
|
|
import { createSignal } from 'solid-js'
|
|
|
|
import { PROXIES_PREVIEW_TYPE } from '~/config/enum'
|
2023-09-02 19:06:02 +08:00
|
|
|
import { setCurTheme } from '~/signals'
|
2023-09-02 15:55:38 +08:00
|
|
|
|
|
|
|
export const [proxiesPreviewType, setProxiesPreviewType] = makePersisted(
|
|
|
|
createSignal(PROXIES_PREVIEW_TYPE.BAR),
|
|
|
|
{ name: 'proxiesPreviewType', storage: localStorage },
|
|
|
|
)
|
|
|
|
export const [urlForDelayTest, setUrlForDelayTest] = makePersisted(
|
|
|
|
createSignal('https://www.gstatic.com/generate_204'),
|
|
|
|
{ name: 'urlForDelayTest', storage: localStorage },
|
|
|
|
)
|
|
|
|
export const [autoCloseConns, setAutoCloseConns] = makePersisted(
|
|
|
|
createSignal(false),
|
|
|
|
{ name: 'autoCloseConns', storage: localStorage },
|
|
|
|
)
|
2023-09-02 19:06:02 +08:00
|
|
|
export const [autoSwitchTheme, setAutoSwitchTheme] = makePersisted(
|
|
|
|
createSignal(false),
|
|
|
|
{ name: 'autoSwitchTheme', storage: localStorage },
|
|
|
|
)
|
|
|
|
export const [favDayTheme, setFavDayTheme] = makePersisted(
|
|
|
|
createSignal('light'),
|
|
|
|
{ name: 'favDayTheme', storage: localStorage },
|
|
|
|
)
|
|
|
|
export const [favNightTheme, setFavNightTheme] = makePersisted(
|
|
|
|
createSignal('night'),
|
|
|
|
{ name: 'favNightTheme', storage: localStorage },
|
|
|
|
)
|
2023-09-02 21:00:20 +08:00
|
|
|
export const [renderInTwoColumn, setRenderInTwoColumn] = makePersisted(
|
|
|
|
createSignal(true),
|
|
|
|
{ name: 'renderInTwoColumn', storage: localStorage },
|
|
|
|
)
|
2023-09-02 19:06:02 +08:00
|
|
|
|
|
|
|
const setTheme = (isDark: boolean) => {
|
|
|
|
if (autoSwitchTheme()) {
|
|
|
|
if (isDark) {
|
|
|
|
setCurTheme(favNightTheme())
|
|
|
|
} else {
|
|
|
|
setCurTheme(favDayTheme())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function applyThemeByMode() {
|
|
|
|
setTheme(window.matchMedia('(prefers-color-scheme: dark)').matches)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function useAutoSwitchTheme() {
|
|
|
|
applyThemeByMode()
|
|
|
|
window
|
|
|
|
.matchMedia('(prefers-color-scheme: dark)')
|
|
|
|
.addEventListener('change', (event) => {
|
|
|
|
setTheme(event.matches)
|
|
|
|
})
|
|
|
|
}
|