feat: relax https latency test range

This commit is contained in:
kunish 2023-09-03 03:56:04 +08:00
parent bbeb7c2e8d
commit 1b09fa39af
No known key found for this signature in database
GPG Key ID: 647A12B4F782C430
8 changed files with 59 additions and 26 deletions

View File

@ -1,8 +1,8 @@
import { Show, createEffect, createMemo, createSignal } from 'solid-js'
import { DELAY } from '~/constants'
import { useProxies } from '~/signals'
import { LATENCY_QUALITY_MAP_HTTP } from '~/constants'
import { latencyQualityMap, useProxies } from '~/signals'
export const Delay = (props: { name?: string }) => {
export const Latency = (props: { name?: string }) => {
const { delayMap } = useProxies()
const [textClassName, setTextClassName] = createSignal('')
const delay = createMemo(() => {
@ -12,9 +12,9 @@ export const Delay = (props: { name?: string }) => {
createEffect(() => {
setTextClassName('text-success')
if (delay() > DELAY.HIGH) {
if (delay() > latencyQualityMap().HIGH) {
setTextClassName('text-error')
} else if (delay() > DELAY.MEDIUM) {
} else if (delay() > latencyQualityMap().MEDIUM) {
setTextClassName('text-warning')
}
})
@ -22,7 +22,10 @@ export const Delay = (props: { name?: string }) => {
return (
<>
<Show
when={typeof delay() === 'number' && delay() !== DELAY.NOT_CONNECTED}
when={
typeof delay() === 'number' &&
delay() !== LATENCY_QUALITY_MAP_HTTP.NOT_CONNECTED
}
>
<span class={textClassName()}>{delay()}ms</span>
</Show>

View File

@ -1,6 +1,6 @@
import { createMemo } from 'solid-js'
import { twMerge } from 'tailwind-merge'
import { Delay } from '~/components'
import { Latency } from '~/components'
import { useProxies } from '~/signals'
export default (props: {
@ -44,7 +44,7 @@ export default (props: {
{proxyNode()?.udp && ' :: udp'}
</div>
<div class="text-xs">
<Delay name={props.proxyName} />
<Latency name={props.proxyName} />
</div>
</div>
</div>

View File

@ -1,7 +1,6 @@
import { createMemo } from 'solid-js'
import { Delay } from '~/components'
import { DELAY } from '~/constants'
import { useProxies } from '~/signals'
import { Latency } from '~/components'
import { latencyQualityMap, useProxies } from '~/signals'
export const ProxyPreviewBar = (props: {
proxyNameList: string[]
@ -15,21 +14,29 @@ export const ProxyPreviewBar = (props: {
const good = createMemo(
() =>
delayList().filter(
(delay) => delay > DELAY.NOT_CONNECTED && delay <= DELAY.MEDIUM,
(delay) =>
delay > latencyQualityMap().NOT_CONNECTED &&
delay <= latencyQualityMap().MEDIUM,
).length,
)
const middle = createMemo(
() =>
delayList().filter((delay) => delay > DELAY.MEDIUM && delay <= DELAY.HIGH)
.length,
delayList().filter(
(delay) =>
delay > latencyQualityMap().NOT_CONNECTED &&
delay <= latencyQualityMap().HIGH,
).length,
)
const slow = createMemo(
() => delayList().filter((delay) => delay > DELAY.HIGH).length,
() =>
delayList().filter((delay) => delay > latencyQualityMap().HIGH).length,
)
const notConnected = createMemo(
() =>
delayList().filter(
(delay) => delay === DELAY.NOT_CONNECTED || typeof delay !== 'number',
(delay) =>
delay === latencyQualityMap().NOT_CONNECTED ||
typeof delay !== 'number',
).length,
)
@ -62,7 +69,7 @@ export const ProxyPreviewBar = (props: {
></div>
</div>
<div class="ml-3 w-8 text-xs">
<Delay name={props.now} />
<Latency name={props.now} />
</div>
</div>
)

View File

@ -1,20 +1,27 @@
import { For } from 'solid-js'
import { twMerge } from 'tailwind-merge'
import { DELAY } from '~/constants'
import { useProxies } from '~/signals'
import {
LATENCY_QUALITY_MAP_HTTP,
LATENCY_QUALITY_MAP_HTTPS,
} from '~/constants'
import { isLatencyTestByHttps, useProxies } from '~/signals'
const DelayDots = (p: { delay: number | undefined; selected: boolean }) => {
const delayMap = isLatencyTestByHttps()
? LATENCY_QUALITY_MAP_HTTP
: LATENCY_QUALITY_MAP_HTTPS
let dotClassName = p.selected
? 'bg-white border-4 border-success'
: 'bg-success'
if (typeof p.delay !== 'number' || p.delay === DELAY.NOT_CONNECTED) {
if (typeof p.delay !== 'number' || p.delay === delayMap.NOT_CONNECTED) {
dotClassName = p.selected
? 'bg-white border-4 border-neutral'
: 'bg-neutral'
} else if (p.delay > DELAY.HIGH) {
} else if (p.delay > delayMap.HIGH) {
dotClassName = p.selected ? 'bg-white border-4 border-error' : 'bg-error'
} else if (p.delay > DELAY.MEDIUM) {
} else if (p.delay > delayMap.MEDIUM) {
dotClassName = p.selected
? 'bg-white border-4 border-warning'
: 'bg-warning'

View File

@ -1,9 +1,9 @@
export * from './Button'
export * from './Collpase'
export * from './ConnectionsModal'
export * from './Delay'
export * from './ConnectionsTableOrderingModal'
export * from './ForTwoColumns'
export * from './Header'
export * from './Latency'
export * from './ProxyCardGroups'
export * from './ProxyNodeCard'
export * from './ProxyNodePreview'

View File

@ -40,12 +40,18 @@ export enum ROUTES {
Config = '/config',
}
export enum DELAY {
export enum LATENCY_QUALITY_MAP_HTTP {
NOT_CONNECTED = 0,
MEDIUM = 200,
HIGH = 500,
}
export enum LATENCY_QUALITY_MAP_HTTPS {
NOT_CONNECTED = 0,
MEDIUM = 800,
HIGH = 1500,
}
export enum PROXIES_PREVIEW_TYPE {
OFF = 'off',
DOTS = 'dots',

View File

@ -1,6 +1,11 @@
import { makePersisted } from '@solid-primitives/storage'
import { createSignal } from 'solid-js'
import { PROXIES_PREVIEW_TYPE, PROXIES_SORTING_TYPE } from '~/constants'
import {
LATENCY_QUALITY_MAP_HTTP,
LATENCY_QUALITY_MAP_HTTPS,
PROXIES_PREVIEW_TYPE,
PROXIES_SORTING_TYPE,
} from '~/constants'
import { setCurTheme } from '~/signals'
export const [proxiesPreviewType, setProxiesPreviewType] = makePersisted(
@ -36,6 +41,11 @@ export const [renderInTwoColumn, setRenderInTwoColumn] = makePersisted(
{ name: 'renderInTwoColumn', storage: localStorage },
)
export const isLatencyTestByHttps = () => urlForDelayTest().startsWith('https')
export const latencyQualityMap = () =>
isLatencyTestByHttps() ? LATENCY_QUALITY_MAP_HTTPS : LATENCY_QUALITY_MAP_HTTP
const setTheme = (isDark: boolean) => {
if (autoSwitchTheme()) {
if (isDark) {