mirror of
https://github.com/pompurin404/mihomo-party.git
synced 2024-11-15 19:22:31 +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 {
|
||||
controlDns = true,
|
||||
controlSniff = true,
|
||||
delayTestConcurrency,
|
||||
delayTestTimeout,
|
||||
githubToken = '',
|
||||
autoCloseConnection = true,
|
||||
|
@ -56,6 +57,18 @@ const MihomoConfig: React.FC = () => {
|
|||
}}
|
||||
></Input>
|
||||
</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>
|
||||
<Input
|
||||
type="number"
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
import { Avatar, Button, Card, CardBody, Chip } from '@nextui-org/react'
|
||||
import BasePage from '@renderer/components/base/base-page'
|
||||
import { useAppConfig } from '@renderer/hooks/use-app-config'
|
||||
import {
|
||||
mihomoChangeProxy,
|
||||
mihomoCloseAllConnections,
|
||||
mihomoGroupDelay,
|
||||
mihomoProxyDelay
|
||||
} from '@renderer/utils/ipc'
|
||||
import { mihomoChangeProxy, mihomoCloseAllConnections, mihomoProxyDelay } from '@renderer/utils/ipc'
|
||||
import { CgDetailsLess, CgDetailsMore } from 'react-icons/cg'
|
||||
import { TbCircleLetterD } from 'react-icons/tb'
|
||||
import { FaLocationCrosshairs } from 'react-icons/fa6'
|
||||
|
@ -27,7 +22,8 @@ const Proxies: React.FC = () => {
|
|||
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<void> => {
|
||||
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<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) => {
|
||||
const newDelaying = [...prev]
|
||||
newDelaying[index] = false
|
||||
return newDelaying
|
||||
})
|
||||
mutate()
|
||||
}
|
||||
|
||||
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
|
||||
maxLogDays: number
|
||||
userAgent?: string
|
||||
delayTestConcurrency?: number
|
||||
delayTestUrl?: string
|
||||
delayTestTimeout?: number
|
||||
encryptedPassword?: number[]
|
||||
|
|
Loading…
Reference in New Issue
Block a user