From 78fb15e327be91cae43063bddb46b77d9cc2163d Mon Sep 17 00:00:00 2001 From: Eduard Gert Date: Mon, 18 May 2026 10:39:32 +0200 Subject: [PATCH] update profile context --- .../src/modules/profile/ProfileContext.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/client/ui/frontend/src/modules/profile/ProfileContext.tsx b/client/ui/frontend/src/modules/profile/ProfileContext.tsx index 4131d7c6e..71ba18412 100644 --- a/client/ui/frontend/src/modules/profile/ProfileContext.tsx +++ b/client/ui/frontend/src/modules/profile/ProfileContext.tsx @@ -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(