Files
hermeven/apps/even-client/src/device/previewDevice.ts
T
DanandClaude Fable 5.2 bbde3c86a8 CODY-016, 017, 018: launch source cannot be missed; a failed idle exit is retried
CODY-016. The SDK pushes the launch source once, early. The Even adapter now
subscribes in its constructor, remembers the value and replays it to a
listener that subscribes later. appMenu still does not arm idle exit.

CODY-018. exitNow() returns whether the host confirmed. The adapter keeps at
most one shutdown call in flight (through the same queue as every other host
call), lets a repeat request wait on that call, and never calls the host
again after a confirmed exit, including one confirmed late. The controller
marks itself as gone only on confirmation or on a system_exit/abnormal_exit
event; otherwise it retries after 3 s, at most 4 attempts in a row, under the
same resting-screen and phone-grace guards, and starts again after activity.

CODY-017. README: one owner-reported locked-phone success; pocketed,
five-minute and ten-cycle runs unverified.

Tests: production-adapter tests with a stand-in host, including the default
30 s under a fake clock; a simulator scenario that performs the real exit
(development-only ?idleExit=fast). Not reviewed. 0.1.1 is not uploaded.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 14:38:29 -08:00

96 lines
3.0 KiB
TypeScript

import type { HudFrame } from '../core/hud.ts';
import type { DeviceEvent } from './events.ts';
import type { DevicePort, StorageRead } from './port.ts';
/**
* Stand-in for the glasses when the page runs in a plain browser (no Even host).
* Draws the two HUD text areas in the page and offers buttons for the gestures.
* It has NO microphone: a tap that would start recording reports the mic as
* unavailable. Nothing shown here is evidence about real hardware.
*/
export class BrowserPreviewDevice implements DevicePort {
private readonly body = document.createElement('pre');
private readonly status = document.createElement('pre');
private readonly listeners = new Set<(event: DeviceEvent) => void>();
constructor(container: HTMLElement) {
this.body.className = 'hud-body';
this.status.className = 'hud-status';
const label = document.createElement('p');
label.className = 'hint';
label.textContent = 'Browser preview of the HUD text. Not the glasses, not the simulator; fonts and wrapping differ.';
const controls = document.createElement('div');
controls.className = 'row';
const gestures: Array<[string, DeviceEvent]> = [
['Tap', { type: 'tap' }],
['Double-tap', { type: 'double_tap' }],
['Swipe up', { type: 'swipe_up' }],
['Swipe down', { type: 'swipe_down' }],
];
for (const [text, event] of gestures) {
const button = document.createElement('button');
button.type = 'button';
button.className = 'secondary';
button.textContent = text;
button.addEventListener('click', () => this.listeners.forEach((l) => l(event)));
controls.append(button);
}
const screen = document.createElement('div');
screen.className = 'hud';
screen.append(this.body, this.status);
container.append(label, screen, controls);
}
async init(frame: HudFrame): Promise<boolean> {
this.show(frame);
return true;
}
show(frame: HudFrame): void {
this.body.textContent = frame.body;
this.status.textContent = frame.status;
}
async startMic(): Promise<boolean> {
return false;
}
async stopMic(): Promise<void> {}
onEvent(listener: (event: DeviceEvent) => void): () => void {
this.listeners.add(listener);
return () => this.listeners.delete(listener);
}
onConnection(): () => void {
return () => undefined;
}
async requestExit(): Promise<void> {}
/** The preview cannot leave anything; it only says so. */
async exitNow(): Promise<boolean> {
this.body.textContent = '(Pepper would now leave the glasses.)';
this.status.textContent = '';
return true;
}
async storageGet(key: string): Promise<StorageRead> {
try {
return { ok: true, value: localStorage.getItem(key) ?? '' };
} catch {
return { ok: false };
}
}
async storageSet(key: string, value: string): Promise<boolean> {
try {
if (value) localStorage.setItem(key, value);
else localStorage.removeItem(key);
return true;
} catch {
return false;
}
}
}