29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
import type { DesktopEnvironmentBootstrap } from "@t3tools/contracts";
|
|
import { useEffect, useState } from "react";
|
|
|
|
import { readDesktopSecondaryBootstraps } from "./desktopLocal";
|
|
|
|
const DESKTOP_LOCAL_BOOTSTRAP_POLL_MS = 2_000;
|
|
|
|
/**
|
|
* Reactively track the desktop's secondary local backends (e.g. a parallel WSL
|
|
* backend). The bridge exposes no change event, so we re-read on an interval;
|
|
* failed reads retain the latest successful snapshot, while a successful empty
|
|
* read clears it. Use this instead of polling the bridge ad hoc so every
|
|
* renderer consumer reads the same topology.
|
|
*/
|
|
export function useDesktopLocalBootstraps(): ReadonlyArray<DesktopEnvironmentBootstrap> {
|
|
const [bootstraps, setBootstraps] = useState<ReadonlyArray<DesktopEnvironmentBootstrap>>(
|
|
readDesktopSecondaryBootstraps,
|
|
);
|
|
|
|
useEffect(() => {
|
|
const read = () => setBootstraps(readDesktopSecondaryBootstraps());
|
|
read();
|
|
const interval = setInterval(read, DESKTOP_LOCAL_BOOTSTRAP_POLL_MS);
|
|
return () => clearInterval(interval);
|
|
}, []);
|
|
|
|
return bootstraps;
|
|
}
|