2023-09-02 15:55:38 +08:00
|
|
|
import { makePersisted } from '@solid-primitives/storage'
|
2023-09-03 03:56:04 +08:00
|
|
|
import {
|
2023-09-16 23:31:40 +08:00
|
|
|
CONNECTIONS_TABLE_INITIAL_COLUMN_ORDER,
|
|
|
|
CONNECTIONS_TABLE_INITIAL_COLUMN_VISIBILITY,
|
2023-09-22 00:12:52 +08:00
|
|
|
DEFAULT_LOGS_TABLE_MAX_ROWS,
|
2023-09-03 03:56:04 +08:00
|
|
|
LATENCY_QUALITY_MAP_HTTP,
|
|
|
|
LATENCY_QUALITY_MAP_HTTPS,
|
2023-09-14 16:49:39 +08:00
|
|
|
LOG_LEVEL,
|
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-23 20:47:29 +08:00
|
|
|
themes,
|
2023-09-03 03:56:04 +08:00
|
|
|
} from '~/constants'
|
2023-09-16 23:31:40 +08:00
|
|
|
import {
|
|
|
|
ConnectionsTableColumnOrder,
|
|
|
|
ConnectionsTableColumnVisibility,
|
|
|
|
} from '~/types'
|
2023-09-02 15:55:38 +08:00
|
|
|
|
2024-10-11 02:11:20 +08:00
|
|
|
export const proxiesPreviewTypeDefault = PROXIES_PREVIEW_TYPE.Auto
|
|
|
|
|
2023-09-02 15:55:38 +08:00
|
|
|
export const [proxiesPreviewType, setProxiesPreviewType] = makePersisted(
|
2024-10-11 02:11:20 +08:00
|
|
|
createSignal(proxiesPreviewTypeDefault),
|
2023-09-02 15:55:38 +08:00
|
|
|
{ name: 'proxiesPreviewType', storage: localStorage },
|
|
|
|
)
|
2024-10-11 02:11:20 +08:00
|
|
|
|
|
|
|
export const proxiesOrderingTypeDefault = PROXIES_ORDERING_TYPE.NATURAL
|
|
|
|
|
2023-09-03 05:35:08 +08:00
|
|
|
export const [proxiesOrderingType, setProxiesOrderingType] = makePersisted(
|
2024-10-11 02:11:20 +08:00
|
|
|
createSignal(proxiesOrderingTypeDefault),
|
2023-09-03 05:35:08 +08:00
|
|
|
{ name: 'proxiesOrderingType', storage: localStorage },
|
2023-09-03 03:26:29 +08:00
|
|
|
)
|
2023-09-15 23:56:14 +08:00
|
|
|
|
2024-10-11 19:53:31 +08:00
|
|
|
export const renderProxiesInTwoColumnsDefault = true
|
|
|
|
|
|
|
|
export const [renderProxiesInTwoColumns, setRenderProxiesInTwoColumns] =
|
|
|
|
makePersisted(createSignal(renderProxiesInTwoColumnsDefault), {
|
|
|
|
name: 'renderProxiesInTwoColumns',
|
|
|
|
storage: localStorage,
|
|
|
|
})
|
|
|
|
|
2024-10-11 02:11:20 +08:00
|
|
|
export const hideUnAvailableProxiesDefault = false
|
|
|
|
|
2023-09-15 23:56:14 +08:00
|
|
|
export const [hideUnAvailableProxies, setHideUnAvailableProxies] =
|
2024-10-11 02:11:20 +08:00
|
|
|
makePersisted(createSignal(hideUnAvailableProxiesDefault), {
|
2023-09-15 23:56:14 +08:00
|
|
|
name: 'hideUnAvailableProxies',
|
|
|
|
storage: localStorage,
|
|
|
|
})
|
|
|
|
|
2024-10-11 02:11:20 +08:00
|
|
|
export const urlForLatencyTestDefault = 'https://www.gstatic.com/generate_204'
|
|
|
|
|
2023-09-03 05:40:39 +08:00
|
|
|
export const [urlForLatencyTest, setUrlForLatencyTest] = makePersisted(
|
2024-10-11 02:11:20 +08:00
|
|
|
createSignal(urlForLatencyTestDefault),
|
2023-09-03 05:40:39 +08:00
|
|
|
{ name: 'urlForLatencyTest', storage: localStorage },
|
2023-09-02 15:55:38 +08:00
|
|
|
)
|
2023-10-22 13:00:09 +08:00
|
|
|
|
2024-10-11 02:11:20 +08:00
|
|
|
export const autoCloseConnsDefault = false
|
|
|
|
|
2023-09-02 15:55:38 +08:00
|
|
|
export const [autoCloseConns, setAutoCloseConns] = makePersisted(
|
2024-10-11 02:11:20 +08:00
|
|
|
createSignal(autoCloseConnsDefault),
|
2023-09-02 15:55:38 +08:00
|
|
|
{ name: 'autoCloseConns', storage: localStorage },
|
|
|
|
)
|
2024-10-11 02:11:20 +08:00
|
|
|
|
2024-10-11 22:29:36 +08:00
|
|
|
export const useTwemojiDefault = false
|
2024-10-11 02:11:20 +08:00
|
|
|
|
|
|
|
export const [useTwemoji, setUseTwemoji] = makePersisted(
|
|
|
|
createSignal(useTwemojiDefault),
|
|
|
|
{
|
|
|
|
name: 'useTwemoji',
|
|
|
|
storage: localStorage,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
export const autoSwitchThemeDefault = false
|
|
|
|
|
2023-09-02 19:06:02 +08:00
|
|
|
export const [autoSwitchTheme, setAutoSwitchTheme] = makePersisted(
|
2024-10-11 02:11:20 +08:00
|
|
|
createSignal(autoSwitchThemeDefault),
|
2023-09-02 19:06:02 +08:00
|
|
|
{ name: 'autoSwitchTheme', storage: localStorage },
|
|
|
|
)
|
2024-10-11 02:11:20 +08:00
|
|
|
|
|
|
|
export const favDayThemeDefault: (typeof themes)[number] = 'nord'
|
|
|
|
|
2023-09-02 19:06:02 +08:00
|
|
|
export const [favDayTheme, setFavDayTheme] = makePersisted(
|
2024-10-11 02:11:20 +08:00
|
|
|
createSignal<(typeof themes)[number]>(favDayThemeDefault),
|
2023-09-02 19:06:02 +08:00
|
|
|
{ name: 'favDayTheme', storage: localStorage },
|
|
|
|
)
|
2024-10-11 02:11:20 +08:00
|
|
|
|
|
|
|
export const favNightThemeDefault: (typeof themes)[number] = 'sunset'
|
|
|
|
|
2023-09-02 19:06:02 +08:00
|
|
|
export const [favNightTheme, setFavNightTheme] = makePersisted(
|
2024-10-11 02:11:20 +08:00
|
|
|
createSignal<(typeof themes)[number]>(favNightThemeDefault),
|
2023-09-02 19:06:02 +08:00
|
|
|
{ name: 'favNightTheme', storage: localStorage },
|
|
|
|
)
|
2024-10-11 02:11:20 +08:00
|
|
|
|
|
|
|
export const connectionsTableSizeDefault = TAILWINDCSS_SIZE.XS
|
|
|
|
|
2023-09-15 23:43:55 +08:00
|
|
|
export const [connectionsTableSize, setConnectionsTableSize] = makePersisted(
|
2024-10-11 02:11:20 +08:00
|
|
|
createSignal(connectionsTableSizeDefault),
|
2023-09-15 23:43:55 +08:00
|
|
|
{ name: 'connectionsTableSize', storage: localStorage },
|
|
|
|
)
|
2024-10-11 02:11:20 +08:00
|
|
|
|
|
|
|
export const connectionsTableColumnVisibilityDefault =
|
|
|
|
CONNECTIONS_TABLE_INITIAL_COLUMN_VISIBILITY
|
|
|
|
|
2023-09-16 23:31:40 +08:00
|
|
|
export const [
|
|
|
|
connectionsTableColumnVisibility,
|
|
|
|
setConnectionsTableColumnVisibility,
|
|
|
|
] = makePersisted(
|
|
|
|
createSignal<ConnectionsTableColumnVisibility>(
|
2024-10-11 02:11:20 +08:00
|
|
|
connectionsTableColumnVisibilityDefault,
|
2023-09-16 23:31:40 +08:00
|
|
|
),
|
|
|
|
{
|
|
|
|
name: 'connectionsTableColumnVisibility',
|
|
|
|
storage: localStorage,
|
|
|
|
},
|
|
|
|
)
|
2024-10-11 02:11:20 +08:00
|
|
|
|
|
|
|
export const connectionsTableColumnOrderDefault =
|
|
|
|
CONNECTIONS_TABLE_INITIAL_COLUMN_ORDER
|
|
|
|
|
2023-09-16 23:31:40 +08:00
|
|
|
export const [connectionsTableColumnOrder, setConnectionsTableColumnOrder] =
|
|
|
|
makePersisted(
|
|
|
|
createSignal<ConnectionsTableColumnOrder>(
|
2024-10-11 02:11:20 +08:00
|
|
|
connectionsTableColumnOrderDefault,
|
2023-09-16 23:31:40 +08:00
|
|
|
),
|
|
|
|
{
|
|
|
|
name: 'connectionsTableColumnOrder',
|
|
|
|
storage: localStorage,
|
|
|
|
},
|
|
|
|
)
|
2024-10-11 02:11:20 +08:00
|
|
|
|
|
|
|
export const clientSourceIPTagsDefault: {
|
|
|
|
tagName: string
|
|
|
|
sourceIP: string
|
|
|
|
}[] = []
|
|
|
|
|
2023-09-16 23:31:40 +08:00
|
|
|
export const [clientSourceIPTags, setClientSourceIPTags] = makePersisted(
|
2024-10-11 02:11:20 +08:00
|
|
|
createSignal(clientSourceIPTagsDefault),
|
2023-09-16 23:31:40 +08:00
|
|
|
{
|
|
|
|
name: 'clientSourceIPTags',
|
|
|
|
storage: localStorage,
|
|
|
|
},
|
|
|
|
)
|
2024-10-11 02:11:20 +08:00
|
|
|
|
|
|
|
export const logsTableSizeDefault = TAILWINDCSS_SIZE.XS
|
|
|
|
|
2023-09-15 23:43:55 +08:00
|
|
|
export const [logsTableSize, setLogsTableSize] = makePersisted(
|
2024-10-11 02:11:20 +08:00
|
|
|
createSignal(logsTableSizeDefault),
|
2023-09-15 23:43:55 +08:00
|
|
|
{ name: 'logsTableSize', storage: localStorage },
|
2023-09-05 20:53:00 +08:00
|
|
|
)
|
2024-10-11 02:11:20 +08:00
|
|
|
|
|
|
|
export const logLevelDefault = LOG_LEVEL.Info
|
|
|
|
|
2023-09-14 16:49:39 +08:00
|
|
|
export const [logLevel, setLogLevel] = makePersisted(
|
2024-10-11 02:11:20 +08:00
|
|
|
createSignal(logLevelDefault),
|
2023-09-14 16:49:39 +08:00
|
|
|
{ name: 'logLevel', storage: localStorage },
|
|
|
|
)
|
2024-10-11 02:11:20 +08:00
|
|
|
|
|
|
|
export const logMaxRowsDefault = DEFAULT_LOGS_TABLE_MAX_ROWS
|
|
|
|
|
2023-09-22 00:12:52 +08:00
|
|
|
export const [logMaxRows, setLogMaxRows] = makePersisted(
|
2024-10-11 02:11:20 +08:00
|
|
|
createSignal(logMaxRowsDefault),
|
2023-09-22 00:12:52 +08:00
|
|
|
{
|
|
|
|
name: 'logMaxRows',
|
|
|
|
storage: localStorage,
|
|
|
|
},
|
|
|
|
)
|
2023-09-14 18:31:52 +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
|
|
|
|
}
|
|
|
|
|
2024-10-11 02:11:20 +08:00
|
|
|
export const latencyTestTimeoutDurationDefault = 5000
|
|
|
|
|
2023-09-06 11:55:12 +08:00
|
|
|
export const [latencyTestTimeoutDuration, setLatencyTestTimeoutDuration] =
|
2024-10-11 02:11:20 +08:00
|
|
|
makePersisted(createSignal(latencyTestTimeoutDurationDefault), {
|
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
|
2024-09-29 10:46:22 +08:00
|
|
|
|
2024-10-11 02:11:20 +08:00
|
|
|
export const iconHeightDefault = 24
|
|
|
|
|
|
|
|
export const [iconHeight, setIconHeight] = makePersisted(
|
|
|
|
createSignal(iconHeightDefault),
|
|
|
|
{
|
|
|
|
name: 'iconHeight',
|
|
|
|
storage: localStorage,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
export const iconMarginRightDefault = 8
|
2024-09-29 10:46:22 +08:00
|
|
|
|
|
|
|
export const [iconMarginRight, setIconMarginRight] = makePersisted(
|
2024-10-11 02:11:20 +08:00
|
|
|
createSignal(iconMarginRightDefault),
|
2024-09-29 10:46:22 +08:00
|
|
|
{ name: 'iconMarginRight', storage: localStorage },
|
|
|
|
)
|