mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 05:00:30 +08:00
support custom delay test concurrency
This commit is contained in:
parent
cfb37efb2a
commit
256fffae0b
@ -13,6 +13,7 @@ const MihomoConfig: React.FC = () => {
|
|||||||
const {
|
const {
|
||||||
controlDns = true,
|
controlDns = true,
|
||||||
controlSniff = true,
|
controlSniff = true,
|
||||||
|
delayTestConcurrency,
|
||||||
delayTestTimeout,
|
delayTestTimeout,
|
||||||
githubToken = '',
|
githubToken = '',
|
||||||
autoCloseConnection = true,
|
autoCloseConnection = true,
|
||||||
@ -56,6 +57,18 @@ const MihomoConfig: React.FC = () => {
|
|||||||
}}
|
}}
|
||||||
></Input>
|
></Input>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
|
<SettingItem title="延迟测试并发数量" divider>
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
size="sm"
|
||||||
|
className="w-[60%]"
|
||||||
|
value={delayTestConcurrency?.toString()}
|
||||||
|
placeholder="默认 50"
|
||||||
|
onValueChange={(v) => {
|
||||||
|
patchAppConfig({ delayTestConcurrency: parseInt(v) })
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</SettingItem>
|
||||||
<SettingItem title="延迟测试超时时间" divider>
|
<SettingItem title="延迟测试超时时间" divider>
|
||||||
<Input
|
<Input
|
||||||
type="number"
|
type="number"
|
||||||
|
|||||||
@ -1,12 +1,7 @@
|
|||||||
import { Avatar, Button, Card, CardBody, Chip } from '@nextui-org/react'
|
import { Avatar, Button, Card, CardBody, Chip } from '@nextui-org/react'
|
||||||
import BasePage from '@renderer/components/base/base-page'
|
import BasePage from '@renderer/components/base/base-page'
|
||||||
import { useAppConfig } from '@renderer/hooks/use-app-config'
|
import { useAppConfig } from '@renderer/hooks/use-app-config'
|
||||||
import {
|
import { mihomoChangeProxy, mihomoCloseAllConnections, mihomoProxyDelay } from '@renderer/utils/ipc'
|
||||||
mihomoChangeProxy,
|
|
||||||
mihomoCloseAllConnections,
|
|
||||||
mihomoGroupDelay,
|
|
||||||
mihomoProxyDelay
|
|
||||||
} from '@renderer/utils/ipc'
|
|
||||||
import { CgDetailsLess, CgDetailsMore } from 'react-icons/cg'
|
import { CgDetailsLess, CgDetailsMore } from 'react-icons/cg'
|
||||||
import { TbCircleLetterD } from 'react-icons/tb'
|
import { TbCircleLetterD } from 'react-icons/tb'
|
||||||
import { FaLocationCrosshairs } from 'react-icons/fa6'
|
import { FaLocationCrosshairs } from 'react-icons/fa6'
|
||||||
@ -27,7 +22,8 @@ const Proxies: React.FC = () => {
|
|||||||
proxyDisplayMode = 'simple',
|
proxyDisplayMode = 'simple',
|
||||||
proxyDisplayOrder = 'default',
|
proxyDisplayOrder = 'default',
|
||||||
autoCloseConnection = true,
|
autoCloseConnection = true,
|
||||||
proxyCols = 'auto'
|
proxyCols = 'auto',
|
||||||
|
delayTestConcurrency = 50
|
||||||
} = appConfig || {}
|
} = appConfig || {}
|
||||||
const [cols, setCols] = useState(1)
|
const [cols, setCols] = useState(1)
|
||||||
const [isOpen, setIsOpen] = useState(Array(groups.length).fill(false))
|
const [isOpen, setIsOpen] = useState(Array(groups.length).fill(false))
|
||||||
@ -79,18 +75,46 @@ const Proxies: React.FC = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onGroupDelay = async (index: number): Promise<void> => {
|
const onGroupDelay = async (index: number): Promise<void> => {
|
||||||
|
if (allProxies[index].length === 0) {
|
||||||
|
setIsOpen((prev) => {
|
||||||
|
const newOpen = [...prev]
|
||||||
|
newOpen[index] = true
|
||||||
|
return newOpen
|
||||||
|
})
|
||||||
|
}
|
||||||
setDelaying((prev) => {
|
setDelaying((prev) => {
|
||||||
const newDelaying = [...prev]
|
const newDelaying = [...prev]
|
||||||
newDelaying[index] = true
|
newDelaying[index] = true
|
||||||
return newDelaying
|
return newDelaying
|
||||||
})
|
})
|
||||||
await mihomoGroupDelay(groups[index].name, groups[index].testUrl)
|
// 限制并发数量
|
||||||
|
const result: Promise<void>[] = []
|
||||||
|
const runningList: Promise<void>[] = []
|
||||||
|
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) => {
|
setDelaying((prev) => {
|
||||||
const newDelaying = [...prev]
|
const newDelaying = [...prev]
|
||||||
newDelaying[index] = false
|
newDelaying[index] = false
|
||||||
return newDelaying
|
return newDelaying
|
||||||
})
|
})
|
||||||
mutate()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const calcCols = (): number => {
|
const calcCols = (): number => {
|
||||||
|
|||||||
1
src/shared/types.d.ts
vendored
1
src/shared/types.d.ts
vendored
@ -246,6 +246,7 @@ interface IAppConfig {
|
|||||||
sysProxy: ISysProxyConfig
|
sysProxy: ISysProxyConfig
|
||||||
maxLogDays: number
|
maxLogDays: number
|
||||||
userAgent?: string
|
userAgent?: string
|
||||||
|
delayTestConcurrency?: number
|
||||||
delayTestUrl?: string
|
delayTestUrl?: string
|
||||||
delayTestTimeout?: number
|
delayTestTimeout?: number
|
||||||
encryptedPassword?: number[]
|
encryptedPassword?: number[]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user