mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
fix: use verge hook
This commit is contained in:
@@ -1,12 +1,6 @@
|
||||
import { useRef } from "react";
|
||||
import { useLockFn } from "ahooks";
|
||||
import {
|
||||
Box,
|
||||
Divider,
|
||||
ListItem,
|
||||
ListItemText,
|
||||
Typography,
|
||||
} from "@mui/material";
|
||||
import { Box, ListItem, ListItemText, Typography } from "@mui/material";
|
||||
import { Virtuoso, type VirtuosoHandle } from "react-virtuoso";
|
||||
import {
|
||||
ExpandLessRounded,
|
||||
@@ -21,7 +15,7 @@ import {
|
||||
deleteConnection,
|
||||
} from "@/services/api";
|
||||
import { useProfiles } from "@/hooks/use-profiles";
|
||||
import { useVergeConfig } from "@/hooks/use-verge-config";
|
||||
import { useVerge } from "@/hooks/use-verge";
|
||||
import { useRenderList, type IRenderItem } from "./use-render-list";
|
||||
import { HeadState } from "./use-head-state";
|
||||
import { ProxyHead } from "./proxy-head";
|
||||
@@ -37,7 +31,7 @@ export const ProxyGroups = (props: Props) => {
|
||||
|
||||
const { renderList, onProxies, onHeadState } = useRenderList(mode);
|
||||
|
||||
const { data: vergeConfig } = useVergeConfig();
|
||||
const { verge } = useVerge();
|
||||
const { current, patchCurrent } = useProfiles();
|
||||
|
||||
const virtuosoRef = useRef<VirtuosoHandle>(null);
|
||||
@@ -52,7 +46,7 @@ export const ProxyGroups = (props: Props) => {
|
||||
onProxies();
|
||||
|
||||
// 断开连接
|
||||
if (vergeConfig?.auto_close_connection) {
|
||||
if (verge?.auto_close_connection) {
|
||||
getConnections().then(({ connections }) => {
|
||||
connections.forEach((conn) => {
|
||||
if (conn.chains.includes(now!)) {
|
||||
|
||||
@@ -14,10 +14,10 @@ import {
|
||||
SortByAlphaRounded,
|
||||
SortRounded,
|
||||
} from "@mui/icons-material";
|
||||
import { useVergeConfig } from "@/hooks/use-verge-config";
|
||||
import delayManager from "@/services/delay";
|
||||
import { useVerge } from "@/hooks/use-verge";
|
||||
import type { HeadState } from "./use-head-state";
|
||||
import type { ProxySortType } from "./use-filter-sort";
|
||||
import delayManager from "@/services/delay";
|
||||
|
||||
interface Props {
|
||||
sx?: SxProps;
|
||||
@@ -42,14 +42,11 @@ export const ProxyHead = (props: Props) => {
|
||||
return () => clearTimeout(timer);
|
||||
}, []);
|
||||
|
||||
const { data: vergeConfig } = useVergeConfig();
|
||||
const { verge } = useVerge();
|
||||
|
||||
useEffect(() => {
|
||||
delayManager.setUrl(
|
||||
groupName,
|
||||
testUrl || vergeConfig?.default_latency_test!
|
||||
);
|
||||
}, [groupName, testUrl, vergeConfig?.default_latency_test]);
|
||||
delayManager.setUrl(groupName, testUrl || verge?.default_latency_test!);
|
||||
}, [groupName, testUrl, verge?.default_latency_test]);
|
||||
|
||||
return (
|
||||
<Box sx={{ display: "flex", alignItems: "center", ...sx }}>
|
||||
|
||||
@@ -24,61 +24,6 @@ export const DEFAULT_STATE: HeadState = {
|
||||
testUrl: "",
|
||||
};
|
||||
|
||||
export default function useHeadState(groupName: string) {
|
||||
const current = useRecoilValue(atomCurrentProfile);
|
||||
|
||||
const [state, setState] = useState<HeadState>(DEFAULT_STATE);
|
||||
|
||||
useEffect(() => {
|
||||
if (!current) {
|
||||
setState(DEFAULT_STATE);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const data = JSON.parse(
|
||||
localStorage.getItem(HEAD_STATE_KEY)!
|
||||
) as HeadStateStorage;
|
||||
|
||||
const value = data[current][groupName] || DEFAULT_STATE;
|
||||
|
||||
if (value && typeof value === "object") {
|
||||
setState({ ...DEFAULT_STATE, ...value });
|
||||
} else {
|
||||
setState(DEFAULT_STATE);
|
||||
}
|
||||
} catch {}
|
||||
}, [current, groupName]);
|
||||
|
||||
const setHeadState = useCallback(
|
||||
(obj: Partial<HeadState>) => {
|
||||
setState((old) => {
|
||||
const ret = { ...old, ...obj };
|
||||
|
||||
setTimeout(() => {
|
||||
try {
|
||||
const item = localStorage.getItem(HEAD_STATE_KEY);
|
||||
|
||||
let data = (item ? JSON.parse(item) : {}) as HeadStateStorage;
|
||||
|
||||
if (!data || typeof data !== "object") data = {};
|
||||
if (!data[current]) data[current] = {};
|
||||
|
||||
data[current][groupName] = ret;
|
||||
|
||||
localStorage.setItem(HEAD_STATE_KEY, JSON.stringify(data));
|
||||
} catch {}
|
||||
});
|
||||
|
||||
return ret;
|
||||
});
|
||||
},
|
||||
[current, groupName]
|
||||
);
|
||||
|
||||
return [state, setHeadState] as const;
|
||||
}
|
||||
|
||||
export function useHeadStateNew() {
|
||||
const current = useRecoilValue(atomCurrentProfile);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user