MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / useDesktopUpdate

Function useDesktopUpdate

packages/react/src/hooks/desktop-update.ts:51–77  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

49 * once and the subscription effect always runs.
50 */
51export function useDesktopUpdate(): DesktopUpdate | null {
52 const bridge = useMemo(() => getDesktopUpdateBridge(), []);
53 const [status, setStatus] = useState<DesktopUpdateStatus>({ state: "idle" });
54
55 useEffect(() => {
56 if (!bridge) return;
57 let active = true;
58 // The initial snapshot is an async IPC round-trip; a push (e.g. download
59 // finished) can land first. Never let the stale snapshot overwrite a push
60 // that already arrived.
61 let receivedPush = false;
62 void bridge.getUpdateStatus().then((current) => {
63 if (active && !receivedPush) setStatus(current);
64 });
65 const unsubscribe = bridge.onUpdateStatus((next) => {
66 receivedPush = true;
67 setStatus(next);
68 });
69 return () => {
70 active = false;
71 unsubscribe();
72 };
73 }, [bridge]);
74
75 if (!bridge) return null;
76 return { status, install: () => void bridge.installUpdate() };
77}

Callers 1

SidebarUpdateCardFunction · 0.90

Calls 1

getDesktopUpdateBridgeFunction · 0.85

Tested by

no test coverage detected