import type { HudFrame } from '../core/hud.ts'; import type { DeviceEvent } from './events.ts'; export type StorageRead = { ok: true; value: string } | { ok: false }; /** Everything Hermeven needs from the glasses runtime. Implemented by the Even adapter and by test fakes. */ export interface DevicePort { /** Create the HUD page. Resolves false when the host refused it. */ init(frame: HudFrame): Promise; /** Show a frame. Calls are serialised and coalesced; only the latest pending frame is sent. */ show(frame: HudFrame): void; /** Open the glasses microphone. Resolves false when the host refused (for example no permission). */ startMic(): Promise; stopMic(): Promise; onEvent(listener: (event: DeviceEvent) => void): () => void; onConnection(listener: (connected: boolean) => void): () => void; /** Ask the OS to show its own exit confirmation. */ requestExit(): Promise; /** * Leave the glasses now, with no confirmation, returning them to their normal screen. Used * when the app has been idle: while it is open it occupies the display and (seen on a real * G2) phone notifications do not reach the lenses. * * Resolves `true` ONLY when the host confirmed the exit. `false` covers a refusal, an error * and a wait that ran out; the caller may try again. An implementation must never have two * exit calls in flight, and must not call the host again after a confirmed exit. */ exitNow(): Promise; /** * Optional, for Diagnostics: how this session was opened, when the host says. On a real G2 a * voice launch was not reported as `glassesMenu`, so nothing may depend on it. * The host sends this once, early. An implementation must remember it and replay it to a * listener that subscribes later. */ onLaunchSource?(listener: (source: 'appMenu' | 'glassesMenu') => void): () => void; /** * Read a stored value. `{ ok: false }` means the host did not answer (or failed): the value * is UNKNOWN, which is different from "nothing stored" (`{ ok: true, value: '' }`). */ storageGet(key: string): Promise; /** * Store a value. Resolves `true` ONLY when the host positively confirmed the write. * `false` covers a refusal, an error and a timeout; after a timeout the write may still * land later, so `false` is "not confirmed", never "not written" and never "written". */ storageSet(key: string, value: string): Promise; /** * Optional, for the phone's Diagnostics only: a one-line summary of what the glasses runtime * has delivered (counts and event types; never audio or any content). */ inputSummary?(): string; /** Optional: called whenever `inputSummary()` would change. */ onInputActivity?(listener: () => void): () => void; }