latency is now measured only when opening the proxy list

This commit is contained in:
coolcoala
2025-07-14 01:13:54 +03:00
parent 18b7366258
commit 25b295f2a8

View File

@@ -24,6 +24,7 @@ import { updateProxy, deleteConnection } from '@/services/api';
// --- Типы и константы --- // --- Типы и константы ---
const STORAGE_KEY_GROUP = 'clash-verge-selected-proxy-group'; const STORAGE_KEY_GROUP = 'clash-verge-selected-proxy-group';
const STORAGE_KEY_SORT_TYPE = 'clash-verge-proxy-sort-type'; const STORAGE_KEY_SORT_TYPE = 'clash-verge-proxy-sort-type';
const presetList = ["DIRECT", "REJECT", "REJECT-DROP", "PASS", "COMPATIBLE"];
type ProxySortType = 'default' | 'delay' | 'name'; type ProxySortType = 'default' | 'delay' | 'name';
interface IProxyGroup { interface IProxyGroup {
name: string; name: string;
@@ -36,8 +37,6 @@ interface IProxyGroup {
// --- Вспомогательная функция для цвета задержки --- // --- Вспомогательная функция для цвета задержки ---
function getDelayBadgeVariant(delayValue: number): 'default' | 'secondary' | 'destructive' | 'outline' { function getDelayBadgeVariant(delayValue: number): 'default' | 'secondary' | 'destructive' | 'outline' {
if (delayValue < 0) return 'secondary'; if (delayValue < 0) return 'secondary';
if (delayValue >= 10000) return 'destructive';
if (delayValue >= 500) return 'destructive';
if (delayValue >= 150) return 'destructive'; if (delayValue >= 150) return 'destructive';
return 'default'; return 'default';
} }
@@ -128,14 +127,26 @@ export const ProxySelectors: React.FC = () => {
} }
}, [selectedGroup, proxies, isGlobalMode, isDirectMode]); }, [selectedGroup, proxies, isGlobalMode, isDirectMode]);
useEffect(() => { const handleProxyListOpen = useCallback((isOpen: boolean) => {
if (!selectedGroup || !proxies?.groups || isGlobalMode || isDirectMode) return; if (!isOpen || isDirectMode) return;
const group = proxies.groups.find((g: IProxyGroup) => g.name === selectedGroup); const timeout = verge?.default_latency_timeout || 5000;
if (group && group.all) {
if (isGlobalMode) {
const proxyList = proxies?.global?.all;
if (proxyList) {
const proxyNames = proxyList
.map((p: any) => (typeof p === 'string' ? p : p.name))
.filter((name: string) => name && !presetList.includes(name));
delayManager.checkListDelay(proxyNames, 'GLOBAL', timeout);
}
} else {
const group = proxies?.groups?.find((g: IProxyGroup) => g.name === selectedGroup);
if (group && group.all) {
const proxyNames = group.all.map((p: any) => typeof p === 'string' ? p : p.name).filter(Boolean); const proxyNames = group.all.map((p: any) => typeof p === 'string' ? p : p.name).filter(Boolean);
const timeout = verge?.default_latency_timeout || 5000;
delayManager.checkListDelay(proxyNames, selectedGroup, timeout); delayManager.checkListDelay(proxyNames, selectedGroup, timeout);
}
} }
}, [selectedGroup, proxies, isGlobalMode, isDirectMode, verge]); }, [selectedGroup, proxies, isGlobalMode, isDirectMode, verge]);
@@ -255,7 +266,7 @@ export const ProxySelectors: React.FC = () => {
</Tooltip> </Tooltip>
</div> </div>
<Select value={selectedProxy} onValueChange={handleProxyChange} disabled={isDirectMode}> <Select value={selectedProxy} onValueChange={handleProxyChange} disabled={isDirectMode} onOpenChange={handleProxyListOpen}>
<SelectTrigger className="w-100"> <SelectTrigger className="w-100">
<Tooltip> <Tooltip>
<TooltipTrigger asChild> <TooltipTrigger asChild>