[client/ui] Unify profile-switching logic in ProfileSwitcher service

Both the tray and the React Profiles page previously had separate
switching logic: the tray applied a status-aware reconnect policy
(Down for error states, Up only when previously Connected/Connecting),
while the React page always called Switch + Up unconditionally with no
Down for LoginFailed/NeedsLogin/SessionExpired.

Introduce a single ProfileSwitcher service that encapsulates the full
reconnect policy. SwitchActive queries the current daemon status, calls
Switch, and launches Down/Up in a background goroutine so the caller
returns immediately after the Switch RPC completes. Both the tray and
the React Profiles page now delegate to this service.

Export the daemon status string constants (StatusConnected, etc.) from
the services package so tray.go no longer duplicates them as private
constants.
This commit is contained in:
Zoltan Papp
2026-05-13 15:46:00 +02:00
parent c0cd88a3d0
commit 803144e569
23 changed files with 2463 additions and 1521 deletions

View File

@@ -3,6 +3,7 @@ import { Plus, RefreshCw } from "lucide-react";
import {
Profiles as ProfilesSvc,
Connection,
ProfileSwitcher,
} from "../../bindings/github.com/netbirdio/netbird/client/ui/services";
import type { Profile } from "../../bindings/github.com/netbirdio/netbird/client/ui/services/models.js";
import { Button } from "../components/Button";
@@ -33,8 +34,7 @@ export default function Profiles() {
const select = async (name: string) => {
try {
await ProfilesSvc.Switch({ profileName: name, username });
await Connection.Up({ profileName: name, username });
await ProfileSwitcher.SwitchActive({ profileName: name, username });
await refresh();
} catch (e) {
setError(String(e));