From 8e21c795dd712ecddd748d02276532041a2796a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20=C5=9Al=C4=99zak?= Date: Wed, 5 Aug 2026 16:56:54 +0200 Subject: [PATCH] fix tunnel events fix disconnect tunnel from connection watcher --- .../ConnectionWatcher/ConnectionsWatcher.tsx | 37 +++++++++++++++---- .../shared/providers/TauriEventProvider.tsx | 2 + 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/new-ui/src/shared/components/WindowHeader/components/ConnectionWatcher/ConnectionsWatcher.tsx b/new-ui/src/shared/components/WindowHeader/components/ConnectionWatcher/ConnectionsWatcher.tsx index 99a9c687e..7a1ab3b99 100644 --- a/new-ui/src/shared/components/WindowHeader/components/ConnectionWatcher/ConnectionsWatcher.tsx +++ b/new-ui/src/shared/components/WindowHeader/components/ConnectionWatcher/ConnectionsWatcher.tsx @@ -14,7 +14,8 @@ import { } from '@floating-ui/react'; import { useMutation, useQuery } from '@tanstack/react-query'; import clsx from 'clsx'; -import { useEffect, useState } from 'react'; +import { useEffect, useMemo, useState } from 'react'; +import { Snackbar } from '../../../../providers/snackbar/snackbar'; import { api } from '../../../../rust-api/api'; import { Direction, ThemeSpacing, ThemeVariable } from '../../../../types'; import { isPresent } from '../../../../utils/isPresent'; @@ -28,7 +29,10 @@ type Props = { export const ConnectionWatcher = ({ placement = 'bottom-start' }: Props) => { const { mutate: disconnect } = useMutation({ - mutationFn: api.disconnectLocations, + mutationFn: api.disconnect, + onError: () => { + Snackbar.error('Failed to disconnect.'); + }, }); const { data: connections } = useQuery({ @@ -41,6 +45,25 @@ export const ConnectionWatcher = ({ placement = 'bottom-start' }: Props) => { const [floatingOpen, setFloatingOpen] = useState(false); + const disconnectAllPromise = useMemo(() => { + return () => + Promise.all( + (connections ?? []).map((connection) => + api.disconnect({ + locationId: connection.id, + connectionType: connection.connection_type, + }), + ), + ); + }, [connections]); + + const { mutate: disconnectAll } = useMutation({ + mutationFn: disconnectAllPromise, + onError: () => { + Snackbar.error('Failed to disconnect all locations.'); + }, + }); + useEffect(() => { if (!connected) { setFloatingOpen(false); @@ -114,7 +137,10 @@ export const ConnectionWatcher = ({ placement = 'bottom-start' }: Props) => { className="connection" key={con.id} onClick={() => { - disconnect([con.id]); + disconnect({ + locationId: con.id, + connectionType: con.connection_type, + }); }} > {