diff --git a/src/components/home/current-proxy-card.tsx b/src/components/home/current-proxy-card.tsx index 4b891a623..c0143f3a0 100644 --- a/src/components/home/current-proxy-card.tsx +++ b/src/components/home/current-proxy-card.tsx @@ -596,7 +596,7 @@ export const CurrentProxyCard = () => { [getProfileStorageKey], ) - const { handleSelectChange } = useProxySelection({ + const { select } = useProxySelection({ onSuccess: () => { refreshProxy() }, @@ -766,15 +766,9 @@ export const CurrentProxyCard = () => { const previousProxy = selectedGroup.now const nextName = option.member.ref.name // The profile selection is the durable source across core restarts and run modes. - handleSelectChange( - selectedGroup.name, - previousProxy!, - selectedGroup.fixed!, - )({ - target: { value: nextName }, - }) + select(selectedGroup.name, nextName, previousProxy!, selectedGroup.fixed!) }, - [handleSelectChange, isDirectMode, selectedGroup, unsortedProxyOptions], + [isDirectMode, select, selectedGroup, unsortedProxyOptions], ) const goToProxies = useCallback(() => { diff --git a/src/components/proxy/proxy-groups.tsx b/src/components/proxy/proxy-groups.tsx index 494fc551e..a5e07c6e4 100644 --- a/src/components/proxy/proxy-groups.tsx +++ b/src/components/proxy/proxy-groups.tsx @@ -462,7 +462,7 @@ function NormalProxyGroups(props: { mode: string }) { } }, [handleScroll]) - const { handleProxyGroupChange } = useProxySelection({ + const { select } = useProxySelection({ onSuccess: () => { onProxies() }, @@ -477,9 +477,9 @@ function NormalProxyGroups(props: { mode: string }) { if (!['Selector', 'URLTest', 'Fallback'].includes(group.type)) return if (!isInteractableMember(member)) return - handleProxyGroupChange(group, { name: member.ref.name }) + select(group.name, member.ref.name, group.now!, group.fixed!) }, - [handleProxyGroupChange], + [select], ) const handleLocation = useStableCallback((group: ProxyGroupView) => { diff --git a/src/hooks/use-proxy-selection.test.ts b/src/hooks/use-proxy-selection.test.ts index d176baf66..c382fc76f 100644 --- a/src/hooks/use-proxy-selection.test.ts +++ b/src/hooks/use-proxy-selection.test.ts @@ -35,8 +35,8 @@ it('applies and records independent group selections while another group is pend const secondSuccess = vi.fn() const first = useProxySelection({ onSuccess: firstSuccess }) const second = useProxySelection({ onSuccess: secondSuccess }) - first.changeProxy('Group A', 'Node A') - second.changeProxy('Group B', 'Node B') + first.select('Group A', 'Node A') + second.select('Group B', 'Node B') await vi.waitFor(() => expect(record).toHaveBeenCalledWith('Group B', 'Node B'), ) diff --git a/src/hooks/use-proxy-selection.ts b/src/hooks/use-proxy-selection.ts index 3b70daa82..d773ef361 100644 --- a/src/hooks/use-proxy-selection.ts +++ b/src/hooks/use-proxy-selection.ts @@ -35,7 +35,6 @@ const cleanupConnections = async (previousProxy: string) => { interface ProxySelectionOptions { onSuccess?: () => void onError?: (error: any) => void - enableConnectionCleanup?: boolean } interface ProxyChangeRequest { @@ -53,7 +52,7 @@ export const useProxySelection = (options: ProxySelectionOptions = {}) => { const pendingRequestRef = useRef(null) const isProcessingRef = useRef(false) - const { onSuccess, onError, enableConnectionCleanup = true } = options + const { onSuccess, onError } = options const autoCloseConnection = verge?.auto_close_connection ?? false @@ -98,7 +97,7 @@ export const useProxySelection = (options: ProxySelectionOptions = {}) => { ) } - if (enableConnectionCleanup && autoCloseConnection && previousProxy) { + if (autoCloseConnection && previousProxy) { void cleanupConnections(previousProxy) } } catch (error) { @@ -112,7 +111,6 @@ export const useProxySelection = (options: ProxySelectionOptions = {}) => { [ autoCloseConnection, forgetSelection, - enableConnectionCleanup, onError, onSuccess, recordSelection, @@ -138,7 +136,7 @@ export const useProxySelection = (options: ProxySelectionOptions = {}) => { } }, [executeChange]) - const changeProxy = useCallback( + const select = useCallback( ( groupName: string, proxyName: string, @@ -156,27 +154,5 @@ export const useProxySelection = (options: ProxySelectionOptions = {}) => { [flushChangeQueue], ) - const handleSelectChange = useCallback( - (groupName: string, previousProxy?: string, fixed?: string) => - (event: { target: { value: string } }) => { - changeProxy(groupName, event.target.value, previousProxy, fixed) - }, - [changeProxy], - ) - - const handleProxyGroupChange = useCallback( - ( - group: { name: string; now?: string | null; fixed?: string | null }, - proxy: { name: string }, - ) => { - changeProxy(group.name, proxy.name, group.now!, group.fixed!) - }, - [changeProxy], - ) - - return { - changeProxy, - handleSelectChange, - handleProxyGroupChange, - } + return { select } }