metacubexd/src/signals/config.ts

140 lines
4.1 KiB
TypeScript
Raw Normal View History

import { makePersisted } from '@solid-primitives/storage'
import { createSignal } from 'solid-js'
2023-09-03 03:56:04 +08:00
import {
CONNECTIONS_TABLE_INITIAL_COLUMN_ORDER,
CONNECTIONS_TABLE_INITIAL_COLUMN_VISIBILITY,
DEFAULT_LOGS_TABLE_MAX_ROWS,
2023-09-03 03:56:04 +08:00
LATENCY_QUALITY_MAP_HTTP,
LATENCY_QUALITY_MAP_HTTPS,
LOG_LEVEL,
PROXIES_ORDERING_TYPE,
2023-09-03 03:56:04 +08:00
PROXIES_PREVIEW_TYPE,
TAILWINDCSS_SIZE,
2023-09-23 20:47:29 +08:00
themes,
2023-09-03 03:56:04 +08:00
} from '~/constants'
import {
ConnectionsTableColumnOrder,
ConnectionsTableColumnVisibility,
} from '~/types'
export const [proxiesPreviewType, setProxiesPreviewType] = makePersisted(
createSignal(PROXIES_PREVIEW_TYPE.Auto),
{ name: 'proxiesPreviewType', storage: localStorage },
)
export const [proxiesOrderingType, setProxiesOrderingType] = makePersisted(
createSignal(PROXIES_ORDERING_TYPE.NATURAL),
{ name: 'proxiesOrderingType', storage: localStorage },
)
export const [hideUnAvailableProxies, setHideUnAvailableProxies] =
makePersisted(createSignal(false), {
name: 'hideUnAvailableProxies',
storage: localStorage,
})
2023-09-03 05:40:39 +08:00
export const [urlForLatencyTest, setUrlForLatencyTest] = makePersisted(
createSignal('https://www.gstatic.com/generate_204'),
2023-09-03 05:40:39 +08:00
{ name: 'urlForLatencyTest', storage: localStorage },
)
export const [autoCloseConns, setAutoCloseConns] = makePersisted(
createSignal(false),
{ name: 'autoCloseConns', storage: localStorage },
)
2023-09-16 23:55:42 +08:00
export const [useTwemoji, setUseTwemoji] = makePersisted(createSignal(true), {
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(
2023-09-23 20:47:29 +08:00
createSignal<(typeof themes)[number]>('lofi'),
2023-09-02 19:06:02 +08:00
{ name: 'favDayTheme', storage: localStorage },
)
export const [favNightTheme, setFavNightTheme] = makePersisted(
2023-09-23 20:47:29 +08:00
createSignal<(typeof themes)[number]>('business'),
2023-09-02 19:06:02 +08:00
{ name: 'favNightTheme', storage: localStorage },
)
2023-09-15 23:43:55 +08:00
export const [connectionsTableSize, setConnectionsTableSize] = makePersisted(
createSignal<TAILWINDCSS_SIZE>(TAILWINDCSS_SIZE.XS),
2023-09-15 23:43:55 +08:00
{ name: 'connectionsTableSize', storage: localStorage },
)
export const [
connectionsTableColumnVisibility,
setConnectionsTableColumnVisibility,
] = makePersisted(
createSignal<ConnectionsTableColumnVisibility>(
CONNECTIONS_TABLE_INITIAL_COLUMN_VISIBILITY,
),
{
name: 'connectionsTableColumnVisibility',
storage: localStorage,
},
)
export const [connectionsTableColumnOrder, setConnectionsTableColumnOrder] =
makePersisted(
createSignal<ConnectionsTableColumnOrder>(
CONNECTIONS_TABLE_INITIAL_COLUMN_ORDER,
),
{
name: 'connectionsTableColumnOrder',
storage: localStorage,
},
)
export const [clientSourceIPTags, setClientSourceIPTags] = makePersisted(
createSignal<{ tagName: string; sourceIP: string }[]>([]),
{
name: 'clientSourceIPTags',
storage: localStorage,
},
)
2023-09-15 23:43:55 +08:00
export const [logsTableSize, setLogsTableSize] = makePersisted(
createSignal<TAILWINDCSS_SIZE>(TAILWINDCSS_SIZE.XS),
{ name: 'logsTableSize', storage: localStorage },
)
export const [logLevel, setLogLevel] = makePersisted(
createSignal<LOG_LEVEL>(LOG_LEVEL.Info),
{ name: 'logLevel', storage: localStorage },
)
export const [logMaxRows, setLogMaxRows] = makePersisted(
createSignal(DEFAULT_LOGS_TABLE_MAX_ROWS),
{
name: 'logMaxRows',
storage: localStorage,
},
)
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
}
export const [latencyTestTimeoutDuration, setLatencyTestTimeoutDuration] =
2023-09-06 11:17:00 +08:00
makePersisted(createSignal(2000), {
name: 'latencyTestTimeoutDuration',
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