mirror of
https://github.com/pompurin404/mihomo-party.git
synced 2024-11-16 11:42:19 +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 React, { useEffect, useMemo, useState } from 'react'
|
||||
import PubSub from 'pubsub-js'
|
||||
import React, { useMemo, useState } from 'react'
|
||||
|
||||
interface Props {
|
||||
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
|
||||
|
||||
return (
|
||||
|
|
|
@ -6,6 +6,7 @@ import { IoMdRefresh } from 'react-icons/io'
|
|||
import { useSortable } from '@dnd-kit/sortable'
|
||||
import { CSS } from '@dnd-kit/utilities'
|
||||
import { useLocation, useNavigate } from 'react-router-dom'
|
||||
import PubSub from 'pubsub-js'
|
||||
import useSWR from 'swr'
|
||||
|
||||
const MihomoCoreCard: React.FC = () => {
|
||||
|
|
|
@ -7,6 +7,7 @@ import { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-c
|
|||
import { platform } from '@renderer/utils/init'
|
||||
import { FaNetworkWired } from 'react-icons/fa'
|
||||
import { IoMdCloudDownload } from 'react-icons/io'
|
||||
import PubSub from 'pubsub-js'
|
||||
import { mihomoUpgrade, restartCore, triggerSysProxy } from '@renderer/utils/ipc'
|
||||
import React, { useState } from 'react'
|
||||
import InterfaceModal from '@renderer/components/mihomo/interface-modal'
|
||||
|
|
|
@ -30,6 +30,7 @@ const Proxies: React.FC = () => {
|
|||
} = appConfig || {}
|
||||
const [cols, setCols] = useState(1)
|
||||
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 virtuosoRef = useRef<GroupedVirtuosoHandle>(null)
|
||||
const { groupCounts, allProxies } = useMemo(() => {
|
||||
|
@ -76,9 +77,19 @@ const Proxies: React.FC = () => {
|
|||
return await mihomoProxyDelay(proxy, url)
|
||||
}
|
||||
|
||||
const onGroupDelay = async (group: string, url?: string): Promise<void> => {
|
||||
PubSub.publish(`${group}-delay`)
|
||||
await mihomoGroupDelay(group, url)
|
||||
const onGroupDelay = async (index: number): Promise<void> => {
|
||||
setDelaying((prev) => {
|
||||
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 => {
|
||||
|
@ -267,10 +278,11 @@ const Proxies: React.FC = () => {
|
|||
<Button
|
||||
title="延迟测试"
|
||||
variant="light"
|
||||
isLoading={delaying[index]}
|
||||
size="sm"
|
||||
isIconOnly
|
||||
onPress={() => {
|
||||
onGroupDelay(groups[index].name, groups[index].testUrl)
|
||||
onGroupDelay(index)
|
||||
}}
|
||||
>
|
||||
<MdOutlineSpeed className="text-lg text-default-500" />
|
||||
|
|
Loading…
Reference in New Issue
Block a user