mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-28 08:20:04 +08:00
perf(proxy): consolidate proxy data into a single IPC (#7542)
* feat(proxy): build deterministic proxy view * feat(proxy): expose ordered proxy view command * feat(proxy): add proxy view client contract * fix(lint): allow Node test files * feat(proxy): switch UI to ordered proxy view * fix(proxy): harden ordered proxy view consumers * fix(proxy): compare chain duplicates by current id * fix(proxy): release mihomo guard after fetch * fix(proxy): preserve semantic selections across refresh * fix(proxy): block global chain without GLOBAL * fix(proxy): handle proxy view edge states
This commit is contained in:
+30
-20
@@ -4,6 +4,12 @@ import {
|
||||
type ProxyDelay,
|
||||
} from 'tauri-plugin-mihomo-api'
|
||||
|
||||
import {
|
||||
memberDetails,
|
||||
providerNameOf,
|
||||
type InteractableProxyMember,
|
||||
type ResolvedProxyMember,
|
||||
} from '@/types/proxy-view'
|
||||
import { debugLog } from '@/utils/debug'
|
||||
|
||||
const hashKey = (name: string, group: string) => `${group ?? ''}::${name}`
|
||||
@@ -185,19 +191,18 @@ class DelayManager {
|
||||
return update ? update.delay : -1
|
||||
}
|
||||
|
||||
/// 暂时修复provider的节点延迟排序的问题
|
||||
getDelayFix(proxy: IProxyItem, group: string) {
|
||||
if (!proxy.provider) {
|
||||
const update = this.getDelayUpdate(proxy.name, group)
|
||||
if (update && (update.delay >= 0 || update.delay === -2)) {
|
||||
return update.delay
|
||||
}
|
||||
getDelayFix(member: ResolvedProxyMember, group: string) {
|
||||
if (member.kind === 'unresolved') return -1
|
||||
const details = memberDetails(member)
|
||||
const name = member.ref.name
|
||||
const update = this.getDelayUpdate(name, group)
|
||||
if (update && (update.delay >= 0 || update.delay === -2)) {
|
||||
return update.delay
|
||||
}
|
||||
|
||||
// 添加 history 属性的安全检查
|
||||
if (proxy.history && proxy.history.length > 0) {
|
||||
if (details?.history && details.history.length > 0) {
|
||||
// 0ms以error显示
|
||||
return proxy.history[proxy.history.length - 1].delay || 1e6
|
||||
return details.history[details.history.length - 1].delay || 1e6
|
||||
}
|
||||
return -1
|
||||
}
|
||||
@@ -215,11 +220,17 @@ class DelayManager {
|
||||
}
|
||||
|
||||
async checkDelay(
|
||||
name: string,
|
||||
member: InteractableProxyMember,
|
||||
group: string,
|
||||
timeout: number,
|
||||
providerName?: string,
|
||||
): Promise<DelayUpdate> {
|
||||
const name = member.ref.name
|
||||
const providerName =
|
||||
member.kind === 'node' ? providerNameOf(member.node) : undefined
|
||||
const apiName =
|
||||
member.kind === 'node' && member.node.source.kind === 'provider'
|
||||
? member.node.source.proxyName
|
||||
: name
|
||||
debugLog(
|
||||
`[DelayManager] 开始测试延迟,代理: ${name}, 组: ${group}, 超时: ${timeout}ms`,
|
||||
)
|
||||
@@ -240,7 +251,7 @@ class DelayManager {
|
||||
|
||||
// 使用Promise.race来实现超时控制
|
||||
const result = await Promise.race([
|
||||
this.unifiedDelayCheck(name, url, timeout, providerName),
|
||||
this.unifiedDelayCheck(apiName, url, timeout, providerName),
|
||||
timeoutPromise,
|
||||
])
|
||||
|
||||
@@ -267,7 +278,7 @@ class DelayManager {
|
||||
}
|
||||
|
||||
async checkListDelay(
|
||||
proxies: IProxyItem[],
|
||||
proxies: InteractableProxyMember[],
|
||||
group: string,
|
||||
timeout: number,
|
||||
concurrency = 36,
|
||||
@@ -275,7 +286,7 @@ class DelayManager {
|
||||
debugLog(
|
||||
`[DelayManager] 批量测试延迟开始,组: ${group}, 数量: ${proxies.length}, 并发数: ${concurrency}`,
|
||||
)
|
||||
const names = proxies.map((p) => p.name)
|
||||
const names = proxies.map((member) => member.ref.name)
|
||||
// 设置正在延迟测试中
|
||||
names.forEach((name) => {
|
||||
this.setDelay(name, group, -2)
|
||||
@@ -286,10 +297,9 @@ class DelayManager {
|
||||
const listener = this.groupListenerMap.get(group)
|
||||
|
||||
const help = async (): Promise<void> => {
|
||||
const currProxy = proxies[index++]
|
||||
if (!currProxy) return
|
||||
const currName = currProxy.name
|
||||
const currProviderName = currProxy.provider
|
||||
const currMember = proxies[index++]
|
||||
if (!currMember) return
|
||||
const currName = currMember.ref.name
|
||||
|
||||
try {
|
||||
// 确保API调用前状态为测试中
|
||||
@@ -303,7 +313,7 @@ class DelayManager {
|
||||
)
|
||||
}
|
||||
|
||||
await this.checkDelay(currName, group, timeout, currProviderName)
|
||||
await this.checkDelay(currMember, group, timeout)
|
||||
if (listener) {
|
||||
this.queueGroupNotification(group)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user