Handle long presses: push-to-talk, with a tap-like fallback

On a real G2 a touch held slightly too long is reported as a long press
(sysEvent type 9, then type 10 on release; source 1 right temple, 3 left),
not as a tap, and was ignored. A long press now does what a tap does. If it
started a recording and is held at least 700 ms, releasing it sends
(push-to-talk); released sooner, it behaves like a tap and the recording
continues until the next tap or press.

Tests: 219 unit/integration; simulator 7 scenarios (long_press /
long_press_release through the automation API). Not reviewed, not deployed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Dan
2026-11-21 13:11:55 -08:00
co-authored by Claude Fable 5.2
parent b8191a7bd2
commit 9cb34b3125
8 changed files with 148 additions and 7 deletions
+27
View File
@@ -64,6 +64,8 @@ export interface ControllerOptions {
submitRetryMs?: number;
/** No audio frames for this long while recording means the microphone is gone. */
micStallMs?: number;
/** A long press held at least this long, then released, sends what was recorded (push-to-talk). */
holdToTalkMs?: number;
}
interface Capture {
@@ -107,6 +109,9 @@ export class Controller {
private readonly submitAttempts: number;
private readonly submitRetryMs: number;
private readonly micStallMs: number;
private readonly holdToTalkMs: number;
/** Set while a long press that STARTED a recording is still held down. */
private heldPress: { generation: number; at: number } | null = null;
constructor(private readonly options: ControllerOptions) {
this.device = options.device;
@@ -116,6 +121,7 @@ export class Controller {
this.submitAttempts = options.submitAttempts ?? 4;
this.submitRetryMs = options.submitRetryMs ?? 1500;
this.micStallMs = options.micStallMs ?? 3000;
this.holdToTalkMs = options.holdToTalkMs ?? 700;
}
// ------------------------------------------------------------------ public
@@ -640,8 +646,29 @@ export class Controller {
case 'audio':
return this.onAudio(event.pcm);
case 'tap':
this.heldPress = null;
return this.dispatch({ type: 'activate', freshId: this.newId() });
case 'long_press': {
// First seen on a real G2 (2026-11-21): a touch held a little too long arrives as a
// long press, not a tap. It does what a tap does, so the user need not care which the
// glasses decided it was. If it started a recording, remember that the finger is down.
const wasListening = this.state.phase === 'listening';
this.dispatch({ type: 'activate', freshId: this.newId() });
this.heldPress =
!wasListening && this.state.phase === 'listening' ? { generation: this.state.generation, at: this.now() } : null;
return;
}
case 'long_press_release': {
// Push-to-talk: held while speaking, then released, sends. A press released quickly is
// treated like a tap and leaves the recording running until the next tap or press.
const held = this.heldPress;
this.heldPress = null;
if (!held || held.generation !== this.state.generation || this.state.phase !== 'listening') return;
if (this.now() - held.at < this.holdToTalkMs) return;
return this.dispatch({ type: 'activate', freshId: this.newId() });
}
case 'double_tap':
this.heldPress = null;
return this.dispatch({ type: 'back' });
case 'swipe_down':
return this.dispatch({ type: 'next_page' });