From b894d9c18e880b504ab996a240ff3003679c7ed7 Mon Sep 17 00:00:00 2001 From: prem315 <8848429+prem315@users.noreply.github.com> Date: Sun, 1 Nov 2026 14:34:58 +0530 Subject: [PATCH] fix(desktop): refresh sessions when server home changes --- apps/web/src/kernel/servers.ts | 14 ++++++++------ apps/web/src/widgets/projects/projects.tsx | 6 ++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apps/web/src/kernel/servers.ts b/apps/web/src/kernel/servers.ts index ada99e74..9a902769 100644 --- a/apps/web/src/kernel/servers.ts +++ b/apps/web/src/kernel/servers.ts @@ -50,18 +50,20 @@ export function problemOf(status: ServerStatus): Problem | undefined { /** * Every server's status, as the app server last checked it, kept current as it checks again. When - * the default server becomes usable, whatever failed while it was not loads again. + * the default server becomes usable or its home changes, its queries load again. */ export const serversAtom = Server.runtime .atom( Stream.suspend(() => { - let wasUsable: boolean | undefined; + let previous: { readonly home: string | undefined; readonly usable: boolean } | undefined; return Stream.unwrap(Server.use((client) => Effect.succeed(client("servers.watch", undefined)))).pipe( Stream.tap((statuses) => { - const now = statuses.some((status) => status.isDefault && problemOf(status) === undefined); - const recovered = wasUsable === false && now; - wasUsable = now; - return recovered ? Reactivity.invalidate(codeworkKey) : Effect.void; + const current = statuses.find((status) => status.isDefault); + const home = current?.home.path; + const usable = current !== undefined && problemOf(current) === undefined; + const refresh = usable && previous !== undefined && (!previous.usable || previous.home !== home); + previous = { home, usable }; + return refresh ? Reactivity.invalidate(codeworkKey) : Effect.void; }), // The app server is local, so a dropped stream is only a moment's gap. Stream.retry(Schedule.spaced("1 second")), diff --git a/apps/web/src/widgets/projects/projects.tsx b/apps/web/src/widgets/projects/projects.tsx index 359c9009..46c720c1 100644 --- a/apps/web/src/widgets/projects/projects.tsx +++ b/apps/web/src/widgets/projects/projects.tsx @@ -5,15 +5,13 @@ import type { MouseEvent } from "react"; import { isMac, openMode, useShell } from "@codeworksh/widget/view"; -import { Server } from "../../kernel/rpc"; import { sessionAddress } from "../session/address"; +import { projectsAtom } from "../session/projects"; import { ago } from "../time"; -const list = Server.query("projects.list", undefined); - export function Projects() { const shell = useShell(); - const result = useAtomValue(list); + const result = useAtomValue(projectsAtom); // Primary and middle clicks open; a right click is left to the context menu. const open = (id: string, event: MouseEvent) => { if (event.button <= 1) shell.open(sessionAddress(id), { mode: openMode(event) });