mirror of
https://github.com/netbirdio/netbird.git
synced 2026-05-20 23:59:55 +00:00
update profile context
This commit is contained in:
@@ -6,7 +6,7 @@ import {
|
|||||||
useState,
|
useState,
|
||||||
type ReactNode,
|
type ReactNode,
|
||||||
} from "react";
|
} from "react";
|
||||||
import { Dialogs } from "@wailsio/runtime";
|
import { Dialogs, Events } from "@wailsio/runtime";
|
||||||
import {
|
import {
|
||||||
Connection,
|
Connection,
|
||||||
ProfileSwitcher,
|
ProfileSwitcher,
|
||||||
@@ -15,6 +15,8 @@ import {
|
|||||||
import type { Profile } from "@bindings/services/models.js";
|
import type { Profile } from "@bindings/services/models.js";
|
||||||
import i18next from "@/lib/i18n";
|
import i18next from "@/lib/i18n";
|
||||||
|
|
||||||
|
const EVENT_PROFILE_CHANGED = "netbird:profile:changed";
|
||||||
|
|
||||||
type ProfileContextValue = {
|
type ProfileContextValue = {
|
||||||
username: string;
|
username: string;
|
||||||
activeProfile: string;
|
activeProfile: string;
|
||||||
@@ -65,6 +67,16 @@ export const ProfileProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
refresh();
|
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]);
|
}, [refresh]);
|
||||||
|
|
||||||
const switchProfile = useCallback(
|
const switchProfile = useCallback(
|
||||||
|
|||||||
Reference in New Issue
Block a user