ci / rust (push) Failing after 1m49s
A game-HUD-style debug overlay (FPS-counter for sessions) that surfaces the daemon-inferred fields from #18 — activity, foreground, idle time, status — on the active session, live off the existing events WS. Lets us validate the inferred data before designing any "real" UI, and stays useful as a permanent debugging tool. - Off by default; toggled via Ctrl+Shift+D (persisted in localStorage) or `?hud` in dev (debug.ts). - Fixed bottom-right overlay, pointer-events:none so it never blocks the terminal; activity value is color-coded (active/awaiting/idle). - Generic: renders every non-client-owned Session field, so a new daemon-derived field (#19 `detail`, later metrics) surfaces with no overlay change. Idle time re-renders on a 1s ticker; values update on SessionUpdated. - Pure consumer-side: no daemon/protocol/registry changes. The `?mock` fixture seeds varied activity so the HUD can be reviewed without a daemon. Closes #20 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
// Debug-HUD toggle (#20). Off by default; persisted in localStorage so it
|
|
// survives reloads, flipped by a keybind (Ctrl+Shift+D), and force-enabled by
|
|
// `?hud` in dev. A `maestro-hud-toggle` event lets the HUD re-render on change.
|
|
|
|
const STORAGE_KEY = "maestro:hud";
|
|
export const HUD_TOGGLE_EVENT = "maestro-hud-toggle";
|
|
|
|
/** Whether the debug HUD should be shown. */
|
|
export function isHudEnabled(): boolean {
|
|
if (import.meta.env.DEV && location.search.includes("hud")) return true;
|
|
try {
|
|
return localStorage.getItem(STORAGE_KEY) === "1";
|
|
} catch {
|
|
// Private-mode / storage-disabled: HUD just stays off.
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/** Persist the HUD on/off state and notify listeners. */
|
|
export function setHudEnabled(on: boolean): void {
|
|
try {
|
|
if (on) localStorage.setItem(STORAGE_KEY, "1");
|
|
else localStorage.removeItem(STORAGE_KEY);
|
|
} catch {
|
|
// ignore storage failures — the event still drives the in-memory HUD
|
|
}
|
|
window.dispatchEvent(new CustomEvent(HUD_TOGGLE_EVENT));
|
|
}
|
|
|
|
export function toggleHud(): void {
|
|
setHudEnabled(!isHudEnabled());
|
|
}
|
|
|
|
/** Global keybind: Ctrl+Shift+D toggles the debug HUD. */
|
|
export function installHudKeybind(): void {
|
|
window.addEventListener("keydown", (e) => {
|
|
if (e.ctrlKey && e.shiftKey && (e.key === "D" || e.key === "d")) {
|
|
e.preventDefault();
|
|
toggleHud();
|
|
}
|
|
});
|
|
}
|