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:
@@ -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' });
|
||||
|
||||
@@ -64,7 +64,7 @@ export function renderHud(state: AppState, nowMs: number): HudFrame {
|
||||
const cap = state.captureMaxSeconds;
|
||||
return {
|
||||
body: `Listening…\n\nRecording stops by itself after ${cap} seconds.`,
|
||||
status: `● REC ${clock(elapsed)} / ${clock(cap)} · Tap: send · 2×: cancel`,
|
||||
status: `● REC ${clock(elapsed)} / ${clock(cap)} · Tap or release: send · 2×: cancel`,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,10 @@ export const MENU_ITEM = { NEW_CONVERSATION: 1, CANCEL: 2 } as const;
|
||||
export type DeviceEvent =
|
||||
| { type: 'tap' }
|
||||
| { type: 'double_tap' }
|
||||
/** The touch has been held long enough for the glasses to call it a long press. */
|
||||
| { type: 'long_press' }
|
||||
/** The finger was lifted after a long press. */
|
||||
| { type: 'long_press_release' }
|
||||
| { type: 'swipe_up' }
|
||||
| { type: 'swipe_down' }
|
||||
| { type: 'menu'; itemId: number }
|
||||
@@ -89,11 +93,17 @@ export function normalizeEvent(event: RawEvenHubEvent): DeviceEvent[] {
|
||||
case OS_EVENT.SYSTEM_EXIT:
|
||||
out.push({ type: 'system_exit' });
|
||||
break;
|
||||
case OS_EVENT.LONG_PRESS:
|
||||
out.push({ type: 'long_press' });
|
||||
break;
|
||||
case OS_EVENT.LONG_PRESS_RELEASE:
|
||||
out.push({ type: 'long_press_release' });
|
||||
break;
|
||||
case OS_EVENT.CLICK:
|
||||
out.push({ type: 'tap' });
|
||||
break;
|
||||
default:
|
||||
// IMU reports and long press are not part of the interaction contract.
|
||||
// IMU reports are not part of the interaction contract.
|
||||
break;
|
||||
}
|
||||
return out;
|
||||
|
||||
Reference in New Issue
Block a user