mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-14 16:17:25 +00:00
feat(ui): show server version in sidebar connection status
Replace hardcoded "0.2.0" in WS connect response with the actual build-injected version. Wire server version through WS client → auth store → sidebar footer so it displays next to connection status.
This commit is contained in:
1 parent
2d9d8adb0c
commit
cb37383ccd
4 files changed
+19
-5
No files matched your search
@@ -272,7 +272,7 @@ func (r *MethodRouter) handleConnect(ctx context.Context, client *Client, req *p
|
||||
"sender_id": client.id,
|
||||
"server": map[string]any{
|
||||
"name": "goclaw",
|
||||
"version": "0.2.0",
|
||||
"version": r.server.version,
|
||||
},
|
||||
}))
|
||||
return
|
||||
@@ -301,7 +301,7 @@ func (r *MethodRouter) sendConnectResponse(ctx context.Context, client *Client,
|
||||
"cross_tenant": client.crossTenant,
|
||||
"server": map[string]any{
|
||||
"name": "goclaw",
|
||||
"version": "0.2.0",
|
||||
"version": r.server.version,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ export class WsClient {
|
||||
tenantName = "";
|
||||
tenantSlug = "";
|
||||
crossTenant = false;
|
||||
serverVersion = "";
|
||||
|
||||
private readonly maxReconnectDelay = 30_000;
|
||||
private readonly baseReconnectDelay = 1_000;
|
||||
@@ -206,6 +207,7 @@ export class WsClient {
|
||||
tenant_name?: string;
|
||||
tenant_slug?: string;
|
||||
cross_tenant?: boolean;
|
||||
server?: { name?: string; version?: string };
|
||||
}>("connect", {
|
||||
token: this.getToken(),
|
||||
user_id: this.getUserId(),
|
||||
@@ -238,6 +240,7 @@ export class WsClient {
|
||||
this.tenantName = res?.tenant_name ?? "";
|
||||
this.tenantSlug = res?.tenant_slug ?? "";
|
||||
this.crossTenant = res?.cross_tenant ?? false;
|
||||
this.serverVersion = res?.server?.version ?? "";
|
||||
this.onStateChange("connected");
|
||||
} catch (e) {
|
||||
if (this.connectGeneration === generation) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import { cn } from "@/lib/utils";
|
||||
export function ConnectionStatus({ collapsed }: { collapsed?: boolean }) {
|
||||
const { t } = useTranslation("common");
|
||||
const connected = useAuthStore((s) => s.connected);
|
||||
const serverVersion = useAuthStore((s) => s.serverInfo?.version);
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground overflow-hidden">
|
||||
@@ -15,7 +16,12 @@ export function ConnectionStatus({ collapsed }: { collapsed?: boolean }) {
|
||||
)}
|
||||
/>
|
||||
{!collapsed && (
|
||||
<span className="truncate">{connected ? t("connected") : t("disconnected")}</span>
|
||||
<span className="truncate">
|
||||
{connected ? t("connected") : t("disconnected")}
|
||||
{connected && serverVersion && (
|
||||
<span className="ml-1 opacity-60">· {serverVersion}</span>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -30,8 +30,13 @@ export function WsProvider({ children }: { children: React.ReactNode }) {
|
||||
() => useAuthStore.getState().senderID,
|
||||
(state: ConnectionState) => {
|
||||
const store = useAuthStore.getState();
|
||||
store.setConnected(state === "connected");
|
||||
if (state === "connected" && wsRef.current) {
|
||||
const isConnected = state === "connected";
|
||||
if (isConnected && wsRef.current) {
|
||||
store.setConnected(true, { version: wsRef.current.serverVersion });
|
||||
} else {
|
||||
store.setConnected(false);
|
||||
}
|
||||
if (isConnected && wsRef.current) {
|
||||
const client = wsRef.current;
|
||||
store.setRole(client.role || "");
|
||||
store.setTenant(client.tenantId, client.tenantName, client.tenantSlug, client.crossTenant);
|
||||
|
||||
Reference in new issue
Block a user