update stuff

This commit is contained in:
Eduard Gert
2026-05-13 16:28:51 +02:00
parent 83030dbbd6
commit 1932b76f5b
24 changed files with 702 additions and 375 deletions
+23 -14
View File
@@ -1,4 +1,4 @@
import { useEffect, useState } from "react";
import { useCallback, useEffect, useState } from "react";
import { Events } from "@wailsio/runtime";
import { Peers } from "@bindings/services";
import type { Status } from "@bindings/services/models.js";
@@ -6,20 +6,30 @@ import type { Status } from "@bindings/services/models.js";
const EVENT_STATUS = "netbird:status";
// useStatus loads the current daemon status once and re-renders whenever the
// peers service emits a fresh snapshot over the Wails event bus.
export function useStatus(): { status: Status | null; error: string | null } {
// peers service emits a fresh snapshot over the Wails event bus. Callers can
// also force a manual refresh (e.g. right after Connection.Up/Down) so the
// view never lags behind a user action even if the daemon event stream is
// briefly silent.
export function useStatus(): {
status: Status | null;
error: string | null;
refresh: () => Promise<void>;
} {
const [status, setStatus] = useState<Status | null>(null);
const [error, setError] = useState<string | null>(null);
const refresh = useCallback(async () => {
try {
const s = await Peers.Get();
setStatus(s);
setError(null);
} catch (e) {
setError(String(e));
}
}, []);
useEffect(() => {
let cancelled = false;
Peers.Get()
.then((s) => {
if (!cancelled) setStatus(s);
})
.catch((e: unknown) => {
if (!cancelled) setError(String(e));
});
void refresh();
const off = Events.On(EVENT_STATUS, (ev: { data: Status }) => {
setStatus(ev.data);
@@ -27,10 +37,9 @@ export function useStatus(): { status: Status | null; error: string | null } {
});
return () => {
cancelled = true;
off();
};
}, []);
}, [refresh]);
return { status, error };
return { status, error, refresh };
}