@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 26 lines 1.03 KB
Raw
1 import { useAtomValue } from "@effect/atom-react";
2 import type { DesktopEnvironmentBootstrap } from "@t3tools/contracts";
3 import { Atom } from "effect/reactivity";
4
5 import { readDesktopSecondaryBootstraps } from "./desktopLocal";
6
7 const DESKTOP_LOCAL_BOOTSTRAP_POLL_MS = 2_000;
8
9 /**
10 * The bridge exposes no change event, so this re-reads on an interval while
11 * anything reads it; failed reads retain the latest successful snapshot, while
12 * a successful empty read clears it. The reader returns the same array while
13 * nothing changed, so an unchanged poll notifies no one.
14 */
15 const desktopLocalBootstrapsAtom = Atom.make((get) => {
16 const interval = setInterval(
17 () => get.setSelf(readDesktopSecondaryBootstraps()),
18 DESKTOP_LOCAL_BOOTSTRAP_POLL_MS,
19 );
20 get.addFinalizer(() => clearInterval(interval));
21 return readDesktopSecondaryBootstraps();
22 }).pipe(Atom.withLabel("desktop-local-bootstraps"));
23
24 export function useDesktopLocalBootstraps(): ReadonlyArray<DesktopEnvironmentBootstrap> {
25 return useAtomValue(desktopLocalBootstrapsAtom);
26 }