mirror of
https://github.com/MetaCubeX/metacubexd.git
synced 2024-11-24 09:45:35 +08:00
refactor: rename delay to latency
This commit is contained in:
parent
635b8ba966
commit
18922eecb3
@ -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,
|
||||
)
|
||||
|
||||
|
@ -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 <DelayDots delay={delay} selected={isSelected} />
|
||||
return <LatencyDots latency={latency} selected={isSelected} />
|
||||
}}
|
||||
</For>
|
||||
</div>
|
||||
|
@ -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',
|
||||
|
@ -39,7 +39,7 @@ export default {
|
||||
auto: '自适应',
|
||||
off: '关闭',
|
||||
proxiesPreviewType: '节点组预览样式',
|
||||
urlForDelayTest: '测速链接',
|
||||
urlForLatencyTest: '测速链接',
|
||||
autoCloseConns: '切换代理时自动断开全部连接',
|
||||
autoSwitchTheme: '自动切换主题',
|
||||
favDayTheme: '浅色主题偏好',
|
||||
|
@ -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 = () => {
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col">
|
||||
<div class="pb-4">{t('urlForDelayTest')}</div>
|
||||
<div class="pb-4">{t('urlForLatencyTest')}</div>
|
||||
|
||||
<input
|
||||
class="w-100 input input-bordered max-w-md"
|
||||
value={urlForDelayTest()}
|
||||
onChange={(e) => setUrlForDelayTest(e.target?.value!)}
|
||||
value={urlForLatencyTest()}
|
||||
onChange={(e) => setUrlForLatencyTest(e.target?.value!)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -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 () => {
|
||||
</div>
|
||||
<Show when={!collapsedMap()[`group-${proxy.name}`]}>
|
||||
<ProxyNodePreview
|
||||
proxyNameList={proxy.all ?? []}
|
||||
proxyNameList={sortProxiesByOrderingType(
|
||||
proxy.all ?? [],
|
||||
latencyMap(),
|
||||
proxiesOrderingType(),
|
||||
)}
|
||||
now={proxy.now}
|
||||
/>
|
||||
</Show>
|
||||
|
@ -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
|
||||
|
@ -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<string, number> = 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,
|
||||
|
Loading…
Reference in New Issue
Block a user