2023-09-02 15:55:38 +08:00
|
|
|
import { makePersisted } from '@solid-primitives/storage'
|
|
|
|
import { createSignal } from 'solid-js'
|
2023-09-03 03:56:04 +08:00
|
|
|
import {
|
|
|
|
LATENCY_QUALITY_MAP_HTTP,
|
|
|
|
LATENCY_QUALITY_MAP_HTTPS,
|
2023-09-03 05:35:08 +08:00
|
|
|
PROXIES_ORDERING_TYPE,
|
2023-09-03 03:56:04 +08:00
|
|
|
PROXIES_PREVIEW_TYPE,
|
2023-09-05 20:53:00 +08:00
|
|
|
TAILWINDCSS_SIZE,
|
2023-09-03 03:56:04 +08:00
|
|
|
} from '~/constants'
|
2023-09-12 21:33:16 +08:00
|
|
|
import { setCurTheme } from '~/signals'
|
2023-09-12 20:50:52 +08:00
|
|
|
import { Config } from '~/types'
|
2023-09-02 15:55:38 +08:00
|
|
|
|
|
|
|
export const [proxiesPreviewType, setProxiesPreviewType] = makePersisted(
|
2023-09-03 03:26:29 +08:00
|
|
|
createSignal(PROXIES_PREVIEW_TYPE.Auto),
|
2023-09-02 15:55:38 +08:00
|
|
|
{ name: 'proxiesPreviewType', storage: localStorage },
|
|
|
|
)
|
2023-09-03 05:35:08 +08:00
|
|
|
export const [proxiesOrderingType, setProxiesOrderingType] = makePersisted(
|
|
|
|
createSignal(PROXIES_ORDERING_TYPE.NATURAL),
|
|
|
|
{ name: 'proxiesOrderingType', storage: localStorage },
|
2023-09-03 03:26:29 +08:00
|
|
|
)
|
2023-09-03 05:40:39 +08:00
|
|
|
export const [urlForLatencyTest, setUrlForLatencyTest] = makePersisted(
|
2023-09-02 15:55:38 +08:00
|
|
|
createSignal('https://www.gstatic.com/generate_204'),
|
2023-09-03 05:40:39 +08:00
|
|
|
{ name: 'urlForLatencyTest', storage: localStorage },
|
2023-09-02 15:55:38 +08:00
|
|
|
)
|
|
|
|
export const [autoCloseConns, setAutoCloseConns] = makePersisted(
|
|
|
|
createSignal(false),
|
|
|
|
{ name: 'autoCloseConns', storage: localStorage },
|
|
|
|
)
|
2023-09-05 12:18:32 +08:00
|
|
|
export const [useTwemoji, setTwemoji] = makePersisted(createSignal(true), {
|
2023-09-05 11:40:00 +08:00
|
|
|
name: 'useTwemoji',
|
|
|
|
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-06 16:08:25 +08:00
|
|
|
export const [renderInTwoColumns, setRenderInTwoColumns] = makePersisted(
|
2023-09-02 21:00:20 +08:00
|
|
|
createSignal(true),
|
|
|
|
{ name: 'renderInTwoColumn', storage: localStorage },
|
|
|
|
)
|
2023-09-05 20:53:00 +08:00
|
|
|
export const [tableSize, setTableSize] = makePersisted(
|
|
|
|
createSignal<TAILWINDCSS_SIZE>(TAILWINDCSS_SIZE.XS),
|
|
|
|
{ name: 'tableSize', storage: localStorage },
|
|
|
|
)
|
2023-09-06 03:08:18 +08:00
|
|
|
|
2023-09-06 10:37:25 +08:00
|
|
|
export const tableSizeClassName = (size: TAILWINDCSS_SIZE) => {
|
2023-09-06 03:08:18 +08:00
|
|
|
let className = 'table-xs'
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case TAILWINDCSS_SIZE.XS:
|
|
|
|
className = 'table-xs'
|
|
|
|
break
|
|
|
|
case TAILWINDCSS_SIZE.SM:
|
|
|
|
className = 'table-sm'
|
|
|
|
break
|
|
|
|
case TAILWINDCSS_SIZE.MD:
|
|
|
|
className = 'table-md'
|
|
|
|
break
|
|
|
|
case TAILWINDCSS_SIZE.LG:
|
|
|
|
className = 'table-lg'
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
return className
|
|
|
|
}
|
|
|
|
|
2023-09-06 11:55:12 +08:00
|
|
|
export const [latencyTestTimeoutDuration, setLatencyTestTimeoutDuration] =
|
2023-09-06 11:17:00 +08:00
|
|
|
makePersisted(createSignal(2000), {
|
2023-09-06 11:55:12 +08:00
|
|
|
name: 'latencyTestTimeoutDuration',
|
2023-09-05 22:32:47 +08:00
|
|
|
storage: localStorage,
|
|
|
|
})
|
2023-09-02 19:06:02 +08:00
|
|
|
|
2023-09-03 05:40:39 +08:00
|
|
|
export const isLatencyTestByHttps = () =>
|
|
|
|
urlForLatencyTest().startsWith('https')
|
2023-09-03 03:56:04 +08:00
|
|
|
|
|
|
|
export const latencyQualityMap = () =>
|
|
|
|
isLatencyTestByHttps() ? LATENCY_QUALITY_MAP_HTTPS : LATENCY_QUALITY_MAP_HTTP
|
|
|
|
|
2023-09-02 19:06:02 +08:00
|
|
|
const setTheme = (isDark: boolean) => {
|
|
|
|
if (autoSwitchTheme()) {
|
|
|
|
if (isDark) {
|
|
|
|
setCurTheme(favNightTheme())
|
|
|
|
} else {
|
|
|
|
setCurTheme(favDayTheme())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-03 03:26:29 +08:00
|
|
|
export const applyThemeByMode = () =>
|
2023-09-02 19:06:02 +08:00
|
|
|
setTheme(window.matchMedia('(prefers-color-scheme: dark)').matches)
|
|
|
|
|
2023-09-03 03:26:29 +08:00
|
|
|
export const useAutoSwitchTheme = () => {
|
2023-09-02 19:06:02 +08:00
|
|
|
applyThemeByMode()
|
2023-09-03 03:26:29 +08:00
|
|
|
|
2023-09-02 19:06:02 +08:00
|
|
|
window
|
|
|
|
.matchMedia('(prefers-color-scheme: dark)')
|
2023-09-03 03:26:29 +08:00
|
|
|
.addEventListener('change', (event) => setTheme(event.matches))
|
2023-09-02 19:06:02 +08:00
|
|
|
}
|
2023-09-12 20:50:52 +08:00
|
|
|
|
|
|
|
export const [backendConfig, setBackendConfig] = createSignal<Config>()
|