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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,11 @@
import { makePersisted } from '@solid-primitives/storage' import { makePersisted } from '@solid-primitives/storage'
import { createSignal } from 'solid-js' 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' import { setCurTheme } from '~/signals'
export const [proxiesPreviewType, setProxiesPreviewType] = makePersisted( export const [proxiesPreviewType, setProxiesPreviewType] = makePersisted(
@ -36,6 +41,11 @@ export const [renderInTwoColumn, setRenderInTwoColumn] = makePersisted(
{ name: 'renderInTwoColumn', storage: localStorage }, { 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) => { const setTheme = (isDark: boolean) => {
if (autoSwitchTheme()) { if (autoSwitchTheme()) {
if (isDark) { if (isDark) {