forked from Blendman974/faceclaw
[verified] merge upstream 25cb255b into all-features
This commit is contained in:
commit
ffcdae660d
169 files changed
+16201
-597
No files matched your search
@@ -1063,7 +1063,7 @@ export const useMicControlSetting = new ConfigSettingBoolean({
|
||||
storageKey: "developer.useMicControl",
|
||||
defaultValue: true,
|
||||
description:
|
||||
"Use the custom firmware's per-temple mic-control channel for the Microphones app's array capture. When off, use the standard single mixed stream.",
|
||||
"Use the custom firmware's per-temple mic-control channel for capturing the microphones separately (the Microphones app's array capture, and Transcribe's Microphones option). When off, use the standard single mixed stream.",
|
||||
});
|
||||
|
||||
export const showBleBandwidthSetting = new ConfigSettingBoolean({
|
||||
@@ -1171,7 +1171,9 @@ export const saveRecordingSetting = new ConfigSettingBoolean({
|
||||
label: "Save Recording",
|
||||
storageKey: "voice.saveRecording",
|
||||
defaultValue: false,
|
||||
description: "Record the audio of Transcribe and Translate sessions as WAV files in Downloads (about 2 MB per minute), named after the app and the session's start time. Recordings are kept until you delete them.",
|
||||
description: global.isIOS
|
||||
? "Record the audio of Transcribe and Translate sessions as Matroska audio (.mka) files in Downloads (about 2 MB per minute), named after the app and the session's start time. Recordings are kept until you delete them."
|
||||
: "Record the audio of Transcribe and Translate sessions as Matroska audio (.mka) files in Downloads: about 2 MB per minute, or 10 MB with all four microphones. Named after the app and the session's start time, and kept until you delete them. Transcribe can replay one: pick it in the Files app.",
|
||||
});
|
||||
|
||||
export const assistantSkipConfirmationSetting = new ConfigSettingBoolean({
|
||||
@@ -1481,11 +1483,28 @@ export const terminalNewConnectionSetting = new ConfigSettingString({
|
||||
label: "New connection",
|
||||
storageKey: "terminal.newConnectionDraft",
|
||||
defaultValue: "",
|
||||
editorTitle: "g2mirror connection string (g2mirror://token@host)",
|
||||
editorTitle: "Connection (ssh://user@host or g2mirror://token@host)",
|
||||
glassesEditTitle: "Add connection",
|
||||
normalize: (value) => (value ?? "").replace(/[\x00-\x1f]+/g, "").trim(),
|
||||
});
|
||||
|
||||
/**
|
||||
* Staging buffer for the Terminal app's SSH password prompt: the worker opens
|
||||
* the phone's (masked) text editor on it, then moves what was typed into the
|
||||
* platform keystore (app/native/ssh) and clears it as soon as the user
|
||||
* confirms or cancels on the glasses. Not listed in the Settings app.
|
||||
*/
|
||||
export const terminalSshPasswordSetting = new ConfigSettingString({
|
||||
id: "terminal-ssh-password",
|
||||
label: "SSH password",
|
||||
storageKey: "terminal.sshPasswordDraft",
|
||||
defaultValue: "",
|
||||
inputKind: "password",
|
||||
editorTitle: "SSH password",
|
||||
glassesEditTitle: "SSH password",
|
||||
normalize: (value) => (value ?? "").replace(/[\r\n]+/g, ""),
|
||||
});
|
||||
|
||||
/**
|
||||
* Staging buffer for the T3 Code app's Pair-environment screen: the phone
|
||||
* text editor types the `t3 pair` link into it, and the app reads it back
|
||||
@@ -1865,9 +1884,18 @@ type SettingsMenuOptions<T> = {
|
||||
label?: string
|
||||
}
|
||||
|
||||
type EnumSettingMenuOptions<T> = SettingsMenuOptions<T> & {
|
||||
/**
|
||||
* A live line under the picker's values, such as a sensor reading to pick
|
||||
* by. open() runs as the picker opens, with a function that repaints it,
|
||||
* and returns what to run when the picker closes.
|
||||
*/
|
||||
pickerFooter?: { text: () => string; open: (repaint: () => void) => () => void }
|
||||
}
|
||||
|
||||
export function enumSettingMenuItem<TValue extends string, TId extends string = string>(
|
||||
setting: ConfigSettingEnum<TValue, TId>,
|
||||
opts?: SettingsMenuOptions<TValue>
|
||||
opts?: EnumSettingMenuOptions<TValue>
|
||||
): MenuItem {
|
||||
const label = opts?.label ?? setting.label;
|
||||
return {
|
||||
@@ -1895,7 +1923,11 @@ export function enumSettingMenuItem<TValue extends string, TId extends string =
|
||||
);
|
||||
},
|
||||
}));
|
||||
openModalMenu(ctx, label, items, Math.max(0, setting.values.indexOf(current)));
|
||||
const footer = opts?.pickerFooter;
|
||||
openModalMenu(ctx, label, items, Math.max(0, setting.values.indexOf(current)), {
|
||||
footer: footer?.text,
|
||||
onClosed: footer?.open(() => ctx.actions.requestRender()),
|
||||
});
|
||||
},
|
||||
render: ({ image, x, y, width }) => {
|
||||
drawRightValueMenuItem(image, getDefaultSmallFont(), x, y, width, label, setting.displayValue(setting.get()));
|
||||
|
||||
@@ -112,6 +112,8 @@ import { openSettingsSubMenu, SettingsPanelLayer, type SettingsSection } from ".
|
||||
import { uiFontPickerMenuItem } from "../font-picker";
|
||||
import { NotificationFilterLayer } from "../notification-filter";
|
||||
import { compatibleModelDiscoveryMenuItem } from "../openai-compatible-model-picker";
|
||||
import { keyboardSettingsMenuItem } from "../keyboard-settings";
|
||||
import { keybindingsMenuItem } from "../keybinding-settings";
|
||||
import { isVeniceApiBaseUrl } from "../../native/openai-chat";
|
||||
|
||||
/** The Settings section the Notifications app's "Settings" menu item opens. */
|
||||
@@ -266,6 +268,14 @@ function settingsSections(): SettingsSection[] {
|
||||
],
|
||||
renderDetail: renderWatchStatus,
|
||||
},
|
||||
// A Bluetooth keyboard paired with the glasses themselves (the G2's
|
||||
// custom firmware hosts it; app/g2/keyboard/). Hidden rather than left
|
||||
// out: the Settings window can be open across a change of glasses.
|
||||
{
|
||||
label: "Keyboard",
|
||||
items: [keyboardSettingsMenuItem(), keybindingsMenuItem()],
|
||||
hidden: () => glassesTypeSetting.get() !== "g2",
|
||||
},
|
||||
{
|
||||
label: "Developer",
|
||||
items: [
|
||||
|
||||
@@ -28,6 +28,13 @@ export type SettingsSection = {
|
||||
height: number;
|
||||
ctx: LayerContext;
|
||||
}) => number | void;
|
||||
/**
|
||||
* Leave the section out of the list while this returns true. Re-read on
|
||||
* every paint and input, for a section that only applies with some other
|
||||
* setting (the paired glasses' type): the Settings window outlives changes
|
||||
* to those.
|
||||
*/
|
||||
hidden?: () => boolean;
|
||||
};
|
||||
|
||||
const LEFT_W = 150;
|
||||
@@ -66,7 +73,7 @@ export class SettingsPanelLayer implements Layer {
|
||||
|
||||
constructor(private readonly sections: SettingsSection[]) {
|
||||
this.leftMenu = new Menu<SettingsSection>({
|
||||
items: sections,
|
||||
items: sections.filter((section) => !section.hidden?.()),
|
||||
wrap: true,
|
||||
rowGap: ROW_GAP,
|
||||
highlight: { radius: 6 },
|
||||
@@ -110,9 +117,28 @@ export class SettingsPanelLayer implements Layer {
|
||||
return this.leftMenu.selectedItem ?? this.sections[0]!;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bring the left column in line with which sections are hidden now. The
|
||||
* highlight stays on its section; if that one just went away it moves to
|
||||
* the list's start, with focus back in the left column.
|
||||
*/
|
||||
private syncSections(): void {
|
||||
const visible = this.sections.filter((section) => !section.hidden?.());
|
||||
const shown = this.leftMenu.items;
|
||||
if (visible.length === shown.length && visible.every((section, index) => section === shown[index])) return;
|
||||
const selected = this.leftMenu.selectedItem;
|
||||
const index = selected ? visible.indexOf(selected) : -1;
|
||||
this.leftMenu.setItems(visible, Math.max(0, index));
|
||||
if (index < 0) {
|
||||
this.focus = "left";
|
||||
this.resetRight();
|
||||
}
|
||||
}
|
||||
|
||||
/** Select a left-column section by label (deep link, e.g. from an app's menu). */
|
||||
focusSection(label: string): void {
|
||||
const index = this.sections.findIndex((section) => section.label === label);
|
||||
this.syncSections();
|
||||
const index = this.leftMenu.items.findIndex((section) => section.label === label);
|
||||
if (index < 0) return;
|
||||
this.leftMenu.select(index);
|
||||
this.focus = "left";
|
||||
@@ -125,6 +151,7 @@ export class SettingsPanelLayer implements Layer {
|
||||
const { width, height, padding } = viewport;
|
||||
const image = new GrayImage(width, height, 0);
|
||||
const appFocused = ctx.stack.isFocused();
|
||||
this.syncSections();
|
||||
const section = this.section();
|
||||
const rightItems = section.items;
|
||||
this.rightMenu.setItems(rightItems);
|
||||
@@ -230,6 +257,7 @@ export class SettingsPanelLayer implements Layer {
|
||||
}
|
||||
|
||||
async handleInput(event: InputEvent, ctx: LayerContext): Promise<void> {
|
||||
this.syncSections();
|
||||
const scroll = scrollEventFor(event);
|
||||
if (this.focus === "left") {
|
||||
if (scroll) {
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
import { getDefaultSmallFont } from "../graphics/ui-fonts";
|
||||
import {
|
||||
DEFAULT_KEYS_HELP,
|
||||
KEY_ACTIONS,
|
||||
chordId,
|
||||
describeChord,
|
||||
keyActionLabel,
|
||||
type KeyChord,
|
||||
} from "../g2/keyboard/bindings";
|
||||
import { keyboardService } from "../g2/keyboard/service";
|
||||
import { TextViewerLayer } from "../apps/files/text-viewer";
|
||||
import type { LayerContext } from "./layers";
|
||||
import { drawRightValueMenuItem, MenuLayer, openModalMenu, submenuItem, TextPageLayer, type MenuItem } from "./menu";
|
||||
|
||||
/**
|
||||
* Settings > Keyboard > Keybindings: the custom keybindings (a key, with
|
||||
* any modifiers held, to a gesture), which come before the built-in
|
||||
* meanings in app/g2/keyboard/bindings.ts. Adding one asks for the key on
|
||||
* the keyboard itself, so it works for a remote whose buttons send who
|
||||
* knows what.
|
||||
*/
|
||||
|
||||
/** Waits for the key to bind. Double tap backs out, as from any page. */
|
||||
class KeyCaptureLayer extends TextPageLayer {
|
||||
private cancel: (() => void) | null = null;
|
||||
|
||||
constructor(private readonly onChord: (chord: KeyChord, ctx: LayerContext) => void) {
|
||||
super(
|
||||
"Add keybinding",
|
||||
"Press the key to bind, on the keyboard: a key, a mouse button, or a turn of the wheel. Hold Shift, Ctrl or Alt with it to bind the combination.",
|
||||
);
|
||||
}
|
||||
|
||||
open(ctx: LayerContext): void {
|
||||
ctx.stack.push(this);
|
||||
this.cancel = keyboardService.captureNextKey((chord) => {
|
||||
this.cancel = null;
|
||||
ctx.stack.popThrough(this);
|
||||
this.onChord(chord, ctx);
|
||||
ctx.actions.requestRender();
|
||||
});
|
||||
}
|
||||
|
||||
onRemoved(): void {
|
||||
this.cancel?.();
|
||||
this.cancel = null;
|
||||
}
|
||||
}
|
||||
|
||||
class KeybindingsLayer extends MenuLayer {
|
||||
constructor(viewport: { width: number; height: number }) {
|
||||
super("Keybindings", [], {
|
||||
x: "center",
|
||||
y: 8,
|
||||
width: Math.min(320, viewport.width - 40),
|
||||
minHeight: Math.min(160, viewport.height - 40),
|
||||
maxHeight: Math.min(240, viewport.height - 40),
|
||||
depth: 4,
|
||||
});
|
||||
}
|
||||
|
||||
open(ctx: LayerContext): void {
|
||||
this.updateRows();
|
||||
ctx.stack.push(this);
|
||||
}
|
||||
|
||||
/** Rebuild the rows, with the highlight on `selectId`'s keybinding when given. */
|
||||
private updateRows(selectId?: string): void {
|
||||
const bindings = keyboardService.keyBindings();
|
||||
const rows: MenuItem[] = bindings.map((binding) => {
|
||||
const label = describeChord(binding.chord);
|
||||
return {
|
||||
label,
|
||||
onSelect: (ctx: LayerContext) => this.pickAction(ctx, binding.chord),
|
||||
render: ({ image, x, y, width }) => {
|
||||
drawRightValueMenuItem(image, getDefaultSmallFont(), x, y, width, label, keyActionLabel(binding.action));
|
||||
},
|
||||
};
|
||||
});
|
||||
rows.push(
|
||||
{ label: "Add keybinding", onSelect: (ctx) => this.add(ctx) },
|
||||
// Scrolls, where a page would cut the text off in a short window.
|
||||
submenuItem("Default keys", (ctx) => ctx.stack.push(new TextViewerLayer(DEFAULT_KEYS_HELP, "Default keys"))),
|
||||
);
|
||||
const selected = selectId === undefined ? -1 : bindings.findIndex((binding) => chordId(binding.chord) === selectId);
|
||||
if (selected >= 0) this.setItems(rows, selected);
|
||||
else this.setItems(rows);
|
||||
}
|
||||
|
||||
private add(ctx: LayerContext): void {
|
||||
if (!keyboardService.bridge.isConnected()) {
|
||||
ctx.stack.push(new TextPageLayer(
|
||||
"Add keybinding",
|
||||
"No keyboard is connected. Pair or reconnect one under Bluetooth keyboard, then come back: the key to bind is read from the keyboard.",
|
||||
));
|
||||
return;
|
||||
}
|
||||
new KeyCaptureLayer((chord, captureCtx) => this.pickAction(captureCtx, chord)).open(ctx);
|
||||
}
|
||||
|
||||
/** Choose what `chord` does: for a new keybinding, or to change or remove one. */
|
||||
private pickAction(ctx: LayerContext, chord: KeyChord): void {
|
||||
const id = chordId(chord);
|
||||
const current = keyboardService.keyBindings().find((binding) => chordId(binding.chord) === id)?.action;
|
||||
const done = (inner: LayerContext): void => {
|
||||
inner.stack.pop();
|
||||
this.updateRows(id);
|
||||
inner.actions.requestRender();
|
||||
};
|
||||
const rows: MenuItem[] = KEY_ACTIONS.map((entry) => ({
|
||||
label: entry.action === current ? `${entry.label} *` : entry.label,
|
||||
onSelect: (inner: LayerContext) => {
|
||||
if (!keyboardService.setKeyBinding(chord, entry.action)) {
|
||||
inner.stack.pop();
|
||||
inner.stack.push(new TextPageLayer("Keybindings", "There is no room for another keybinding. Remove one first."));
|
||||
return;
|
||||
}
|
||||
done(inner);
|
||||
},
|
||||
}));
|
||||
if (current !== undefined) {
|
||||
rows.push({
|
||||
label: "Remove keybinding",
|
||||
onSelect: (inner) => {
|
||||
keyboardService.removeKeyBinding(chord);
|
||||
done(inner);
|
||||
},
|
||||
});
|
||||
}
|
||||
const selected = Math.max(0, KEY_ACTIONS.findIndex((entry) => entry.action === current));
|
||||
openModalMenu(ctx, describeChord(chord), rows, selected);
|
||||
}
|
||||
}
|
||||
|
||||
/** The Settings row that opens the keybindings menu. */
|
||||
export function keybindingsMenuItem(): MenuItem {
|
||||
return {
|
||||
label: "Keybindings",
|
||||
description:
|
||||
"Choose what keys do: arrows, Enter, Esc and a mouse's buttons and wheel navigate by default, and any key (or a remote's button) can be bound to select, back, a swipe, a scroll or a menu.",
|
||||
onSelect: (ctx) => new KeybindingsLayer(ctx.stack.getBaseSize()).open(ctx),
|
||||
render: ({ image, x, y, width }) => {
|
||||
const count = keyboardService.keyBindings().length;
|
||||
drawRightValueMenuItem(image, getDefaultSmallFont(), x, y, width, "Keybindings", count ? `${count} custom` : "Default");
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
import { getDefaultSmallFont } from "../graphics/ui-fonts";
|
||||
import type { KeyboardBridgeSnapshot } from "../g2/keyboard/bridge";
|
||||
import type { KeyboardAdvert } from "../g2/keyboard/protocol";
|
||||
import { keyboardService } from "../g2/keyboard/service";
|
||||
import { ConfigSettingString, textSettingMenuItem } from "./dashboard-settings";
|
||||
import type { LayerContext } from "./layers";
|
||||
import { drawRightValueMenuItem, MenuLayer, type MenuItem } from "./menu";
|
||||
|
||||
/**
|
||||
* Settings > Keyboard: pairing a Bluetooth keyboard with the glasses (the
|
||||
* CFW keyboard bridge, app/g2/keyboard/). The keyboard pairs with the
|
||||
* glasses, not the phone, so all of it happens here, on the glasses: scan,
|
||||
* pick, and for a keyboard that wants one, the passkey to type on it.
|
||||
*/
|
||||
|
||||
/** The code a keyboard with a display shows, typed on the phone. Scratch, not a preference. */
|
||||
const pairingCodeSetting = new ConfigSettingString({
|
||||
id: "keyboardPairingCode",
|
||||
storageKey: "keyboard.pairingCode",
|
||||
label: "Code on keyboard",
|
||||
defaultValue: "",
|
||||
normalize: (value) => (value ?? "").replace(/\D/g, "").slice(0, 6),
|
||||
});
|
||||
|
||||
const sixDigits = (value: number): string => {
|
||||
const text = String(value).padStart(6, "0");
|
||||
return `${text.slice(0, 3)} ${text.slice(3)}`;
|
||||
};
|
||||
|
||||
function advertLabel(advert: KeyboardAdvert): string {
|
||||
const name = advert.name.trim() || advert.address;
|
||||
return name.length > 30 ? `${name.slice(0, 27)}...` : name;
|
||||
}
|
||||
|
||||
/** One line saying where the keyboard stands, for the Settings row and the menu's first row. */
|
||||
export function keyboardStatusText(snapshot: KeyboardBridgeSnapshot): string {
|
||||
const name = snapshot.activeName || snapshot.saved?.name || "keyboard";
|
||||
switch (snapshot.state) {
|
||||
case "unavailable":
|
||||
return snapshot.saved ? "Glasses not connected" : "Not set up";
|
||||
case "scanning":
|
||||
return "Scanning...";
|
||||
case "connecting":
|
||||
return `Connecting to ${name}...`;
|
||||
case "pairing":
|
||||
return `Pairing with ${name}...`;
|
||||
case "configuring":
|
||||
return `Setting up ${name}...`;
|
||||
case "connected":
|
||||
return `Connected: ${name}`;
|
||||
case "error":
|
||||
return snapshot.error || "Failed";
|
||||
default:
|
||||
if (snapshot.waiting) return `Waiting for ${name}`;
|
||||
return snapshot.saved ? `${name} (disconnected)` : "Not set up";
|
||||
}
|
||||
}
|
||||
|
||||
/** The short form for the right edge of the Settings row. */
|
||||
function keyboardStatusBrief(snapshot: KeyboardBridgeSnapshot): string {
|
||||
switch (snapshot.state) {
|
||||
case "connected":
|
||||
return "Connected";
|
||||
case "scanning":
|
||||
return "Scanning";
|
||||
case "connecting":
|
||||
case "pairing":
|
||||
case "configuring":
|
||||
return "Connecting";
|
||||
case "error":
|
||||
return "Failed";
|
||||
case "unavailable":
|
||||
return snapshot.saved ? "Offline" : "Off";
|
||||
default:
|
||||
return snapshot.waiting ? "Waiting" : snapshot.saved ? "Disconnected" : "Off";
|
||||
}
|
||||
}
|
||||
|
||||
const info = (label: string): MenuItem => ({ label, disabled: true, onSelect: () => {} });
|
||||
|
||||
class KeyboardSettingsLayer extends MenuLayer {
|
||||
private unsubscribe: (() => void) | null = null;
|
||||
private showOthers = false;
|
||||
/** What kind of rows are showing; a change moves the highlight to the first row that does something. */
|
||||
private shape = "";
|
||||
|
||||
constructor(viewport: { width: number; height: number }) {
|
||||
super("Bluetooth keyboard", [], {
|
||||
x: "center",
|
||||
y: 8,
|
||||
width: Math.min(320, viewport.width - 40),
|
||||
minHeight: Math.min(160, viewport.height - 40),
|
||||
maxHeight: Math.min(240, viewport.height - 40),
|
||||
depth: 4,
|
||||
});
|
||||
}
|
||||
|
||||
open(ctx: LayerContext): void {
|
||||
ctx.stack.push(this);
|
||||
this.updateRows();
|
||||
this.unsubscribe = keyboardService.subscribe(() => {
|
||||
this.updateRows();
|
||||
ctx.actions.requestRender();
|
||||
});
|
||||
}
|
||||
|
||||
onRemoved(): void {
|
||||
this.unsubscribe?.();
|
||||
this.unsubscribe = null;
|
||||
}
|
||||
|
||||
/** Run a bridge command; its failure shows up in the snapshot, which repaints the rows. */
|
||||
private run(action: () => Promise<unknown>): void {
|
||||
void action().catch(() => {});
|
||||
}
|
||||
|
||||
private updateRows(): void {
|
||||
const snapshot = keyboardService.snapshot();
|
||||
const bridge = keyboardService.bridge;
|
||||
const rows: MenuItem[] = [info(keyboardStatusText(snapshot))];
|
||||
let shape: string = snapshot.state;
|
||||
|
||||
const scanRow = (label: string): MenuItem => ({
|
||||
label,
|
||||
disabled: snapshot.busy,
|
||||
onSelect: () => {
|
||||
this.showOthers = false;
|
||||
this.run(() => bridge.scan());
|
||||
},
|
||||
});
|
||||
|
||||
if (snapshot.state === "unavailable") {
|
||||
rows.push(info("Connect G2 glasses to pair one."));
|
||||
if (snapshot.saved) rows.push({ label: `Forget ${snapshot.saved.name || "keyboard"}`, onSelect: () => this.run(() => bridge.forget()) });
|
||||
} else if (snapshot.pairing) {
|
||||
const pairing = snapshot.pairing;
|
||||
shape = `pairing:${pairing.kind}`;
|
||||
if (pairing.kind === "display") {
|
||||
rows.push(info(`Type ${sixDigits(pairing.pin)} on the keyboard,`), info("then press Enter."));
|
||||
} else if (pairing.kind === "compare") {
|
||||
rows.push(
|
||||
info(`Does the keyboard show ${sixDigits(pairing.value)}?`),
|
||||
{ label: "Yes, pair", onSelect: () => this.run(() => bridge.answerCompare(true)) },
|
||||
{ label: "No", onSelect: () => this.run(() => bridge.answerCompare(false)) },
|
||||
);
|
||||
} else {
|
||||
rows.push(
|
||||
info("Enter the code the keyboard shows."),
|
||||
textSettingMenuItem(pairingCodeSetting),
|
||||
{
|
||||
label: "Pair with this code",
|
||||
disabled: () => pairingCodeSetting.get().length !== 6,
|
||||
onSelect: () => {
|
||||
const code = pairingCodeSetting.get();
|
||||
pairingCodeSetting.set("");
|
||||
this.run(() => bridge.answerPasskey(parseInt(code, 10)));
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
rows.push({ label: "Cancel pairing", onSelect: () => this.run(() => bridge.disconnect()) });
|
||||
} else if (snapshot.state === "connecting" || snapshot.state === "pairing" || snapshot.state === "configuring") {
|
||||
rows.push({ label: "Cancel", onSelect: () => this.run(() => bridge.disconnect()) });
|
||||
} else if (snapshot.state === "scanning" || (snapshot.scanResults.length > 0 && snapshot.state !== "connected")) {
|
||||
shape = "results";
|
||||
const hid = snapshot.scanResults.filter((advert) => advert.hid);
|
||||
const others = snapshot.scanResults.filter((advert) => !advert.hid);
|
||||
const pick = (advert: KeyboardAdvert): MenuItem => ({
|
||||
label: advertLabel(advert),
|
||||
disabled: snapshot.busy,
|
||||
onSelect: () => {
|
||||
this.run(() => bridge.connect({ address: advert.address, addressType: advert.addressType, name: advert.name.trim() || advert.address }));
|
||||
},
|
||||
});
|
||||
rows.push(...hid.map(pick));
|
||||
if (!hid.length && snapshot.state !== "scanning") rows.push(info("No keyboards found."), info("Put it in pairing mode."));
|
||||
if (others.length && this.showOthers) rows.push(...others.map(pick));
|
||||
else if (others.length) {
|
||||
rows.push({
|
||||
label: `Show ${others.length} other device${others.length === 1 ? "" : "s"}`,
|
||||
onSelect: (ctx) => {
|
||||
this.showOthers = true;
|
||||
this.updateRows();
|
||||
ctx.actions.requestRender();
|
||||
},
|
||||
});
|
||||
}
|
||||
if (snapshot.state !== "scanning") rows.push(scanRow("Scan again"));
|
||||
if (snapshot.saved && snapshot.state !== "scanning") {
|
||||
rows.push({ label: `Reconnect ${snapshot.saved.name || "keyboard"}`, disabled: snapshot.busy, onSelect: () => this.run(() => bridge.reconnect()) });
|
||||
}
|
||||
} else if (snapshot.state === "connected") {
|
||||
rows.push(
|
||||
{ label: "Disconnect", onSelect: () => this.run(() => bridge.disconnect()) },
|
||||
{ label: "Forget this keyboard", onSelect: () => this.run(() => bridge.forget()) },
|
||||
scanRow("Pair a different keyboard"),
|
||||
);
|
||||
} else if (snapshot.saved) {
|
||||
shape = snapshot.waiting ? "waiting" : "saved";
|
||||
rows.push({ label: "Reconnect now", disabled: snapshot.busy, onSelect: () => this.run(() => bridge.reconnect()) });
|
||||
if (snapshot.waiting) rows.push({ label: "Stop reconnecting", onSelect: () => this.run(() => bridge.disconnect()) });
|
||||
rows.push(
|
||||
{ label: "Forget this keyboard", onSelect: () => this.run(() => bridge.forget()) },
|
||||
scanRow("Pair a different keyboard"),
|
||||
);
|
||||
} else {
|
||||
shape = "empty";
|
||||
rows.push(info("Put the keyboard in pairing mode,"), info("then scan."), scanRow("Scan for keyboards"));
|
||||
}
|
||||
|
||||
const firstAction = rows.findIndex((row) => row.disabled !== true);
|
||||
if (shape !== this.shape) {
|
||||
this.shape = shape;
|
||||
this.setItems(rows, Math.max(0, firstAction));
|
||||
} else {
|
||||
this.setItems(rows);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The Settings row that opens the keyboard menu. */
|
||||
export function keyboardSettingsMenuItem(): MenuItem {
|
||||
return {
|
||||
label: "Bluetooth keyboard",
|
||||
description:
|
||||
"Pair a Bluetooth keyboard with the glasses. It types into Terminal sessions, and its arrow keys, Enter and Escape work everywhere as scroll, select and back.",
|
||||
onSelect: (ctx) => new KeyboardSettingsLayer(ctx.stack.getBaseSize()).open(ctx),
|
||||
render: ({ image, x, y, width }) => {
|
||||
drawRightValueMenuItem(image, getDefaultSmallFont(), x, y, width, "Bluetooth keyboard", keyboardStatusBrief(keyboardService.snapshot()));
|
||||
},
|
||||
};
|
||||
}
|
||||
+19
-1
@@ -3,6 +3,7 @@ import { screenHeight, screenWidth } from "../graphics/screen-size";
|
||||
import { dimPlanes, type Plane } from "../graphics/plane";
|
||||
import { spanCurrent } from "../native/frame-timings";
|
||||
import { type ConfigSettingBoolean, type ConfigSettingString, type VoiceProvider } from "./dashboard-settings";
|
||||
import { type VoiceReplay } from "../native/voice-control";
|
||||
import { directionalFallback, isDirectionalInput, type InputEvent } from "./gestures";
|
||||
import { toViewport, type Viewport, type ViewportSize } from "./viewport";
|
||||
|
||||
@@ -13,8 +14,17 @@ export type TextSettingsEditToggle = {
|
||||
|
||||
/** A continuous-capture client's needs (see LayerActions.startContinuousVoiceCapture). */
|
||||
export type ContinuousCaptureOptions = {
|
||||
/** Names a WAV of the captured audio in Downloads, written while Save Recording is on. */
|
||||
/** Names a recording (.mka) of the captured audio in Downloads, written while Save Recording is on. */
|
||||
recordAs?: string;
|
||||
/**
|
||||
* How many of the glasses' microphones to capture: 1 is their own mixed
|
||||
* stream; 2 (one per temple) and 4 (both of each temple) stream the
|
||||
* microphones separately through the custom firmware, for recording and
|
||||
* array processing. While any client asks for more than one, every capture
|
||||
* uses the most asked for. Glasses without the microphone channel, and the
|
||||
* phone's microphone, give 1 whatever is asked.
|
||||
*/
|
||||
mics?: MicCount;
|
||||
/**
|
||||
* Transcribe with this provider, expecting this spoken language (ISO 639-1,
|
||||
* or "" for the provider to detect it), instead of the Transcription
|
||||
@@ -26,6 +36,8 @@ export type ContinuousCaptureOptions = {
|
||||
|
||||
export type TranscriptionChoice = { provider: VoiceProvider; language: string };
|
||||
|
||||
export type MicCount = 1 | 2 | 4;
|
||||
|
||||
export type LayerActions = {
|
||||
/** Ask for a dashboard repaint+transmit, e.g. when async data arrives. */
|
||||
requestRender: () => void;
|
||||
@@ -55,6 +67,12 @@ export type LayerActions = {
|
||||
*/
|
||||
startContinuousVoiceCapture: (client: string, options?: ContinuousCaptureOptions) => Promise<void> | void;
|
||||
stopContinuousVoiceCapture: (client: string) => Promise<void> | void;
|
||||
/**
|
||||
* Open a recording (.mka) for playing back through transcription in place
|
||||
* of the microphone; the caller starts and closes it. Absent, or null,
|
||||
* where recordings can't be replayed.
|
||||
*/
|
||||
openVoiceReplay?: (path: string) => VoiceReplay | null;
|
||||
/** Play a CFW tone-sequencer payload (see sound-effects.ts). */
|
||||
playBuzzerSequence: (payload: Uint8Array) => Promise<void> | void;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { GrayImage, imageFromAsciiArt, type UiFont } from "../graphics/image";
|
||||
import { truncateText } from "../graphics/textwrap";
|
||||
import { voiceControlBridge } from "../native/voice-control";
|
||||
import { voiceControlBridge, type VoiceEventSource } from "../native/voice-control";
|
||||
import { lineStep } from "./metrics";
|
||||
import type { Edges } from "./viewport";
|
||||
|
||||
@@ -68,8 +68,9 @@ export class MicLevelMeter {
|
||||
private timer: ReturnType<typeof setInterval> | null = null;
|
||||
private unsubscribe: (() => void) | null = null;
|
||||
|
||||
start(requestRender: () => void, isVisible: () => boolean): void {
|
||||
this.unsubscribe = voiceControlBridge.onMicLevel((level) => {
|
||||
/** `source` is the capture whose level to show: the microphone's unless given. */
|
||||
start(requestRender: () => void, isVisible: () => boolean, source: VoiceEventSource = voiceControlBridge): void {
|
||||
this.unsubscribe = source.onMicLevel((level) => {
|
||||
this.peak = Math.max(this.peak, level);
|
||||
});
|
||||
this.timer = setInterval(() => {
|
||||
|
||||
+58
-6
@@ -39,6 +39,8 @@ const PAGE_TITLE_OFFSET_Y = 2;
|
||||
const PAGE_TITLE_GAP = 4;
|
||||
/** Room a page menu keeps right of its rows for the scrollbar. */
|
||||
const PAGE_SCROLLBAR_GUTTER = 6;
|
||||
/** A heading row's text: dimmer than a row's, brighter than a disabled row's. */
|
||||
const MENU_HEADING_VALUE = 90;
|
||||
|
||||
export type MenuLayout = {
|
||||
/** Stereo depth of the menu surface, including the selected row. */
|
||||
@@ -57,7 +59,7 @@ export type MenuLayout = {
|
||||
* Dim hint line pinned to the bottom edge inside the box, below the items
|
||||
* (gesture help such as "●— system menu"). Takes a line off the item area.
|
||||
*/
|
||||
footer?: string;
|
||||
footer?: MenuFooter;
|
||||
/** Brightness factor for everything beneath the menu (see Layer.dimUnderneath). Default: none. */
|
||||
dimUnderneath?: number;
|
||||
/**
|
||||
@@ -83,9 +85,16 @@ export type MenuPageLayout = {
|
||||
/** Width of the rows. Default (and at most): the window's, inside its side padding. */
|
||||
width?: number;
|
||||
/** Dim hint line pinned above the window's bottom padding, below the rows. */
|
||||
footer?: string;
|
||||
footer?: MenuFooter;
|
||||
};
|
||||
|
||||
/** A menu's footer line: fixed text, or read on every paint (a live value). */
|
||||
export type MenuFooter = string | (() => string);
|
||||
|
||||
function footerText(footer: MenuFooter): string {
|
||||
return typeof footer === "function" ? footer() : footer;
|
||||
}
|
||||
|
||||
export type MenuItemRenderArgs = {
|
||||
image: GrayImage;
|
||||
x: number;
|
||||
@@ -104,6 +113,12 @@ export type MenuItem = {
|
||||
description?: string;
|
||||
/** Disabled rows stay visible but render dimly and ignore clicks. */
|
||||
disabled?: boolean | (() => boolean);
|
||||
/**
|
||||
* A label for the group of rows after it (see menuHeadingItem). MenuLayer's
|
||||
* highlight skips it; a list that doesn't know headings shows it as a
|
||||
* disabled row.
|
||||
*/
|
||||
heading?: boolean;
|
||||
onSelect: (ctx: LayerContext, menu: MenuLayer) => Promise<void> | void;
|
||||
render?: (args: MenuItemRenderArgs) => void;
|
||||
};
|
||||
@@ -207,6 +222,22 @@ export function submenuItem(
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* A heading for the rows that follow it, splitting a long menu into sections:
|
||||
* dim capitals in the rows' text column, never selected.
|
||||
*/
|
||||
export function menuHeadingItem(label: string): MenuItem {
|
||||
return {
|
||||
label,
|
||||
heading: true,
|
||||
disabled: true,
|
||||
onSelect: () => {},
|
||||
render: ({ image, x, y, text }) => {
|
||||
image.drawText(getDefaultSmallFont(), x, y + LIST_ROW_TEXT_INSET, text.toUpperCase(), MENU_HEADING_VALUE);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function drawToggleMenuItem(
|
||||
image: GrayImage,
|
||||
font: UiFont,
|
||||
@@ -274,6 +305,7 @@ export class MenuLayer implements Layer {
|
||||
wrap: true,
|
||||
rowGap: 1,
|
||||
getHeight: () => listRowHeight(getDefaultSmallFont()),
|
||||
isSelectable: (item) => !item.heading,
|
||||
draw: ({ image, item, x, y, width, height, selected }) => {
|
||||
const font = getDefaultSmallFont();
|
||||
const disabled = isMenuItemDisabled(item);
|
||||
@@ -361,7 +393,7 @@ export class MenuLayer implements Layer {
|
||||
image.drawText(font, x + 12, y + 8, this.title, 220);
|
||||
}
|
||||
if (layout.footer) {
|
||||
image.drawText(font, x + 22, y + height - MENU_BODY_PADDING - font.lineHeight, layout.footer, 110);
|
||||
image.drawText(font, x + 22, y + height - MENU_BODY_PADDING - font.lineHeight, footerText(layout.footer), 110);
|
||||
}
|
||||
|
||||
const bodyY = y + chromeTop;
|
||||
@@ -398,7 +430,7 @@ export class MenuLayer implements Layer {
|
||||
let fixedBottom = height - padding.bottom;
|
||||
if (layout.footer) {
|
||||
const footerY = height - padding.bottom - font.lineHeight;
|
||||
image.drawText(font, x + MENU_ROW_TEXT_INSET, footerY, layout.footer, 110);
|
||||
image.drawText(font, x + MENU_ROW_TEXT_INSET, footerY, footerText(layout.footer), 110);
|
||||
bottom = fixedBottom = footerY - MENU_FOOTER_GAP;
|
||||
}
|
||||
if (bottom <= top) return image;
|
||||
@@ -432,17 +464,26 @@ export class MenuLayer implements Layer {
|
||||
}
|
||||
}
|
||||
|
||||
export type ModalMenuOptions = {
|
||||
/** A dim line under the items (see MenuLayout.footer). */
|
||||
footer?: MenuFooter;
|
||||
/** Runs when the menu leaves the stack, however it closes. */
|
||||
onClosed?: () => void;
|
||||
};
|
||||
|
||||
/** Open a centered, bordered menu over the current layer. */
|
||||
export function openModalMenu(
|
||||
ctx: LayerContext,
|
||||
title: string,
|
||||
items: MenuItem[],
|
||||
initialSelectedIndex = 0,
|
||||
options: ModalMenuOptions = {},
|
||||
): void {
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const font = getDefaultSmallFont();
|
||||
const menuWidth = Math.min(320, width - 40);
|
||||
const naturalHeight = menuTitleHeight(font) + 2 * MENU_BODY_PADDING + items.length * listRowHeight(font);
|
||||
const footerHeight = options.footer ? MENU_FOOTER_GAP + lineStep(font) : 0;
|
||||
const naturalHeight = menuTitleHeight(font) + 2 * MENU_BODY_PADDING + items.length * listRowHeight(font) + footerHeight;
|
||||
// 20px clear above and below, or 8 in a short window (the RayNeo iO's),
|
||||
// where those rows are worth more than the margin.
|
||||
const marginY = height < SHORT_WINDOW_HEIGHT ? 8 : 20;
|
||||
@@ -455,8 +496,19 @@ export function openModalMenu(
|
||||
maxHeight: menuHeight,
|
||||
// Floats nearer than the content it opens over, like the window and system menus.
|
||||
depth: 4,
|
||||
footer: options.footer,
|
||||
};
|
||||
ctx.stack.push(new MenuLayer(title, items, layout).selectItem(initialSelectedIndex));
|
||||
ctx.stack.push(new ModalMenuLayer(title, items, layout, options.onClosed).selectItem(initialSelectedIndex));
|
||||
}
|
||||
|
||||
class ModalMenuLayer extends MenuLayer {
|
||||
constructor(title: string, items: MenuItem[], layout: MenuLayout, private readonly onClosed?: () => void) {
|
||||
super(title, items, layout);
|
||||
}
|
||||
|
||||
onRemoved(): void {
|
||||
this.onClosed?.();
|
||||
}
|
||||
}
|
||||
|
||||
export function isMenuItemDisabled(item: MenuItem): boolean {
|
||||
|
||||
@@ -50,6 +50,8 @@ export type InProcessWindowOptions = {
|
||||
setScreenOn?: ShellWindow["setScreenOn"];
|
||||
/** See ShellWindow.keepsScreenOn. */
|
||||
keepsScreenOn?: ShellWindow["keepsScreenOn"];
|
||||
/** See ShellWindow.restoresApp. */
|
||||
restoresApp?: boolean;
|
||||
/** The window came to or left the foreground (after its surface visibility follows). */
|
||||
onForegroundChanged?: (foreground: boolean) => void;
|
||||
/** Shared actions; requestRender is rebound to this window's render. */
|
||||
@@ -179,6 +181,7 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
|
||||
holdToTalk: options.holdToTalk,
|
||||
isVoiceCapturing: options.isVoiceCapturing,
|
||||
keepsScreenOn: options.keepsScreenOn,
|
||||
restoresApp: options.restoresApp,
|
||||
setScreenOn: options.setScreenOn,
|
||||
heightMode,
|
||||
hasAppMenu: () => appMenuItems().length > 0,
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
isWatchInput,
|
||||
makeInputEvent,
|
||||
} from "../gestures";
|
||||
import type { KeyEvent } from "../../g2/keyboard/keys";
|
||||
import { Layer, LayerActions, LayerContext, LayerStack, noopLayerActions } from "../layers";
|
||||
import { CONTEXT_MENU_DIM, MenuLayer, type MenuItem } from "../menu";
|
||||
import { VoiceInputLayer, type VoiceSendTarget } from "./voice-input";
|
||||
@@ -158,6 +159,13 @@ export type ShellWindow = {
|
||||
* draws this window's top bar.
|
||||
*/
|
||||
heightMode: WindowHeightMode;
|
||||
/**
|
||||
* False for a window that must not bring its app back when Faceclaw
|
||||
* restarts (the controller's open-apps restore relaunches apps, not
|
||||
* windows): one that shows something a plain launch of its app would not,
|
||||
* where the relaunch would do something else in its place.
|
||||
*/
|
||||
restoresApp?: boolean;
|
||||
/** App-side cleanup when the shell closes the window (worker notification, surface removal). */
|
||||
close?: () => void;
|
||||
drawIcon: ShellChromeWindow["drawIcon"];
|
||||
@@ -192,6 +200,15 @@ export type ShellWindow = {
|
||||
* only windows that consume typed text (the terminal) implement it.
|
||||
*/
|
||||
receiveTextInput?: (text: string, options?: { submit?: boolean }) => void;
|
||||
/**
|
||||
* Take a key from a hardware keyboard (app/g2/keyboard) as a key. Optional:
|
||||
* only windows that give keys a meaning of their own (the terminal)
|
||||
* implement it. They get the keys no keybinding claimed while they have
|
||||
* input focus, presses and releases alike; the rest of the time, and for
|
||||
* every other window, the navigation keys act as gestures (see
|
||||
* app/g2/keyboard/bindings.ts).
|
||||
*/
|
||||
handleKeyEvent?: (event: KeyEvent) => void;
|
||||
/** Foreground state changed: this window's surface is (not) the visible one. */
|
||||
setForeground?: (foreground: boolean) => void;
|
||||
/**
|
||||
@@ -1671,6 +1688,21 @@ class Shell {
|
||||
this.foregroundWindow()?.receiveTextInput?.(text, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Offer a hardware-keyboard key to the window that has input focus. True
|
||||
* when that window takes keys (ShellWindow.handleKeyEvent) and got this
|
||||
* one; false when the key is the caller's to interpret: the screen is off,
|
||||
* the sidebar or a shell overlay has focus, or the window has no use for
|
||||
* keys. Typing counts as activity for the screen timeout.
|
||||
*/
|
||||
receiveKeyEvent(event: KeyEvent): boolean {
|
||||
const window = this.inputTargetWindow();
|
||||
if (!window?.handleKeyEvent) return false;
|
||||
if (event.phase === "down") this.lastInputAtMs = Date.now();
|
||||
window.handleKeyEvent(event);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the voice dialog aimed at the foreground window. Called when the
|
||||
* user picks Voice input from the system menu (or an app asks via a
|
||||
|
||||
@@ -28,6 +28,8 @@ export type WorkerAppMessage =
|
||||
| { type: "close-window"; windowId: string }
|
||||
| { type: "input"; windowId: string; event: unknown; frameId: number; focused: boolean }
|
||||
| { type: "text-input"; windowId: string; text: string; submit?: boolean }
|
||||
/** A hardware-keyboard key (a KeyEvent), for windows opened with acceptsKeys. */
|
||||
| { type: "key"; windowId: string; event: unknown; focused: boolean }
|
||||
| { type: "render"; windowId: string; focused: boolean }
|
||||
| { type: "foreground"; windowId: string; foreground: boolean; focused: boolean }
|
||||
/**
|
||||
@@ -56,6 +58,16 @@ export type WorkerAppReply =
|
||||
type: "worker-ready";
|
||||
}
|
||||
| { type: "yield-focus"; windowId: string }
|
||||
| {
|
||||
/**
|
||||
* A "key" message the window had no use for as a key (a terminal
|
||||
* showing its session list rather than a session). The host gives it
|
||||
* the keyboard's navigation meaning instead.
|
||||
*/
|
||||
type: "key-unhandled";
|
||||
windowId: string;
|
||||
event: unknown;
|
||||
}
|
||||
| {
|
||||
/** Foreground and focus one of the app's existing windows. */
|
||||
type: "focus-window";
|
||||
@@ -81,6 +93,8 @@ export type WorkerAppReply =
|
||||
focus?: boolean;
|
||||
/** Window height: the standard 288px band ("min", default) or full screen ("max"). */
|
||||
heightMode?: WindowHeightMode;
|
||||
/** Send the window hardware-keyboard keys (see WorkerWindowSpec). */
|
||||
acceptsKeys?: boolean;
|
||||
}
|
||||
| {
|
||||
/**
|
||||
@@ -196,6 +210,13 @@ export type WorkerWindowSpec = {
|
||||
* of all four directions in every window state (see ShellWindow).
|
||||
*/
|
||||
acceptsDirectional?: boolean;
|
||||
/**
|
||||
* Deliver hardware-keyboard keys to the worker as "key" messages while the
|
||||
* window has input focus (see ShellWindow.handleKeyEvent). The worker
|
||||
* answers "key-unhandled" for a key it doesn't want as a key just then,
|
||||
* which gets the keyboard's navigation meaning instead.
|
||||
*/
|
||||
acceptsKeys?: boolean;
|
||||
};
|
||||
|
||||
export type WorkerAppHostOptions = {
|
||||
@@ -223,6 +244,8 @@ export type WorkerAppHostOptions = {
|
||||
startTextSettingEdit: (settingId: string) => void;
|
||||
/** Close the phone text editor opened by startTextSettingEdit. */
|
||||
endTextSettingEdit: () => void;
|
||||
/** A key a window was sent and handed back (the "key-unhandled" reply); a KeyEvent. */
|
||||
unhandledKey?: (event: unknown) => void;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -312,6 +335,10 @@ export class WorkerAppHost {
|
||||
shell.yieldFocusToSidebar();
|
||||
}
|
||||
break;
|
||||
case "key-unhandled":
|
||||
// Stale once focus has moved on: the key was meant for that window.
|
||||
if (shell.isWindowFocused(message.windowId)) this.options.unhandledKey?.(message.event);
|
||||
break;
|
||||
case "focus-window":
|
||||
if (this.openWindows.has(message.windowId)) {
|
||||
shell.focusWindow(message.windowId);
|
||||
@@ -335,6 +362,7 @@ export class WorkerAppHost {
|
||||
iconGlyph: message.iconGlyph,
|
||||
focus: message.focus,
|
||||
heightMode: message.heightMode,
|
||||
acceptsKeys: message.acceptsKeys,
|
||||
});
|
||||
break;
|
||||
case "set-height-mode":
|
||||
@@ -522,6 +550,13 @@ export class WorkerAppHost {
|
||||
receiveTextInput: (text, options) => {
|
||||
this.post({ type: "text-input", windowId: spec.windowId, text, ...(options?.submit === undefined ? {} : { submit: options.submit }) });
|
||||
},
|
||||
...(spec.acceptsKeys
|
||||
? {
|
||||
handleKeyEvent: (event) => {
|
||||
this.post({ type: "key", windowId: spec.windowId, event, focused: shell.isWindowFocused(spec.windowId) });
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
setForeground: (foreground) => {
|
||||
this.options.setSurfaceVisible(surfaceId, foreground);
|
||||
if (foreground) {
|
||||
|
||||
Reference in new issue
Block a user