mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 21:20:29 +08:00
optimized delay logic
This commit is contained in:
parent
035d573d88
commit
1cbae3a510
@ -1,6 +1,5 @@
|
|||||||
import { Button, Card, CardBody } from '@nextui-org/react'
|
import { Button, Card, CardBody } from '@nextui-org/react'
|
||||||
import React, { useEffect, useMemo, useState } from 'react'
|
import React, { useMemo, useState } from 'react'
|
||||||
import PubSub from 'pubsub-js'
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
mutateProxies: () => void
|
mutateProxies: () => void
|
||||||
@ -45,13 +44,6 @@ const ProxyItem: React.FC<Props> = (props) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const token = PubSub.subscribe(`${group.name}-delay`, onDelay)
|
|
||||||
|
|
||||||
return (): void => {
|
|
||||||
PubSub.unsubscribe(token)
|
|
||||||
}
|
|
||||||
}, [])
|
|
||||||
const fixed = group.fixed && group.fixed === proxy.name
|
const fixed = group.fixed && group.fixed === proxy.name
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import { IoMdRefresh } from 'react-icons/io'
|
|||||||
import { useSortable } from '@dnd-kit/sortable'
|
import { useSortable } from '@dnd-kit/sortable'
|
||||||
import { CSS } from '@dnd-kit/utilities'
|
import { CSS } from '@dnd-kit/utilities'
|
||||||
import { useLocation, useNavigate } from 'react-router-dom'
|
import { useLocation, useNavigate } from 'react-router-dom'
|
||||||
|
import PubSub from 'pubsub-js'
|
||||||
import useSWR from 'swr'
|
import useSWR from 'swr'
|
||||||
|
|
||||||
const MihomoCoreCard: React.FC = () => {
|
const MihomoCoreCard: React.FC = () => {
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-c
|
|||||||
import { platform } from '@renderer/utils/init'
|
import { platform } from '@renderer/utils/init'
|
||||||
import { FaNetworkWired } from 'react-icons/fa'
|
import { FaNetworkWired } from 'react-icons/fa'
|
||||||
import { IoMdCloudDownload } from 'react-icons/io'
|
import { IoMdCloudDownload } from 'react-icons/io'
|
||||||
|
import PubSub from 'pubsub-js'
|
||||||
import { mihomoUpgrade, restartCore, triggerSysProxy } from '@renderer/utils/ipc'
|
import { mihomoUpgrade, restartCore, triggerSysProxy } from '@renderer/utils/ipc'
|
||||||
import React, { useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
import InterfaceModal from '@renderer/components/mihomo/interface-modal'
|
import InterfaceModal from '@renderer/components/mihomo/interface-modal'
|
||||||
|
|||||||
@ -30,6 +30,7 @@ const Proxies: React.FC = () => {
|
|||||||
} = 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))
|
||||||
|
const [delaying, setDelaying] = useState(Array(groups.length).fill(false))
|
||||||
const [searchValue, setSearchValue] = useState(Array(groups.length).fill(''))
|
const [searchValue, setSearchValue] = useState(Array(groups.length).fill(''))
|
||||||
const virtuosoRef = useRef<GroupedVirtuosoHandle>(null)
|
const virtuosoRef = useRef<GroupedVirtuosoHandle>(null)
|
||||||
const { groupCounts, allProxies } = useMemo(() => {
|
const { groupCounts, allProxies } = useMemo(() => {
|
||||||
@ -76,9 +77,19 @@ const Proxies: React.FC = () => {
|
|||||||
return await mihomoProxyDelay(proxy, url)
|
return await mihomoProxyDelay(proxy, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onGroupDelay = async (group: string, url?: string): Promise<void> => {
|
const onGroupDelay = async (index: number): Promise<void> => {
|
||||||
PubSub.publish(`${group}-delay`)
|
setDelaying((prev) => {
|
||||||
await mihomoGroupDelay(group, url)
|
const newDelaying = [...prev]
|
||||||
|
newDelaying[index] = true
|
||||||
|
return newDelaying
|
||||||
|
})
|
||||||
|
await mihomoGroupDelay(groups[index].name, groups[index].testUrl)
|
||||||
|
setDelaying((prev) => {
|
||||||
|
const newDelaying = [...prev]
|
||||||
|
newDelaying[index] = false
|
||||||
|
return newDelaying
|
||||||
|
})
|
||||||
|
mutate()
|
||||||
}
|
}
|
||||||
|
|
||||||
const calcCols = (): number => {
|
const calcCols = (): number => {
|
||||||
@ -267,10 +278,11 @@ const Proxies: React.FC = () => {
|
|||||||
<Button
|
<Button
|
||||||
title="延迟测试"
|
title="延迟测试"
|
||||||
variant="light"
|
variant="light"
|
||||||
|
isLoading={delaying[index]}
|
||||||
size="sm"
|
size="sm"
|
||||||
isIconOnly
|
isIconOnly
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
onGroupDelay(groups[index].name, groups[index].testUrl)
|
onGroupDelay(index)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<MdOutlineSpeed className="text-lg text-default-500" />
|
<MdOutlineSpeed className="text-lg text-default-500" />
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user