From 256fffae0bc09ec36b3d4d00c6086818234adf98 Mon Sep 17 00:00:00 2001 From: pompurin404 Date: Mon, 23 Sep 2024 19:40:30 +0800 Subject: [PATCH] support custom delay test concurrency --- .../src/components/settings/mihomo-config.tsx | 13 ++++++ src/renderer/src/pages/proxies.tsx | 42 +++++++++++++++---- src/shared/types.d.ts | 1 + 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/renderer/src/components/settings/mihomo-config.tsx b/src/renderer/src/components/settings/mihomo-config.tsx index 66d00b1..f92aaff 100644 --- a/src/renderer/src/components/settings/mihomo-config.tsx +++ b/src/renderer/src/components/settings/mihomo-config.tsx @@ -13,6 +13,7 @@ const MihomoConfig: React.FC = () => { const { controlDns = true, controlSniff = true, + delayTestConcurrency, delayTestTimeout, githubToken = '', autoCloseConnection = true, @@ -56,6 +57,18 @@ const MihomoConfig: React.FC = () => { }} > + + { + patchAppConfig({ delayTestConcurrency: parseInt(v) }) + }} + /> + { proxyDisplayMode = 'simple', proxyDisplayOrder = 'default', autoCloseConnection = true, - proxyCols = 'auto' + proxyCols = 'auto', + delayTestConcurrency = 50 } = appConfig || {} const [cols, setCols] = useState(1) const [isOpen, setIsOpen] = useState(Array(groups.length).fill(false)) @@ -79,18 +75,46 @@ const Proxies: React.FC = () => { } const onGroupDelay = async (index: number): Promise => { + if (allProxies[index].length === 0) { + setIsOpen((prev) => { + const newOpen = [...prev] + newOpen[index] = true + return newOpen + }) + } setDelaying((prev) => { const newDelaying = [...prev] newDelaying[index] = true return newDelaying }) - await mihomoGroupDelay(groups[index].name, groups[index].testUrl) + // 限制并发数量 + const result: Promise[] = [] + const runningList: Promise[] = [] + for (const proxy of allProxies[index]) { + const promise = Promise.resolve().then(async () => { + try { + await mihomoProxyDelay(proxy.name, groups[index].testUrl) + } catch { + // ignore + } finally { + mutate() + } + }) + result.push(promise) + const running = promise.then(() => { + runningList.splice(runningList.indexOf(running), 1) + }) + runningList.push(running) + if (runningList.length >= (delayTestConcurrency || 50)) { + await Promise.race(runningList) + } + } + await Promise.all(result) setDelaying((prev) => { const newDelaying = [...prev] newDelaying[index] = false return newDelaying }) - mutate() } const calcCols = (): number => { diff --git a/src/shared/types.d.ts b/src/shared/types.d.ts index 6a553fd..43e016d 100644 --- a/src/shared/types.d.ts +++ b/src/shared/types.d.ts @@ -246,6 +246,7 @@ interface IAppConfig { sysProxy: ISysProxyConfig maxLogDays: number userAgent?: string + delayTestConcurrency?: number delayTestUrl?: string delayTestTimeout?: number encryptedPassword?: number[]