Files
clash-verge-rev/src/hooks/use-record-selection.ts
T
Tunglies 05a6e9a64f fix(proxy): unify node switching and connection cleanup (#8592)
Route frontend and tray node selections through the same backend flow for
selection, persistence, state refresh, and connection cleanup. Read the
group's previous selection before switching and preserve the original
rule of closing only connections whose chains contain that selection.

Run optional cleanup in the background and keep its failures separate
from successful selection. Remove redundant frontend effects and unused
IPC commands, and refresh the proxy view for every successful switch.

Refs: 32095daf90
Refs: bea0dde074
2026-11-09 14:28:44 +00:00

22 lines
714 B
TypeScript

import { useCallback } from 'react'
import { recordSelectedNode } from '@/services/cmds'
import { mutate } from '@/services/mutate'
/**
* Persists every group selection because core-local state is not durable across all run modes.
* Send only the changed pair so concurrent selections merge against fresh backend state.
*/
export const useRecordSelection = () => {
return useCallback(async (groupName: string, proxyName: string) => {
try {
await mutate(() => recordSelectedNode(groupName, proxyName), {
id: `persist-selected-node:${groupName}`,
errorNotice: false,
})
} catch (error) {
console.error('[Selection] 保存代理选择失败:', error)
}
}, [])
}