From 1b09fa39af2c5bfc9fd8374c9b2ec53e59595184 Mon Sep 17 00:00:00 2001 From: kunish Date: Sun, 3 Sep 2023 03:56:04 +0800 Subject: [PATCH] feat: relax https latency test range --- ....tsx => ConnectionsTableOrderingModal.tsx} | 0 src/components/{Delay.tsx => Latency.tsx} | 15 ++++++----- src/components/ProxyNodeCard.tsx | 4 +-- src/components/ProxyPreviewBar.tsx | 25 ++++++++++++------- src/components/ProxyPreviewDots.tsx | 17 +++++++++---- src/components/index.ts | 4 +-- src/constants/index.ts | 8 +++++- src/signals/config.ts | 12 ++++++++- 8 files changed, 59 insertions(+), 26 deletions(-) rename src/components/{ConnectionsModal.tsx => ConnectionsTableOrderingModal.tsx} (100%) rename src/components/{Delay.tsx => Latency.tsx} (56%) diff --git a/src/components/ConnectionsModal.tsx b/src/components/ConnectionsTableOrderingModal.tsx similarity index 100% rename from src/components/ConnectionsModal.tsx rename to src/components/ConnectionsTableOrderingModal.tsx diff --git a/src/components/Delay.tsx b/src/components/Latency.tsx similarity index 56% rename from src/components/Delay.tsx rename to src/components/Latency.tsx index 79704ba..4341e67 100644 --- a/src/components/Delay.tsx +++ b/src/components/Latency.tsx @@ -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 ( <> {delay()}ms diff --git a/src/components/ProxyNodeCard.tsx b/src/components/ProxyNodeCard.tsx index a202a35..8303c7d 100644 --- a/src/components/ProxyNodeCard.tsx +++ b/src/components/ProxyNodeCard.tsx @@ -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'}
- +
diff --git a/src/components/ProxyPreviewBar.tsx b/src/components/ProxyPreviewBar.tsx index b0ddfa6..aff07a4 100644 --- a/src/components/ProxyPreviewBar.tsx +++ b/src/components/ProxyPreviewBar.tsx @@ -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: { >
- +
) diff --git a/src/components/ProxyPreviewDots.tsx b/src/components/ProxyPreviewDots.tsx index 1e8ac86..f509f92 100644 --- a/src/components/ProxyPreviewDots.tsx +++ b/src/components/ProxyPreviewDots.tsx @@ -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' diff --git a/src/components/index.ts b/src/components/index.ts index 1916d21..ff30046 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -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' diff --git a/src/constants/index.ts b/src/constants/index.ts index 5bb3c21..3a63284 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -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', diff --git a/src/signals/config.ts b/src/signals/config.ts index 9b56f49..0dd0e23 100644 --- a/src/signals/config.ts +++ b/src/signals/config.ts @@ -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) {