From 18922eecb393201ced7b2e63844d9c93796a517e Mon Sep 17 00:00:00 2001 From: kunish Date: Sun, 3 Sep 2023 05:40:39 +0800 Subject: [PATCH] refactor: rename delay to latency --- src/components/ProxyPreviewBar.tsx | 31 +++++++++++++++-------------- src/components/ProxyPreviewDots.tsx | 14 ++++++------- src/i18n/en.ts | 2 +- src/i18n/zh.ts | 2 +- src/pages/Config.tsx | 10 +++++----- src/pages/Proxies.tsx | 10 +++++++--- src/signals/config.ts | 7 ++++--- src/signals/proxies.ts | 12 +++++------ 8 files changed, 47 insertions(+), 41 deletions(-) diff --git a/src/components/ProxyPreviewBar.tsx b/src/components/ProxyPreviewBar.tsx index d99391d..cf486ac 100644 --- a/src/components/ProxyPreviewBar.tsx +++ b/src/components/ProxyPreviewBar.tsx @@ -7,36 +7,37 @@ export const ProxyPreviewBar = (props: { now?: string }) => { const { latencyMap } = useProxies() - const delayList = createMemo(() => + const latencyList = createMemo(() => props.proxyNameList.map((i) => latencyMap()[i]), ) - const all = createMemo(() => delayList().length) + const all = createMemo(() => latencyList().length) const good = createMemo( () => - delayList().filter( - (delay) => - delay > latencyQualityMap().NOT_CONNECTED && - delay <= latencyQualityMap().MEDIUM, + latencyList().filter( + (latency) => + latency > latencyQualityMap().NOT_CONNECTED && + latency <= latencyQualityMap().MEDIUM, ).length, ) const middle = createMemo( () => - delayList().filter( - (delay) => - delay > latencyQualityMap().NOT_CONNECTED && - delay <= latencyQualityMap().HIGH, + latencyList().filter( + (latency) => + latency > latencyQualityMap().NOT_CONNECTED && + latency <= latencyQualityMap().HIGH, ).length, ) const slow = createMemo( () => - delayList().filter((delay) => delay > latencyQualityMap().HIGH).length, + latencyList().filter((latency) => latency > latencyQualityMap().HIGH) + .length, ) const notConnected = createMemo( () => - delayList().filter( - (delay) => - delay === latencyQualityMap().NOT_CONNECTED || - typeof delay !== 'number', + latencyList().filter( + (latency) => + latency === latencyQualityMap().NOT_CONNECTED || + typeof latency !== 'number', ).length, ) diff --git a/src/components/ProxyPreviewDots.tsx b/src/components/ProxyPreviewDots.tsx index 771216c..5b2a5fc 100644 --- a/src/components/ProxyPreviewDots.tsx +++ b/src/components/ProxyPreviewDots.tsx @@ -2,21 +2,21 @@ import { For } from 'solid-js' import { twMerge } from 'tailwind-merge' import { latencyQualityMap, useProxies } from '~/signals' -const DelayDots = (p: { delay: number | undefined; selected: boolean }) => { +const LatencyDots = (p: { latency: number | undefined; selected: boolean }) => { let dotClassName = p.selected ? 'bg-white border-4 border-success' : 'bg-success' if ( - typeof p.delay !== 'number' || - p.delay === latencyQualityMap().NOT_CONNECTED + typeof p.latency !== 'number' || + p.latency === latencyQualityMap().NOT_CONNECTED ) { dotClassName = p.selected ? 'bg-white border-4 border-neutral' : 'bg-neutral' - } else if (p.delay > latencyQualityMap().HIGH) { + } else if (p.latency > latencyQualityMap().HIGH) { dotClassName = p.selected ? 'bg-white border-4 border-error' : 'bg-error' - } else if (p.delay > latencyQualityMap().MEDIUM) { + } else if (p.latency > latencyQualityMap().MEDIUM) { dotClassName = p.selected ? 'bg-white border-4 border-warning' : 'bg-warning' @@ -39,10 +39,10 @@ export const ProxyPreviewDots = (props: { latencyMap()[name], ])} > - {([name, delay]) => { + {([name, latency]) => { const isSelected = props.now === name - return + return }} diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 09be11b..8584616 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -39,7 +39,7 @@ export default { auto: 'Auto', off: 'Off', proxiesPreviewType: 'Proxies preview type', - urlForDelayTest: 'Url for delay test', + urlForLatencyTest: 'Url for latency test', autoCloseConns: 'Automatically close all connections', autoSwitchTheme: 'Automatically switch theme', favDayTheme: 'Favorite light theme', diff --git a/src/i18n/zh.ts b/src/i18n/zh.ts index f9b51e4..99d07a4 100644 --- a/src/i18n/zh.ts +++ b/src/i18n/zh.ts @@ -39,7 +39,7 @@ export default { auto: '自适应', off: '关闭', proxiesPreviewType: '节点组预览样式', - urlForDelayTest: '测速链接', + urlForLatencyTest: '测速链接', autoCloseConns: '切换代理时自动断开全部连接', autoSwitchTheme: '自动切换主题', favDayTheme: '浅色主题偏好', diff --git a/src/pages/Config.tsx b/src/pages/Config.tsx index 371eda6..9283b23 100644 --- a/src/pages/Config.tsx +++ b/src/pages/Config.tsx @@ -25,8 +25,8 @@ import { setProxiesOrderingType, setProxiesPreviewType, setRenderInTwoColumn, - setUrlForDelayTest, - urlForDelayTest, + setUrlForLatencyTest, + urlForLatencyTest, useRequest, } from '~/signals' import type { DNSQuery, Config as IConfig } from '~/types' @@ -323,12 +323,12 @@ const ConfigForXd = () => {
-
{t('urlForDelayTest')}
+
{t('urlForLatencyTest')}
setUrlForDelayTest(e.target?.value!)} + value={urlForLatencyTest()} + onChange={(e) => setUrlForLatencyTest(e.target?.value!)} />
diff --git a/src/pages/Proxies.tsx b/src/pages/Proxies.tsx index e8b0a46..d55f91c 100644 --- a/src/pages/Proxies.tsx +++ b/src/pages/Proxies.tsx @@ -17,7 +17,7 @@ export default () => { const { proxies, setProxyGroupByProxyName, - delayTestByProxyGroupName, + latencyTestByProxyGroupName, latencyMap, } = useProxies() @@ -34,7 +34,7 @@ export default () => { el.classList.add('animate-pulse') e.stopPropagation() - await delayTestByProxyGroupName(name) + await latencyTestByProxyGroupName(name) el.classList.remove('animate-pulse') } @@ -61,7 +61,11 @@ export default () => { diff --git a/src/signals/config.ts b/src/signals/config.ts index bb6d259..c51cdd6 100644 --- a/src/signals/config.ts +++ b/src/signals/config.ts @@ -16,9 +16,9 @@ export const [proxiesOrderingType, setProxiesOrderingType] = makePersisted( createSignal(PROXIES_ORDERING_TYPE.NATURAL), { name: 'proxiesOrderingType', storage: localStorage }, ) -export const [urlForDelayTest, setUrlForDelayTest] = makePersisted( +export const [urlForLatencyTest, setUrlForLatencyTest] = makePersisted( createSignal('https://www.gstatic.com/generate_204'), - { name: 'urlForDelayTest', storage: localStorage }, + { name: 'urlForLatencyTest', storage: localStorage }, ) export const [autoCloseConns, setAutoCloseConns] = makePersisted( createSignal(false), @@ -41,7 +41,8 @@ export const [renderInTwoColumn, setRenderInTwoColumn] = makePersisted( { name: 'renderInTwoColumn', storage: localStorage }, ) -export const isLatencyTestByHttps = () => urlForDelayTest().startsWith('https') +export const isLatencyTestByHttps = () => + urlForLatencyTest().startsWith('https') export const latencyQualityMap = () => isLatencyTestByHttps() ? LATENCY_QUALITY_MAP_HTTPS : LATENCY_QUALITY_MAP_HTTP diff --git a/src/signals/proxies.ts b/src/signals/proxies.ts index 5fd6233..1cddcfa 100644 --- a/src/signals/proxies.ts +++ b/src/signals/proxies.ts @@ -1,5 +1,5 @@ import { createSignal } from 'solid-js' -import { autoCloseConns, urlForDelayTest, useRequest } from '~/signals' +import { autoCloseConns, urlForLatencyTest, useRequest } from '~/signals' import type { Proxy, ProxyNode, ProxyProvider } from '~/types' type ProxyInfo = { @@ -21,7 +21,7 @@ export const useProxies = () => { const setProxyInfoByProixes = (proxies: Proxy[] | ProxyNode[]) => { proxies.forEach((proxy) => { - const delay = proxy.history.at(-1)?.delay ?? -1 + const latency = proxy.history.at(-1)?.delay ?? -1 setProxyNodeMap({ ...proxyNodeMap(), @@ -33,7 +33,7 @@ export const useProxies = () => { }) setLatencyMap({ ...latencyMap(), - [proxy.name]: delay, + [proxy.name]: latency, }) }) } @@ -88,11 +88,11 @@ export const useProxies = () => { setProxies(proxyGroupList) } - const delayTestByProxyGroupName = async (proxyGroupName: string) => { + const latencyTestByProxyGroupName = async (proxyGroupName: string) => { const data: Record = await request .get(`group/${proxyGroupName}/delay`, { searchParams: { - url: urlForDelayTest(), + url: urlForLatencyTest(), timeout: 2000, }, }) @@ -130,7 +130,7 @@ export const useProxies = () => { return { proxies, proxyProviders, - delayTestByProxyGroupName, + latencyTestByProxyGroupName, latencyMap, proxyNodeMap, updateProxies,