update profile context

This commit is contained in:
Eduard Gert
2026-05-18 10:39:32 +02:00
parent 35e58a2796
commit 78fb15e327

View File

@@ -6,7 +6,7 @@ import {
useState,
type ReactNode,
} from "react";
import { Dialogs } from "@wailsio/runtime";
import { Dialogs, Events } from "@wailsio/runtime";
import {
Connection,
ProfileSwitcher,
@@ -15,6 +15,8 @@ import {
import type { Profile } from "@bindings/services/models.js";
import i18next from "@/lib/i18n";
const EVENT_PROFILE_CHANGED = "netbird:profile:changed";
type ProfileContextValue = {
username: string;
activeProfile: string;
@@ -65,6 +67,16 @@ export const ProfileProvider = ({ children }: { children: ReactNode }) => {
useEffect(() => {
refresh();
// The tray and other windows drive switches through the same
// ProfileSwitcher.SwitchActive RPC, which emits this event on success.
// Without the subscription, a tray-initiated switch leaves this
// window painting the old activeProfile until the next mount.
const off = Events.On(EVENT_PROFILE_CHANGED, () => {
void refresh();
});
return () => {
off();
};
}, [refresh]);
const switchProfile = useCallback(