Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions apps/web/src/kernel/servers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down
6 changes: 2 additions & 4 deletions apps/web/src/widgets/projects/projects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) });
Expand Down
Loading