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
| 1 | import { hostFreezeNotice } from "@t3tools/client-runtime/connection"; |
| 2 | import { m } from "../i18n/messages"; |
| 3 | |
| 4 | import { appAtomRegistry } from "../rpc/atomRegistry"; |
| 5 | import { environmentSummaries } from "../state/presentation"; |
| 6 | import { environmentServerConfigsAtom } from "../state/server"; |
| 7 | import { toastManager } from "./ui/toast"; |
| 8 | |
| 9 | /** Tells the user why a host dropped, once per stall, when it reports one on reconnect. */ |
| 10 | export function startHostFreezeToasts(): () => void { |
| 11 | const shown = new Set<string>(); |
| 12 | return appAtomRegistry.subscribe( |
| 13 | environmentServerConfigsAtom, |
| 14 | (configs) => { |
| 15 | for (const [environmentId, config] of configs) { |
| 16 | const stall = config.lastEventLoopStall; |
| 17 | if (stall === undefined) continue; |
| 18 | const key = `${environmentId}:${stall.detectedAt}`; |
| 19 | if (shown.has(key)) continue; |
| 20 | shown.add(key); |
| 21 | const label = |
| 22 | appAtomRegistry |
| 23 | .get(environmentSummaries.identitiesAtom) |
| 24 | .find((identity) => identity.environmentId === environmentId)?.label ?? |
| 25 | config.environment.label; |
| 26 | const notice = hostFreezeNotice(label, stall, m); |
| 27 | if (notice !== null) { |
| 28 | toastManager.add({ type: "warning", ...notice }); |
| 29 | } |
| 30 | } |
| 31 | }, |
| 32 | { immediate: true }, |
| 33 | ); |
| 34 | } |