Merge branch 'dev' into refactor/mihomo-api

This commit is contained in:
oomeow
2025-10-01 09:33:56 +08:00
17 changed files with 564 additions and 380 deletions
+3 -1
View File
@@ -24,6 +24,8 @@ export const RuleItem = (props: Props) => {
const proxyPolicy = rule.match(/[^,]+$/)?.[0] ?? "";
const ruleContent = rule.slice(ruleType.length + 1, -proxyPolicy.length - 1);
const $sortable = useSortable({ id: ruleRaw });
const {
attributes,
listeners,
@@ -32,7 +34,7 @@ export const RuleItem = (props: Props) => {
transition,
isDragging,
} = sortable
? useSortable({ id: ruleRaw })
? $sortable
: {
attributes: {},
listeners: {},
@@ -0,0 +1,94 @@
import { Box, Button, Tooltip } from "@mui/material";
import { useCallback, useMemo } from "react";
interface ProxyGroupNavigatorProps {
proxyGroupNames: string[];
onGroupLocation: (groupName: string) => void;
}
// 提取代理组名的第一个字符
const getGroupDisplayChar = (groupName: string): string => {
if (!groupName) return "?";
// 直接返回第一个字符,支持表情符号
const firstChar = Array.from(groupName)[0];
return firstChar || "?";
};
export const ProxyGroupNavigator = ({
proxyGroupNames,
onGroupLocation,
}: ProxyGroupNavigatorProps) => {
const handleGroupClick = useCallback(
(groupName: string) => {
onGroupLocation(groupName);
},
[onGroupLocation],
);
// 处理代理组数据,去重和排序
const processedGroups = useMemo(() => {
return proxyGroupNames
.filter((name) => name && name.trim())
.map((name) => ({
name,
displayChar: getGroupDisplayChar(name),
}));
}, [proxyGroupNames]);
if (processedGroups.length === 0) {
return null;
}
return (
<Box
sx={{
position: "absolute",
right: 2,
top: "50%",
transform: "translateY(-50%)",
zIndex: 10,
display: "flex",
flexDirection: "column",
gap: 0.25,
bgcolor: "transparent",
borderRadius: 0.5,
boxShadow: 0,
p: 0.25,
maxHeight: "70vh",
overflowY: "auto",
minWidth: "auto",
}}
>
{processedGroups.map(({ name, displayChar }) => (
<Tooltip key={name} title={name} placement="left" arrow>
<Button
size="small"
variant="text"
onClick={() => handleGroupClick(name)}
sx={{
minWidth: 28,
minHeight: 28,
width: 28,
height: 28,
fontSize: "12px",
fontWeight: 600,
padding: 0,
borderRadius: 0.25,
color: "text.secondary",
textAlign: "center",
justifyContent: "center",
textTransform: "none",
"&:hover": {
bgcolor: "primary.light",
color: "primary.contrastText",
},
}}
>
{displayChar}
</Button>
</Tooltip>
))}
</Box>
);
};
+48
View File
@@ -25,6 +25,7 @@ import { ScrollTopButton } from "../layout/scroll-top-button";
import { ProxyChain } from "./proxy-chain";
import { ProxyRender } from "./proxy-render";
import { ProxyGroupNavigator } from "./proxy-group-navigator";
import { useRenderList } from "./use-render-list";
import { delayGroup, healthcheckProxyProvider } from "tauri-plugin-mihomo-api";
@@ -318,6 +319,45 @@ 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) => {
const index = renderList.findIndex(
(item) => item.type === 0 && item.group?.name === groupName,
);
if (index >= 0) {
virtuosoRef.current?.scrollToIndex?.({
index,
align: "start",
behavior: "smooth",
});
}
},
[renderList],
);
const proxyGroupNames = useMemo(
() => getProxyGroupNames(),
[getProxyGroupNames],
);
if (mode === "direct") {
return <BaseEmpty text={t("clash_mode_direct")} />;
}
@@ -514,6 +554,14 @@ export const ProxyGroups = (props: Props) => {
<div
style={{ position: "relative", height: "100%", willChange: "transform" }}
>
{/* 代理组导航栏 */}
{mode === "rule" && (
<ProxyGroupNavigator
proxyGroupNames={proxyGroupNames}
onGroupLocation={handleGroupLocationByName}
/>
)}
<Virtuoso
ref={virtuosoRef}
style={{ height: "calc(100% - 14px)" }}
+14 -10
View File
@@ -31,9 +31,15 @@ interface Props {
onHeadState: (val: Partial<HeadState>) => void;
}
export const ProxyHead = (props: Props) => {
const { sx = {}, url, groupName, headState, onHeadState } = props;
export const ProxyHead = ({
sx = {},
url,
groupName,
headState,
onHeadState,
onLocation,
onCheckDelay,
}: Props) => {
const { showType, sortType, filterText, textState, testUrl } = headState;
const { t } = useTranslation();
@@ -46,13 +52,11 @@ export const ProxyHead = (props: Props) => {
}, []);
const { verge } = useVerge();
const default_latency_test = verge!.default_latency_test!;
useEffect(() => {
delayManager.setUrl(
groupName,
testUrl || url || verge?.default_latency_test!,
);
}, [groupName, testUrl, verge?.default_latency_test]);
delayManager.setUrl(groupName, testUrl || url || default_latency_test);
}, [groupName, testUrl, default_latency_test, url]);
return (
<Box sx={{ display: "flex", alignItems: "center", gap: 0.5, ...sx }}>
@@ -60,7 +64,7 @@ export const ProxyHead = (props: Props) => {
size="small"
color="inherit"
title={t("locate")}
onClick={props.onLocation}
onClick={onLocation}
>
<MyLocationRounded />
</IconButton>
@@ -76,7 +80,7 @@ export const ProxyHead = (props: Props) => {
console.log(`[ProxyHead] 使用自定义测试URL: ${testUrl}`);
onHeadState({ textState: "url" });
}
props.onCheckDelay();
onCheckDelay();
}}
>
<NetworkCheckRounded />
+2 -2
View File
@@ -61,12 +61,12 @@ export const ProxyItem = (props: Props) => {
return () => {
delayManager.removeListener(proxy.name, group.name);
};
}, [proxy.name, group.name]);
}, [proxy.name, group.name, isPreset]);
useEffect(() => {
if (!proxy) return;
setDelay(delayManager.getDelayFix(proxy, group.name));
}, [proxy]);
}, [group.name, proxy]);
const onDelay = useLockFn(async () => {
setDelay(-2);
+2 -2
View File
@@ -11,7 +11,7 @@ export default function useFilterSort(
filterText: string,
sortType: ProxySortType,
) {
const [refresh, setRefresh] = useState({});
const [, setRefresh] = useState({});
useEffect(() => {
let last = 0;
@@ -34,7 +34,7 @@ export default function useFilterSort(
const fp = filterProxies(proxies, groupName, filterText);
const sp = sortProxies(fp, groupName, sortType);
return sp;
}, [proxies, groupName, filterText, sortType, refresh]);
}, [proxies, groupName, filterText, sortType]);
}
export function filterSort(
+2 -4
View File
@@ -90,13 +90,11 @@ export const HotkeyInput = (props: Props) => {
<div className="list">
{keys.map((key, index) => (
<Box display="flex">
<Box display="flex" key={key}>
<span className="delimiter" hidden={index === 0}>
+
</span>
<div key={key} className="item">
{key}
</div>
<div className="item">{key}</div>
</Box>
))}
</div>
@@ -59,13 +59,13 @@ const SettingVergeAdvanced = ({ onError: _ }: Props) => {
const onExportDiagnosticInfo = useCallback(async () => {
await exportDiagnosticInfo();
showNotice("success", t("Copy Success"), 1000);
}, []);
}, [t]);
const copyVersion = useCallback(() => {
navigator.clipboard.writeText(`v${version}`).then(() => {
showNotice("success", t("Version copied to clipboard"), 1000);
});
}, [version, t]);
}, [t]);
return (
<SettingList title={t("Verge Advanced Setting")}>
@@ -77,7 +77,7 @@ const SettingVergeBasic = ({ onError }: Props) => {
const onCopyClashEnv = useCallback(async () => {
await copyClashEnv();
showNotice("success", t("Copy Success"), 1000);
}, []);
}, [t]);
return (
<SettingList title={t("Verge Basic Setting")}>