Open History to see the last commit
1import type { DesktopEnvironmentBootstrap } from "@t3tools/contracts";
2import { useEffect, useState } from "react";
3
4import { readDesktopSecondaryBootstraps } from "./desktopLocal";
5
6const DESKTOP_LOCAL_BOOTSTRAP_POLL_MS = 2_000;
7
8/**
9 * The bridge exposes no change event, so we re-read on an interval; failed
10 * reads retain the latest successful snapshot, while a successful empty read
11 * clears it.
12 */
13export function useDesktopLocalBootstraps(): ReadonlyArray<DesktopEnvironmentBootstrap> {
14 const [bootstraps, setBootstraps] = useState<ReadonlyArray<DesktopEnvironmentBootstrap>>(
15 readDesktopSecondaryBootstraps,
16 );
17
18 useEffect(() => {
19 const read = () => setBootstraps(readDesktopSecondaryBootstraps());
20 read();
21 const interval = setInterval(read, DESKTOP_LOCAL_BOOTSTRAP_POLL_MS);
22 return () => clearInterval(interval);
23 }, []);
24
25 return bootstraps;
26}