From fbe6cefbdb71091b03ff6e27662b654fdce65856 Mon Sep 17 00:00:00 2001 From: Slinetrac Date: Sun, 19 Oct 2025 16:00:45 +0800 Subject: [PATCH] fix: hover jump navigator --- .../proxy/proxy-group-navigator.tsx | 20 +++++++++++- src/components/proxy/proxy-groups.tsx | 32 ++++--------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/components/proxy/proxy-group-navigator.tsx b/src/components/proxy/proxy-group-navigator.tsx index 4999da49..c27750b5 100644 --- a/src/components/proxy/proxy-group-navigator.tsx +++ b/src/components/proxy/proxy-group-navigator.tsx @@ -1,5 +1,5 @@ import { Box, Button, Tooltip } from "@mui/material"; -import { useCallback, useMemo } from "react"; +import { useCallback, useMemo, useRef } from "react"; interface ProxyGroupNavigatorProps { proxyGroupNames: string[]; @@ -19,6 +19,8 @@ export const ProxyGroupNavigator = ({ proxyGroupNames, onGroupLocation, }: ProxyGroupNavigatorProps) => { + const lastHoveredRef = useRef(null); + const handleGroupClick = useCallback( (groupName: string) => { onGroupLocation(groupName); @@ -26,6 +28,19 @@ export const ProxyGroupNavigator = ({ [onGroupLocation], ); + const handleGroupHover = useCallback( + (groupName: string) => { + if (lastHoveredRef.current === groupName) return; + lastHoveredRef.current = groupName; + onGroupLocation(groupName); + }, + [onGroupLocation], + ); + + const handleButtonLeave = useCallback(() => { + lastHoveredRef.current = null; + }, []); + // 处理代理组数据,去重和排序 const processedGroups = useMemo(() => { return proxyGroupNames @@ -66,6 +81,9 @@ export const ProxyGroupNavigator = ({ size="small" variant="text" onClick={() => handleGroupClick(name)} + onMouseEnter={() => handleGroupHover(name)} + onFocus={() => handleGroupHover(name)} + onMouseLeave={handleButtonLeave} sx={{ minWidth: 28, minHeight: 28, diff --git a/src/components/proxy/proxy-groups.tsx b/src/components/proxy/proxy-groups.tsx index 25861183..535458af 100644 --- a/src/components/proxy/proxy-groups.tsx +++ b/src/components/proxy/proxy-groups.tsx @@ -13,16 +13,12 @@ import { useLockFn } from "ahooks"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { Virtuoso, type VirtuosoHandle } from "react-virtuoso"; -import useSWR from "swr"; import { delayGroup, healthcheckProxyProvider } from "tauri-plugin-mihomo-api"; import { useProxySelection } from "@/hooks/use-proxy-selection"; import { useVerge } from "@/hooks/use-verge"; import { useAppData } from "@/providers/app-data-context"; -import { - getRuntimeConfig, - updateProxyChainConfigInRuntime, -} from "@/services/cmds"; +import { updateProxyChainConfigInRuntime } from "@/services/cmds"; import delayManager from "@/services/delay"; import { BaseEmpty } from "../base"; @@ -347,22 +343,6 @@ export const ProxyGroups = (props: Props) => { } }; - // 获取运行时配置 - const { data: runtimeConfig } = useSWR("getRuntimeConfig", getRuntimeConfig, { - revalidateOnFocus: false, - revalidateIfStale: true, - }); - - // 获取所有代理组名称 - const getProxyGroupNames = useCallback(() => { - const config = runtimeConfig as any; - if (!config?.["proxy-groups"]) return []; - - return config["proxy-groups"] - .map((group: any) => group.name) - .filter((name: string) => name && name.trim() !== ""); - }, [runtimeConfig]); - // 定位到指定的代理组 const handleGroupLocationByName = useCallback( (groupName: string) => { @@ -381,10 +361,12 @@ export const ProxyGroups = (props: Props) => { [renderList], ); - const proxyGroupNames = useMemo( - () => getProxyGroupNames(), - [getProxyGroupNames], - ); + const proxyGroupNames = useMemo(() => { + const names = renderList + .filter((item) => item.type === 0 && item.group?.name) + .map((item) => item.group!.name); + return Array.from(new Set(names)); + }, [renderList]); if (mode === "direct") { return ;