mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-27 07:40:05 +08:00
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:32095daf90Refs:bea0dde074
22 lines
714 B
TypeScript
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)
|
|
}
|
|
}, [])
|
|
}
|