mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-08 02:52:07 +08:00
fix: provider proxy delay check (#7456)
* refactor(proxy): support delay testing for provider-based proxies * style: remove debug console logs * docs: update changelog * feat(services): merge provider nodes into records in calcuProxies --------- Co-authored-by: Tunglies <tunglies.dev@outlook.com>
This commit is contained in:
@@ -21,7 +21,7 @@ import {
|
||||
InputLabel,
|
||||
MenuItem,
|
||||
Select,
|
||||
SelectChangeEvent,
|
||||
type SelectChangeEvent,
|
||||
Tooltip,
|
||||
Typography,
|
||||
alpha,
|
||||
@@ -31,7 +31,7 @@ import { useLockFn } from 'ahooks'
|
||||
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useNavigate } from 'react-router'
|
||||
import { delayGroup, healthcheckProxyProvider } from 'tauri-plugin-mihomo-api'
|
||||
import { delayGroup } from 'tauri-plugin-mihomo-api'
|
||||
|
||||
import { EnhancedCard } from '@/components/home/enhanced-card'
|
||||
import { useProfiles } from '@/hooks/use-profiles'
|
||||
@@ -558,11 +558,12 @@ export const CurrentProxyCard = () => {
|
||||
debugLog(
|
||||
`[CurrentProxyCard] 自动检测当前节点延迟,组: ${groupName}, 节点: ${proxyName}`,
|
||||
)
|
||||
if (proxyRecord.provider) {
|
||||
await healthcheckProxyProvider(proxyRecord.provider)
|
||||
} else {
|
||||
await delayManager.checkDelay(proxyName, groupName, timeout)
|
||||
}
|
||||
await delayManager.checkDelay(
|
||||
proxyRecord.name,
|
||||
groupName,
|
||||
timeout,
|
||||
proxyRecord.provider,
|
||||
)
|
||||
} catch (error) {
|
||||
console.error(
|
||||
`[CurrentProxyCard] 自动检测当前节点延迟失败,组: ${groupName}, 节点: ${proxyName}`,
|
||||
@@ -658,8 +659,7 @@ export const CurrentProxyCard = () => {
|
||||
const timeout = verge?.default_latency_timeout || 10000
|
||||
|
||||
// 获取当前组的所有代理
|
||||
const proxyNames: string[] = []
|
||||
const providers: Set<string> = new Set()
|
||||
const delayProxies: IProxyItem[] = []
|
||||
|
||||
if (isGlobalMode && proxies?.global) {
|
||||
// 全局模式
|
||||
@@ -672,11 +672,7 @@ export const CurrentProxyCard = () => {
|
||||
|
||||
allProxies.forEach((name: string) => {
|
||||
const proxy = state.proxyData.records[name]
|
||||
if (proxy?.provider) {
|
||||
providers.add(proxy.provider)
|
||||
} else {
|
||||
proxyNames.push(name)
|
||||
}
|
||||
delayProxies.push(proxy)
|
||||
})
|
||||
} else {
|
||||
// 规则模式
|
||||
@@ -684,35 +680,19 @@ export const CurrentProxyCard = () => {
|
||||
if (group) {
|
||||
group.all.forEach((name: string) => {
|
||||
const proxy = state.proxyData.records[name]
|
||||
if (proxy?.provider) {
|
||||
providers.add(proxy.provider)
|
||||
} else {
|
||||
proxyNames.push(name)
|
||||
}
|
||||
delayProxies.push(proxy)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
debugLog(
|
||||
`[CurrentProxyCard] 找到代理数量: ${proxyNames.length}, 提供者数量: ${providers.size}`,
|
||||
)
|
||||
|
||||
// 测试提供者的节点
|
||||
if (providers.size > 0) {
|
||||
debugLog(`[CurrentProxyCard] 开始测试提供者节点`)
|
||||
await Promise.allSettled(
|
||||
[...providers].map((p) => healthcheckProxyProvider(p)),
|
||||
)
|
||||
}
|
||||
|
||||
// 测试非提供者的节点
|
||||
if (proxyNames.length > 0) {
|
||||
// 测试全部节点
|
||||
if (delayProxies.length > 0) {
|
||||
const url = delayManager.getUrl(groupName)
|
||||
debugLog(`[CurrentProxyCard] 测试URL: ${url}, 超时: ${timeout}ms`)
|
||||
|
||||
try {
|
||||
await Promise.race([
|
||||
delayManager.checkListDelay(proxyNames, groupName, timeout),
|
||||
delayManager.checkListDelay(delayProxies, groupName, timeout),
|
||||
delayGroup(groupName, url, timeout),
|
||||
])
|
||||
debugLog(`[CurrentProxyCard] 延迟测试完成,组: ${groupName}`)
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react'
|
||||
import { delayGroup, healthcheckProxyProvider } from 'tauri-plugin-mihomo-api'
|
||||
import { delayGroup } from 'tauri-plugin-mihomo-api'
|
||||
|
||||
import {
|
||||
BaseEmpty,
|
||||
@@ -97,29 +97,12 @@ function useProxyRenderState(
|
||||
|
||||
debugLog(`[ProxyGroups] 找到代理数量: ${proxies.length}`)
|
||||
|
||||
const providers = new Set(
|
||||
proxies.map((p) => p!.provider!).filter(Boolean),
|
||||
)
|
||||
|
||||
if (providers.size) {
|
||||
debugLog(`[ProxyGroups] 发现提供者,数量: ${providers.size}`)
|
||||
Promise.allSettled(
|
||||
[...providers].map((p) => healthcheckProxyProvider(p)),
|
||||
).then(() => {
|
||||
debugLog(`[ProxyGroups] 提供者健康检查完成`)
|
||||
onProxies()
|
||||
})
|
||||
}
|
||||
|
||||
const names = proxies.filter((p) => !p!.provider).map((p) => p!.name)
|
||||
debugLog(`[ProxyGroups] 过滤后需要测试的代理数量: ${names.length}`)
|
||||
|
||||
const url = delayManager.getUrl(groupName)
|
||||
debugLog(`[ProxyGroups] 测试URL: ${url}, 超时: ${timeout}ms`)
|
||||
|
||||
try {
|
||||
await Promise.race([
|
||||
delayManager.checkListDelay(names, groupName, timeout),
|
||||
delayManager.checkListDelay(proxies, groupName, timeout),
|
||||
delayGroup(groupName, url, timeout).then((result) => {
|
||||
debugLog(
|
||||
`[ProxyGroups] getGroupProxyDelays返回结果数量:`,
|
||||
|
||||
@@ -159,8 +159,7 @@ export const ProxyItemMini = (props: Props) => {
|
||||
<BaseLoading />
|
||||
</Widget>
|
||||
)}
|
||||
{!proxy.provider && delayValue !== -2 && (
|
||||
// provider 的节点不支持检测
|
||||
{delayValue !== -2 && (
|
||||
<Widget
|
||||
className="the-check"
|
||||
onClick={(e) => {
|
||||
@@ -182,16 +181,13 @@ export const ProxyItemMini = (props: Props) => {
|
||||
<Widget
|
||||
className="the-delay"
|
||||
onClick={(e) => {
|
||||
if (proxy.provider) return
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
onDelay()
|
||||
onDelay(proxy.provider)
|
||||
}}
|
||||
sx={({ palette }) => ({
|
||||
color: delayManager.formatDelayColor(delayValue, timeout),
|
||||
...(!proxy.provider
|
||||
? { ':hover': { bgcolor: alpha(palette.primary.main, 0.15) } }
|
||||
: {}),
|
||||
':hover': { bgcolor: alpha(palette.primary.main, 0.15) },
|
||||
})}
|
||||
>
|
||||
{delayManager.formatDelay(delayValue, timeout)}
|
||||
|
||||
@@ -7,8 +7,8 @@ import {
|
||||
ListItemIcon,
|
||||
ListItemText,
|
||||
styled,
|
||||
SxProps,
|
||||
Theme,
|
||||
type SxProps,
|
||||
type Theme,
|
||||
} from '@mui/material'
|
||||
|
||||
import { BaseLoading } from '@/components/base'
|
||||
@@ -125,14 +125,13 @@ export const ProxyItem = (props: Props) => {
|
||||
</Widget>
|
||||
)}
|
||||
|
||||
{!proxy.provider && delayValue !== -2 && (
|
||||
// provider 的节点不支持检测
|
||||
{delayValue !== -2 && (
|
||||
<Widget
|
||||
className="the-check"
|
||||
onClick={(e) => {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
onDelay()
|
||||
onDelay(proxy.provider)
|
||||
}}
|
||||
sx={({ palette }) => ({
|
||||
display: 'none', // hover 时显示
|
||||
@@ -148,16 +147,13 @@ export const ProxyItem = (props: Props) => {
|
||||
<Widget
|
||||
className="the-delay"
|
||||
onClick={(e) => {
|
||||
if (proxy.provider) return
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
onDelay()
|
||||
onDelay(proxy.provider)
|
||||
}}
|
||||
sx={({ palette }) => ({
|
||||
color: delayManager.formatDelayColor(delayValue, timeout),
|
||||
...(!proxy.provider
|
||||
? { ':hover': { bgcolor: alpha(palette.primary.main, 0.15) } }
|
||||
: {}),
|
||||
':hover': { bgcolor: alpha(palette.primary.main, 0.15) },
|
||||
})}
|
||||
>
|
||||
{delayManager.formatDelay(delayValue, timeout)}
|
||||
|
||||
@@ -158,12 +158,11 @@ export const useRenderList = (
|
||||
const calculateDelays = async () => {
|
||||
try {
|
||||
const timeout = verge?.default_latency_timeout || 10000
|
||||
const proxyNames = allProxies.map((proxy) => proxy.name)
|
||||
|
||||
debugLog(`[ChainMode] 开始计算 ${proxyNames.length} 个节点的延迟`)
|
||||
debugLog(`[ChainMode] 开始计算 ${allProxies.length} 个节点的延迟`)
|
||||
|
||||
// 使用 delayManager 计算延迟,每个节点计算完成后会自动触发监听器刷新界面
|
||||
delayManager.checkListDelay(proxyNames, 'chain-mode', timeout)
|
||||
delayManager.checkListDelay(allProxies, 'chain-mode', timeout)
|
||||
} catch (error) {
|
||||
console.error('Failed to calculate delays for chain mode:', error)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user