Configurable custom keybindings for bluetooth keyboards paired with the glasses

This commit is contained in:
James Babcock committed 2026-11-15 22:21:12 -08:00
1 parent fd3c26333f
commit 344e140e92
17 files changed
+1203 -100

No files matched your search

+39
View File
@@ -29,6 +29,8 @@ import { OsEventTypeList } from './events'
import { loadDeviceAddresses } from './device-addresses'
import { updateGlassesPresence } from './glasses-presence'
import { firmwareIncompatibilityMessage, hasCompatibleFirmware } from './firmware-compat'
import { keyboardService } from './keyboard/service'
import type { KeyEvent } from './keyboard/keys'
import { isHaltedSessionPhase, resumeAutoReconnect, suppressAutoReconnect } from './reconnect-policy'
import { WearRemote, type WearRemoteInputKind } from './wear-remote'
import { deviceAddressError } from './ios-peripheral-identity'
@@ -232,6 +234,7 @@ export class IosPreviewController {
if (!on) void this.display?.setScreenBlanked(true).catch(error => this.fail(error))
this.requestShellRender()
this.wearRemote?.schedulePublish()
if (on) keyboardService.retryNow()
},
})
const launcher = createLauncherWindow({
@@ -270,6 +273,28 @@ export class IosPreviewController {
assistantAvailable: () => shell.isAssistantAvailable(),
assistant: text => shell.sendToAssistant(text),
})
// A keyboard paired through the glasses (the CFW keyboard bridge). The service decides what
// each key means (app/g2/keyboard/key-router.ts); its gestures share the controller queue
// with physical input, like the watch's.
const queueKeyboardInput = (run: () => Promise<void>): Promise<void> => {
const task = this.inputQueue.then(() => { this.onActivity(); return run() })
this.inputQueue = task.catch(error => this.fail(error))
return task
}
keyboardService.setHost({
ready: () => this.state.phase === 'connected',
locked: () => this.glassesLocked,
wake: () => { void queueKeyboardInput(() => this.receiveInput(makeInputEvent({ type: 'display-wake' }))).catch(() => {}) },
gesture: (gesture, origin) => queueKeyboardInput(async () => {
await this.receiveInput(makeInputEvent({ type: gesture, source: origin } as InputEventPayload))
// A discrete hold includes its release.
if (gesture === 'long-press') await this.receiveInput(makeInputEvent({ type: 'long-press-release', source: origin }))
}),
log: line => this.logBluetooth(line),
// Only while the display is on: a keyboard that is switched off would otherwise keep the
// glasses' radio looking for it around the clock.
shouldReconnect: () => this.state.phase === 'connected' && shell.isScreenOn(),
})
// The header's EvenHub phone-UI button hides while that UI is showing.
onPhoneShownChanged(() => this.syncEvenHubPhoneUi())
registerSystemTools()
@@ -809,6 +834,7 @@ export class IosPreviewController {
},
setSurfaceVisible: (id, visible) => this.setWindowSurfaceVisible(id, visible),
removeSurface: id => this.removeWindowSurface(id),
unhandledKey: event => keyboardService.handleUnhandledKey(event as KeyEvent),
submitPixels: (id, pixels, width, height, draws) => {
void this.submitWorkerPixels(id, pixels, width, height, draws).catch(error => this.fail(error))
},
@@ -830,6 +856,18 @@ export class IosPreviewController {
this.state = { ...this.state, phase, status }
this.logBluetooth(status)
this.emitState()
this.syncKeyboardLink()
}
/**
* Tell the keyboard bridge whether the session can host a keyboard: a G2 on firmware with
* the bridge, connected. On a disconnect the user asked for, the link is still up when the
* phase turns, so the firmware is told to let the keyboard go first.
*/
private syncKeyboardLink(): void {
const up = !!this.communicator && this.state.phase === 'connected' && this.firmwareCompatible
&& glassesTypeSetting.get() === 'g2'
if (up) keyboardService.linkReady()
else keyboardService.linkLost(this.state.phase === 'disconnecting')
}
/** Mirror the session into glasses-presence (read by EvenHub's device status and Timers). */
private syncPresence(): void {
@@ -949,6 +987,7 @@ export class IosPreviewController {
const firmwareWarning = firmwareIncompatibilityMessage(info) ?? ''
if (firmwareWarning && firmwareWarning !== this.state.firmwareWarning) this.logBluetooth(`Firmware compatibility warning: ${firmwareWarning}`)
this.firmwareCompatible = !firmwareWarning && hasCompatibleFirmware(info)
this.syncKeyboardLink()
this.state = { ...this.state, leftVersion: info.leftVersion || this.state.leftVersion,
rightVersion: info.rightVersion || this.state.rightVersion, capabilities: info.extension || this.state.capabilities,
firmwareWarning }