This commit is contained in:
James Babcock committed 2026-08-30 00:42:27 -07:00
commit d542acb891
315 files changed
+35117 -2087

No files matched your search

+107 -1
View File
@@ -223,6 +223,36 @@ export const timeFormatSetting = new ConfigSettingEnum<TimeFormat>({
description: "Whether the top-bar clock shows 24-hour or 12-hour time.",
});
/**
* How much of the 640x480 panel the UI uses. "576x288" is the stock band
* (sidebar + a 288px-tall window at the vertical position); "576x480" keeps
* the sidebar and gives every window the full height; "640x480" is the whole
* panel, with the sidebar an overlay that shows only while it has focus.
*/
export const DISPLAY_MODE_VALUES = ["576x288", "576x480", "640x480"] as const;
export type DisplayModeSetting = (typeof DISPLAY_MODE_VALUES)[number];
const DISPLAY_MODE_LABELS: Record<DisplayModeSetting, string> = {
"576x288": "Band · 576×288",
"576x480": "Tall · 576×480",
"640x480": "Full panel · 640×480",
};
export function displayModeLabel(value: DisplayModeSetting): string {
return DISPLAY_MODE_LABELS[value] ?? value;
}
export const displayModeSetting = new ConfigSettingEnum<DisplayModeSetting>({
id: "display-mode",
label: "Display mode",
storageKey: "display.mode",
defaultValue: "576x288",
values: DISPLAY_MODE_VALUES,
formatValue: displayModeLabel,
description:
"Band: the stock 576×288 window beside the sidebar. Tall: the sidebar plus full-height windows. Full panel: the whole 640×480 display; the sidebar overlays the app only while you are in it. Open apps reopen in the new size.",
});
export const brightnessSetting = new ConfigSettingEnum<BrightnessSetting>({
id: "brightness",
label: "Brightness",
@@ -252,6 +282,69 @@ export const lockScreenEnabledSetting = new ConfigSettingBoolean({
"Lock the glasses after they are taken off while the phone is locked. Unlocking the phone unlocks the glasses.",
});
// Phone display: the phone app's mirror of the glasses screen and the
// controls around it on the main page.
export type PreviewColor = "white" | "green";
export const previewColorSetting = new ConfigSettingEnum<PreviewColor>({
id: "preview-color",
label: "Preview color",
storageKey: "phone.previewColor",
defaultValue: "white",
values: ["white", "green"],
formatValue: (value) => (value === "green" ? "Green" : "White"),
description:
"How the phone's mirror of the glasses display renders: white/grayscale (clearest), or green to match the physical glasses.",
});
export const mirrorTouchSetting = new ConfigSettingBoolean({
id: "mirror-touch",
label: "Touch mirror",
// Key predates this setting object (the toggle used to live on the phone's
// main screen); keeping it preserves the user's choice.
storageKey: "phone.mirrorTouch",
defaultValue: true,
description:
"Let touches on the phone's mirror act on the glasses UI: tap selects what it lands on, double-tap goes back, a hold opens the menu, swipes navigate.",
});
// Wear OS watch remote (app/g2/wear-remote.ts, wear/). All three are read on
// every watch message, so a change applies immediately.
export const watchRemoteEnabledSetting = new ConfigSettingBoolean({
id: "watch-remote-enabled",
label: "Watch remote control",
storageKey: "watch.remoteEnabled",
defaultValue: true,
description:
"Accept input from the Faceclaw Wear OS app: spatial swipes, taps, holds, crown, voice queries and app commands. The ring's scheme is unaffected. Turn off to ignore the watch.",
});
export const watchCanUnlockSetting = new ConfigSettingBoolean({
id: "watch-can-unlock",
label: "Watch can unlock glasses",
storageKey: "watch.canUnlock",
defaultValue: true,
description:
"Let the watch unlock the glasses' lock screen (which otherwise waits for the phone to be unlocked). Your watch is on your wrist; turn this off if you would rather it stay a phone-only unlock.",
});
export const watchCrownClockwiseNextSetting = new ConfigSettingBoolean({
id: "watch-crown-clockwise-next",
label: "Clockwise crown = next",
storageKey: "watch.crownClockwiseNext",
defaultValue: false,
description:
"Choose which crown direction moves to the next item. Off: clockwise moves to the previous item. On: clockwise moves to the next item.",
});
export const watchMirrorAssistantSetting = new ConfigSettingBoolean({
id: "watch-mirror-assistant",
label: "Mirror assistant to watch",
storageKey: "watch.mirrorAssistant",
defaultValue: true,
description: "Stream assistant replies and on-glasses alerts to the watch so they can be read from the wrist.",
});
export type VerticalPosition = "top" | "upper" | "middle" | "lower" | "bottom";
const VERTICAL_POSITION_LABELS: Record<VerticalPosition, string> = {
@@ -297,6 +390,19 @@ export const suspendEvenHubWhenScreenOffSetting = new ConfigSettingBoolean({
description: "Suspend the EvenHub session while the display is off. This significantly improves battery life, but increases the latency of waking the screen.",
});
export type RingConnectionMode = "glasses" | "direct";
export const ringConnectionModeSetting = new ConfigSettingEnum<RingConnectionMode>({
id: "ring-connection-mode",
label: "Ring connection",
storageKey: "developer.ringConnectionMode",
defaultValue: "glasses",
values: ["glasses", "direct"],
formatValue: (value) => (value === "direct" ? "Direct" : "Only via glasses"),
description:
"How R1 ring input reaches the phone. Only via glasses: the ring's own link to the glasses carries its gestures, and the phone never opens a Bluetooth connection to the ring. Direct: also connect to the ring from the phone (currently unreliable). Takes effect on the next connection to the glasses.",
});
export type VoiceProvider = "onboard" | "elevenlabs" | "whisper" | "soniox";
const voiceProviderLabels: Record<VoiceProvider, string> = {
@@ -319,7 +425,7 @@ export const voiceProviderSetting = new ConfigSettingEnum<VoiceProvider>({
if (value === "soniox") return sonioxApiKeySetting.get().trim().length === 0;
return false;
},
description: "Speech-to-text engine for voice input. ElevenLabs, Whisper, and Soniox are cloud services that need an API key, with significantly better accuracy than on-device transcription.",
description: "Speech-to-text engine for voice input. ElevenLabs, Whisper, and Soniox are cloud services that need an API key, with significantly better accuracy than on-device transcription. On-device transcription needs the voice model downloaded (below).",
});
const wakeWordActionLabels: Record<WakeWordAction, string> = {
+133 -1
View File
@@ -12,6 +12,14 @@ import {
onLocalModelStateChanged,
startLocalModelDownload,
} from "../../native/llama";
import {
ASR_MODEL,
asrModelState,
cancelAsrModelDownload,
deleteAsrModel,
onAsrModelStateChanged,
startAsrModelDownload,
} from "../../native/asr-model";
import { TextViewerLayer } from "../../apps/files/text-viewer";
import type { LayerContext } from "../layers";
import { drawRightValueMenuItem, openModalMenu, type MenuItem } from "../menu";
@@ -27,9 +35,13 @@ import {
assistantSkipConfirmationSetting,
batteryDisplayModeSetting,
brightnessSetting,
displayModeSetting,
elevenLabsApiKeySetting,
mapboxApiKeySetting,
mirrorTouchSetting,
openAiApiKeySetting,
previewColorSetting,
ringConnectionModeSetting,
roamApiTokenSetting,
roamGraphNameSetting,
sonioxApiKeySetting,
@@ -48,7 +60,12 @@ import {
voiceProviderSetting,
screenTimeoutSetting,
wakeWordActionSetting,
watchCanUnlockSetting,
watchCrownClockwiseNextSetting,
watchMirrorAssistantSetting,
watchRemoteEnabledSetting,
} from "../dashboard-settings";
import { wearBridge } from "../../native/wear-bridge";
import { SettingsPanelLayer, type SettingsSection } from "./settings-panel";
import { terminalFontPickerMenuItem, uiFontPickerMenuItem } from "../font-picker";
@@ -74,6 +91,8 @@ function settingsSections(): SettingsSection[] {
// Where min-height windows (and the sidebar) sit vertically on the
// screen; the dashboard controller repositions surfaces on change.
enumSettingMenuItem(verticalPositionSetting),
// Band / tall / full-panel; the dashboard controller reflows windows.
enumSettingMenuItem(displayModeSetting),
// Controls the top-bar battery indicators (icon vs percentage).
enumSettingMenuItem(batteryDisplayModeSetting),
// Controls the top-bar clock (24-hour vs 12-hour).
@@ -87,6 +106,7 @@ function settingsSections(): SettingsSection[] {
items: [
enumSettingMenuItem(wakeWordActionSetting),
enumSettingMenuItem(voiceProviderSetting),
asrModelMenuItem(),
],
},
{
@@ -133,9 +153,33 @@ function settingsSections(): SettingsSection[] {
textSettingMenuItem(roamApiTokenSetting),
],
},
{
label: "Phone display",
// The phone app's mirror of the glasses screen and its controls
// (app/phone-ui/): all read live by the main page.
items: [
enumSettingMenuItem(previewColorSetting),
toggleSettingMenuItem(mirrorTouchSetting),
],
},
{
label: "Watch",
// Wear OS remote (wear/); the status line above the items says whether
// a watch running the companion app is currently reachable.
items: [
toggleSettingMenuItem(watchRemoteEnabledSetting),
toggleSettingMenuItem(watchCrownClockwiseNextSetting),
toggleSettingMenuItem(watchCanUnlockSetting),
toggleSettingMenuItem(watchMirrorAssistantSetting),
],
renderDetail: renderWatchStatus,
},
{
label: "Developer",
items: [
// Whether the phone opens its own BLE link to the R1 ring; the
// glasses relay ring gestures either way. Applied at connect time.
enumSettingMenuItem(ringConnectionModeSetting),
toggleSettingMenuItem(saveVoiceRecordingsSetting),
toggleSettingMenuItem(firmwareDebugFlagsSetting),
toggleSettingMenuItem(suspendEvenHubWhenScreenOffSetting),
@@ -240,6 +284,75 @@ function localModelMenuItem(): MenuItem {
};
}
const ASR_MODEL_MB = `${Math.round(ASR_MODEL.totalBytes / 1e6)}MB`;
let asrModelRenderUnsub: (() => void) | null = null;
function watchAsrModelDownload(ctx: LayerContext): void {
asrModelRenderUnsub?.();
asrModelRenderUnsub = onAsrModelStateChanged((state) => {
ctx.actions.requestRender();
if (state.status !== "downloading") {
asrModelRenderUnsub?.();
asrModelRenderUnsub = null;
}
});
}
function asrModelStatusText(): string {
const state = asrModelState();
if (state.status === "ready") return "downloaded";
if (state.status === "downloading") {
const pct = state.totalBytes > 0 ? Math.floor((state.bytesDownloaded / state.totalBytes) * 100) : 0;
return `${pct}% of ${ASR_MODEL_MB}`;
}
return "not downloaded";
}
/** Download/cancel/delete management for the on-device transcription model. */
function asrModelMenuItem(): MenuItem {
return {
label: "On-device voice model",
description:
`${ASR_MODEL.label} (${ASR_MODEL_MB} download). ` +
"Transcribes voice input on the phone itself, with no API key or cloud service. " +
"Required for the On-device transcription provider; the cloud providers work without it. " +
"An interrupted download resumes where it left off.",
onSelect: (ctx) => {
const state = asrModelState();
const action: MenuItem =
state.status === "downloading"
? {
label: "Cancel download",
onSelect: (innerCtx) => {
cancelAsrModelDownload();
innerCtx.stack.pop();
},
}
: state.status === "ready"
? {
label: "Delete model",
onSelect: (innerCtx) => {
deleteAsrModel();
innerCtx.stack.pop();
},
}
: {
label: `Download (${ASR_MODEL_MB})`,
onSelect: (innerCtx) => {
startAsrModelDownload();
watchAsrModelDownload(innerCtx);
innerCtx.stack.pop();
},
};
openModalMenu(ctx, "On-device voice model", [action], 0);
},
render: ({ image, x, y, width }) => {
drawRightValueMenuItem(image, getDefaultSmallFont(), x, y, width, "On-device voice model", asrModelStatusText());
},
};
}
/** A row that opens one of the project docs (copied into the bundle under
* about/ by webpack.config.js) in the paged text viewer. */
function bundledDocMenuItem(fileName: string, label: string): MenuItem {
@@ -260,6 +373,25 @@ function readBundledDoc(fileName: string): string {
}
}
function renderWatchStatus(args: { image: GrayImage; x: number; y: number; width: number }): number {
const { image, x, y, width } = args;
const font = getDefaultSmallFont();
let status: string;
if (!wearBridge.isAvailable()) {
status = "Google Play services is unavailable on this phone, so no watch can connect.";
} else {
const connection = wearBridge.getWatchConnection();
status = connection.reachable
? `Connected to ${connection.watchName || "a watch"}.`
: "No watch connected. Install the Faceclaw watch app (wear/ in the source tree) on a Wear OS watch paired with this phone.";
}
const lines = wrapText(font, status, width);
for (let i = 0; i < lines.length; i++) {
image.drawText(font, x, y + i * font.lineHeight, lines[i]!, 170);
}
return lines.length * font.lineHeight + 10;
}
function renderAbout(args: { image: GrayImage; x: number; y: number; width: number }): number {
const { image, x, y, width } = args;
const font = getDefaultSmallFont();
@@ -270,7 +402,7 @@ function renderAbout(args: { image: GrayImage; x: number; y: number; width: numb
const textX = logo ? x + logo.width + 12 : x;
image.drawText(font, textX, y + 8, "Faceclaw", 220);
image.drawText(font, textX, y + 24, `v${FACECLAW_VERSION}`, 170);
const blurb = "By James Babcock. Distributed under the GNU General Public License, version 3.";
const blurb = "By James Babcock and other contributors. Distributed under the GNU General Public License, version 3.";
const blurbY = y + Math.max(64, logo ? logo.height + 12 : 0);
const blurbLines = wrapText(font, blurb, width);
for (let i = 0; i < blurbLines.length; i++) {
+13
View File
@@ -41,6 +41,9 @@ const NO_MENU = new MenuLayer(null, []);
* column, out to the sidebar). Third-level menus open as centered modals.
*/
export class SettingsPanelLayer implements Layer {
// Watch swipes map onto the two columns: right goes into a section's
// items, left comes back out (and out to the sidebar from the left column).
readonly acceptsDirectional = true;
private leftIndex = 0;
private rightIndex = 0;
private focus: "left" | "right" = "left";
@@ -185,14 +188,17 @@ export class SettingsPanelLayer implements Layer {
if (this.focus === "left") {
switch (event.type) {
case "scroll-up":
case "swipe-up":
this.leftIndex = (this.leftIndex + this.sections.length - 1) % this.sections.length;
this.resetRight();
return;
case "scroll-down":
case "swipe-down":
this.leftIndex = (this.leftIndex + 1) % this.sections.length;
this.resetRight();
return;
case "click":
case "swipe-right":
// Only enter sections that have something interactive on the right.
if (this.section().items.length) {
this.focus = "right";
@@ -200,6 +206,7 @@ export class SettingsPanelLayer implements Layer {
}
return;
case "double-click":
case "swipe-left":
shell.yieldFocusToSidebar();
return;
default:
@@ -210,18 +217,22 @@ export class SettingsPanelLayer implements Layer {
const items = this.section().items;
switch (event.type) {
case "scroll-up":
case "swipe-up":
if (items.length) this.rightIndex = (this.rightIndex + items.length - 1) % items.length;
return;
case "scroll-down":
case "swipe-down":
if (items.length) this.rightIndex = (this.rightIndex + 1) % items.length;
return;
case "click":
case "swipe-right":
if (items.length) {
const item = items[clamp(this.rightIndex, 0, items.length - 1)]!;
if (!isMenuItemDisabled(item)) await item.onSelect(ctx, NO_MENU);
}
return;
case "double-click":
case "swipe-left":
this.focus = "left";
return;
default:
@@ -242,6 +253,8 @@ export class SettingsPanelLayer implements Layer {
* layers (modal menus, the text editor) stack above it as before.
*/
export class SettingsDescriptionOverlayLayer implements Layer {
readonly acceptsDirectional = true;
constructor(private readonly panel: SettingsPanelLayer) {}
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
+109 -7
View File
@@ -8,13 +8,35 @@ export type TextSettingsEditToggle = {
label: string;
};
/**
* Where an input came from. The ring and the glasses' arms are the stock
* sources; "watch" is the Wear OS remote, which components may treat with a
* richer scheme (see isWatchInput) — the ring's semantics are never changed
* by it.
*/
export type InputSource = "ring" | "left-arm" | "right-arm" | "watch";
export type DashboardInputEvent =
| { type: "click"; source: "ring" | "left-arm" | "right-arm" }
| { type: "double-click"; source: "ring" | "left-arm" | "right-arm" }
| { type: "scroll-up" }
| { type: "scroll-down" }
| { type: "long-press"; source: "ring" | "left-arm" | "right-arm" }
| { type: "long-press-release"; source: "ring" | "left-arm" | "right-arm" }
| { type: "click"; source: InputSource }
| { type: "double-click"; source: InputSource }
/** Ring scroll (or a watch crown turn, then tagged source "watch"). */
| { type: "scroll-up"; source?: InputSource }
| { type: "scroll-down"; source?: InputSource }
| { type: "long-press"; source: InputSource }
| { type: "long-press-release"; source: InputSource }
/**
* Spatial (four-way) input, which only a watch can produce: the ring's
* scroll is a one-dimensional cursor, these are directions. Components with
* a spatial meaning for them opt in with Layer.acceptsDirectional /
* ShellWindow.acceptsDirectional and must then handle all four; for the
* rest, directionalFallback turns up/down into scroll, right into "select"
* (click) and left into "back" (double-click), so a swipe always does
* something sensible.
*/
| { type: "swipe-up"; source: "watch" }
| { type: "swipe-down"; source: "watch" }
| { type: "swipe-left"; source: "watch" }
| { type: "swipe-right"; source: "watch" }
/**
* The stock display lifecycle woke while no EvenHub page was running. This
* is wake-only, unlike a normal double-click (which turns an on screen off).
@@ -29,6 +51,44 @@ export type DashboardInputEvent =
| { type: "wakeword" }
| { type: "unknown"; kind: string; eventSource: number; eventType: number };
/** True for input from the Wear OS remote (any type that carries a source). */
export function isWatchInput(event: DashboardInputEvent): boolean {
return "source" in event && event.source === "watch";
}
export type DirectionalInputEvent = Extract<
DashboardInputEvent,
{ type: "swipe-up" | "swipe-down" | "swipe-left" | "swipe-right" }
>;
export function isDirectionalInput(event: DashboardInputEvent): event is DirectionalInputEvent {
return (
event.type === "swipe-up" ||
event.type === "swipe-down" ||
event.type === "swipe-left" ||
event.type === "swipe-right"
);
}
/**
* The ring-vocabulary equivalent of a directional swipe: up/down scroll,
* right selects, left backs out.
*/
export function directionalFallback(event: DashboardInputEvent): DashboardInputEvent {
switch (event.type) {
case "swipe-up":
return { type: "scroll-up" };
case "swipe-down":
return { type: "scroll-down" };
case "swipe-right":
return { type: "click", source: "ring" };
case "swipe-left":
return { type: "double-click", source: "ring" };
default:
return event;
}
}
export type LayerActions = {
/** Ask for a dashboard repaint+transmit, e.g. when async data arrives. */
requestRender: () => void;
@@ -102,6 +162,17 @@ export interface Layer {
readonly paintOverBase?: boolean;
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage;
handleInput(event: DashboardInputEvent, ctx: LayerContext): Promise<void> | void;
/**
* True when handleInput gives swipe-left / swipe-right a meaning of its own.
* Otherwise the stack hands the layer directionalFallback(event) instead.
*/
readonly acceptsDirectional?: boolean;
/**
* A touch at (x, y) in this layer's own canvas coordinates, from the phone's
* mirror view. Return true if the layer acted on it (selected / opened what
* is there); false sends a plain select (click) instead.
*/
hitTest?(x: number, y: number, ctx: LayerContext): Promise<boolean> | boolean;
/** Called when the layer leaves the stack by any path (pop or clearToBase). */
onRemoved?(): void;
/**
@@ -173,6 +244,21 @@ export class LayerStack {
}
}
/**
* Pop layers down to and including the given one, wherever it sits in the
* stack (e.g. dismissing the assistant while a follow-up voice dialog is
* open above it). Returns false if the layer isn't stacked (the base layer
* can never be popped). Removal callbacks fire top-down.
*/
popThrough(layer: Layer): boolean {
const index = this.layers.indexOf(layer);
if (index <= 0) return false;
for (const removed of this.layers.splice(index).reverse()) {
notifyRemoved(removed);
}
return true;
}
isAtBase(): boolean {
return this.layers.length === 1;
}
@@ -201,7 +287,23 @@ export class LayerStack {
}
async handleInput(event: DashboardInputEvent): Promise<void> {
await this.layers[this.layers.length - 1]!.handleInput(event, this.ctx);
const top = this.layers[this.layers.length - 1]!;
const delivered = isDirectionalInput(event) && !top.acceptsDirectional ? directionalFallback(event) : event;
await top.handleInput(delivered, this.ctx);
}
/**
* Pass a mirror touch to the base layer when nothing is stacked on it.
* With a layer stacked (a menu, a dialog) the touch is consumed without
* acting: positions mean nothing to the overlay, and falling back to a
* blind synthetic click would activate whatever happens to be highlighted
* rather than what was tapped.
*/
async hitTest(x: number, y: number): Promise<boolean> {
if (this.layers.length !== 1) return true;
const base = this.layers[0]!;
if (!base.hitTest) return false;
return await base.hitTest(x, y, this.ctx);
}
/** Hand text to the top layer; false if it doesn't take text input. */
+91
View File
@@ -0,0 +1,91 @@
/**
* Ambient cards: small, non-interactive popups the shell chrome paints at the
* bottom-right of the screen, stacking upward — used for the "you know this
* person" encounter popup when captions recognize a familiar voice. Unlike
* the notification modal they never take input or focus: they appear, sit
* quietly for a few seconds, and expire on their own.
*
* Pure store + change notification; painting lives in the chrome layer, and
* the shell subscribes to changes to request repaints.
*/
export type AmbientCard = {
/** Stable identity: posting the same id replaces the existing card. */
id: string;
/** Bright first line (e.g. "Alice · 2d ago"). */
title: string;
/** Dimmer detail lines (fact, action items); painted in order, truncated to fit. */
lines: string[];
expiresAtMs: number;
};
const cards: AmbientCard[] = [];
const listeners = new Set<() => void>();
let expiryTimer: ReturnType<typeof setTimeout> | null = null;
/** Cards still alive, oldest first (painted bottom-up, so oldest sits lowest). */
export function activeAmbientCards(nowMs = Date.now()): AmbientCard[] {
prune(nowMs);
return cards;
}
/** Post (or refresh) a card; repaints happen via the change listeners. */
export function postAmbientCard(card: AmbientCard): void {
const index = cards.findIndex((existing) => existing.id === card.id);
if (index >= 0) {
cards.splice(index, 1);
}
cards.push(card);
scheduleExpiry();
notify();
}
export function dismissAmbientCard(id: string): void {
const index = cards.findIndex((existing) => existing.id === id);
if (index >= 0) {
cards.splice(index, 1);
notify();
}
}
export function onAmbientCardsChanged(listener: () => void): () => void {
listeners.add(listener);
return () => listeners.delete(listener);
}
function prune(nowMs: number): void {
const before = cards.length;
for (let index = cards.length - 1; index >= 0; index--) {
if (cards[index]!.expiresAtMs <= nowMs) {
cards.splice(index, 1);
}
}
if (cards.length !== before) {
scheduleExpiry();
}
}
/** One timer for the next expiry, so a card's disappearance also repaints. */
function scheduleExpiry(): void {
if (expiryTimer !== null) {
clearTimeout(expiryTimer);
expiryTimer = null;
}
if (!cards.length) return;
const next = Math.min(...cards.map((card) => card.expiresAtMs));
expiryTimer = setTimeout(() => {
expiryTimer = null;
prune(Date.now());
notify();
}, Math.max(50, next - Date.now()));
}
function notify(): void {
listeners.forEach((listener) => {
try {
listener();
} catch (error) {
console.warn(`ambient card listener failed: ${error}`);
}
});
}
+102 -16
View File
@@ -1,5 +1,7 @@
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
import { getDefaultMediumFont, getDefaultSmallFont } from "../../graphics/ui-fonts";
import { truncateText } from "../../graphics/textwrap";
import { activeAmbientCards } from "./ambient-cards";
import { BATTERY_ICON_WIDTH, drawBattery } from "../../graphics/battery";
import { readActiveNotificationIcons } from "../../native/notification-icons";
import { readPhoneBatteryState } from "../../native/phone-battery";
@@ -8,11 +10,13 @@ import { renderIcon, renderIconWithGlyph, type IconName } from "../../graphics/i
import { batteryDisplayModeSetting, timeFormatSetting } from "../dashboard-settings";
import { Layer } from "../layers";
import { scrollToKeepSelectionVisible } from "../menu";
import { lineStep } from "../metrics";
import {
MIN_WINDOW_HEIGHT,
minWindowTop,
SHELL_OPAQUE_BLACK,
SIDEBAR_WIDTH,
sidebarStripVisible,
TOP_BAR_HEIGHT,
windowTop,
type WindowHeightMode,
@@ -50,6 +54,25 @@ function columnLeft(variant: SidebarVariant, column: number): number {
return SIDEBAR_WIDTH - (variant.columns - column) * variant.columnWidth;
}
/**
* Column and top y of a visible sidebar slot; `position` counts from the
* first visible (scrolled-to) icon. Slots fill the rightmost column top to
* bottom, then overflow leftward. The single source of slot geometry for
* both drawing and hit testing.
*/
function slotPosition(variant: SidebarVariant, listTop: number, position: number): { column: number; y: number } {
const rows = rowsPerColumn(variant);
return {
column: variant.columns - 1 - ((position / rows) | 0),
y: listTop + (position % rows) * (variant.iconSize + ICON_SPACING),
};
}
/** Top y of the sidebar's icon list (below the band's top bar). */
function sidebarListTop(): number {
return minWindowTop() + TOP_BAR_HEIGHT + LIST_MARGIN;
}
/**
* Left edge of the sidebar region that actually holds icons: the one-column
* variant leaves a dead strip left of its single right-aligned column.
@@ -166,8 +189,13 @@ export class ShellChromeLayer implements Layer {
paint(): GrayImage {
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
const state = this.getState();
this.drawSidebar(image, state);
// Full-panel mode: the strip is an overlay, present only while the user
// is in it (the window underneath keeps its full width the rest of the time).
if (sidebarStripVisible(state.focus)) {
this.drawSidebar(image, state);
}
this.drawTopBar(image, state);
drawAmbientCards(image);
return image;
}
@@ -176,6 +204,26 @@ export class ShellChromeLayer implements Layer {
// layer stack; the chrome itself never consumes events.
}
/**
* Which window's sidebar icon is under (x, y) on screen, if any — the same
* slot geometry drawSidebar uses, so a touch on the phone's mirror lands on
* the icon the mirror showed.
*/
windowIndexAt(x: number, y: number, windowCount: number): number | null {
if (x < 0 || x >= SIDEBAR_WIDTH || windowCount === 0) return null;
const variant = sidebarVariant(windowCount);
const listTop = sidebarListTop();
const lastVisible = Math.min(windowCount, this.scrollRow + rowsPerColumn(variant) * variant.columns);
for (let index = this.scrollRow; index < lastVisible; index++) {
const { column, y: slotY } = slotPosition(variant, listTop, index - this.scrollRow);
const left = columnLeft(variant, column);
if (x >= left && x < left + variant.columnWidth && y >= slotY - 2 && y < slotY + variant.iconSize + 2) {
return index;
}
}
return null;
}
private drawSidebar(image: GrayImage, state: ShellChromeState): void {
// The sidebar always occupies the min-height window band at the preferred
// vertical position: it never moves when the foreground window's height
@@ -194,20 +242,11 @@ export class ShellChromeLayer implements Layer {
const iconMarginX = ((variant.columnWidth - iconSize) / 2) | 0;
// Column index of the rightmost column (the one that fills first).
const firstColumn = variant.columns - 1;
const listTop = bandTop + TOP_BAR_HEIGHT + LIST_MARGIN;
const itemStride = iconSize + ICON_SPACING;
const rows = rowsPerColumn(variant);
const visibleCount = rows * variant.columns;
const listTop = sidebarListTop();
const visibleCount = rowsPerColumn(variant) * variant.columns;
this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, state.selectedIndex, visibleCount, count);
const lastVisible = Math.min(count, this.scrollRow + visibleCount);
const slotOf = (index: number) => {
const position = index - this.scrollRow;
const columnsFromRight = (position / rows) | 0;
return {
column: firstColumn - columnsFromRight,
y: listTop + (position % rows) * itemStride,
};
};
const slotOf = (index: number) => slotPosition(variant, listTop, index - this.scrollRow);
// The selection is a "diversion" of the sidebar/main separator line: the
// line bulges right around the selected icon (rounded on the left, open
@@ -266,13 +305,16 @@ export class ShellChromeLayer implements Layer {
// its height mode puts that (screen top for max height). It moves when
// the foreground switches to a window of a different height.
const barTop = windowTop(state.foregroundHeightMode);
image.fillRect(SIDEBAR_WIDTH, barTop, G2_LENS_WIDTH - SIDEBAR_WIDTH, TOP_BAR_HEIGHT, SHELL_OPAQUE_BLACK);
image.drawLine(SIDEBAR_WIDTH, barTop + TOP_BAR_HEIGHT - 1, G2_LENS_WIDTH - 1, barTop + TOP_BAR_HEIGHT - 1, BORDER_VALUE);
// The bar spans the app viewport; with the sidebar overlaid (full-panel
// mode, sidebar focused) it still starts past the strip.
const barLeft = sidebarStripVisible(state.focus) ? SIDEBAR_WIDTH : 0;
image.fillRect(barLeft, barTop, G2_LENS_WIDTH - barLeft, TOP_BAR_HEIGHT, SHELL_OPAQUE_BLACK);
image.drawLine(barLeft, barTop + TOP_BAR_HEIGHT - 1, G2_LENS_WIDTH - 1, barTop + TOP_BAR_HEIGHT - 1, BORDER_VALUE);
const now = new Date();
const clock = `${WEEKDAYS[now.getDay()]} ${now.getDate()} ${MONTHS[now.getMonth()]} ` +
formatClockTime(now);
const clockX = SIDEBAR_WIDTH + 10;
const clockX = barLeft + 10;
const textY = barTop + Math.max(0, ((TOP_BAR_HEIGHT - font.lineHeight) / 2) | 0);
image.drawText(font, clockX, textY, clock, 210);
@@ -344,6 +386,50 @@ export class ShellChromeLayer implements Layer {
}
}
// Ambient cards (encounter popups): compact and deliberately unobtrusive,
// anchored to the bottom-right of the window band and stacking upward, clear
// of the caption area's left-aligned text. Never interactive.
const AMBIENT_CARD_WIDTH = 230;
const AMBIENT_CARD_MARGIN = 6;
const AMBIENT_CARD_GAP = 4;
const AMBIENT_CARD_PADDING_X = 8;
const AMBIENT_CARD_PADDING_Y = 4;
const AMBIENT_MAX_LINES_PER_CARD = 3;
/**
* Paint the active ambient cards bottom-up: the oldest card sits at the very
* bottom of the window band and newer ones stack above it. Cards that would
* cross into the top bar are dropped rather than clipped.
*/
function drawAmbientCards(image: GrayImage): void {
const cards = activeAmbientCards();
if (!cards.length) return;
const font = getDefaultSmallFont();
const bandTop = minWindowTop();
const bandBottom = bandTop + MIN_WINDOW_HEIGHT;
const x = G2_LENS_WIDTH - AMBIENT_CARD_WIDTH - AMBIENT_CARD_MARGIN;
const textWidth = AMBIENT_CARD_WIDTH - 2 * AMBIENT_CARD_PADDING_X;
let bottom = bandBottom - AMBIENT_CARD_MARGIN;
for (const card of cards) {
const lines = [card.title, ...card.lines].slice(0, 1 + AMBIENT_MAX_LINES_PER_CARD);
const height = 2 * AMBIENT_CARD_PADDING_Y + lines.length * lineStep(font);
const y = bottom - height;
if (y < bandTop + TOP_BAR_HEIGHT) break;
image.fillRoundedRect(x, y, AMBIENT_CARD_WIDTH, height, SHELL_OPAQUE_BLACK, 6);
image.drawRoundedRect(x, y, AMBIENT_CARD_WIDTH, height, 90, 6);
for (let index = 0; index < lines.length; index++) {
image.drawText(
font,
x + AMBIENT_CARD_PADDING_X,
y + AMBIENT_CARD_PADDING_Y + index * lineStep(font),
truncateText(font, lines[index]!, textWidth),
index === 0 ? 220 : 160,
);
}
bottom = y - AMBIENT_CARD_GAP;
}
}
/**
* Draw app tray icons right-to-left, ending just left of the battery block;
* returns the left edge of the tray region.
+40 -8
View File
@@ -1,15 +1,47 @@
import { G2_LENS_HEIGHT, G2_LENS_WIDTH } from "../../graphics/image";
import { verticalPositionSetting } from "../dashboard-settings";
import { displayModeSetting, type DisplayModeSetting, verticalPositionSetting } from "../dashboard-settings";
/** Top bar: 24px notification icons plus a little padding. */
export const TOP_BAR_HEIGHT = 28;
/**
* Sidebar width. Leaves the app viewport exactly 576px wide — the surface
* width EvenHub apps expect. Icon column layout within the strip (one wide
* column vs. two narrow ones) is the chrome layer's business.
* Width of the sidebar strip as painted. Leaves the app viewport exactly
* 576px wide — the surface width EvenHub apps expect — except in the
* full-panel display mode, where the strip overlays the app (see
* sidebarWidth). Icon column layout within the strip (one wide column vs.
* two narrow ones) is the chrome layer's business.
*/
export const SIDEBAR_WIDTH = 64;
/** The Display > Display mode setting (see dashboard-settings.ts). */
export function displayMode(): DisplayModeSetting {
return displayModeSetting.get();
}
/**
* How much of the screen's width the sidebar takes away from app windows:
* the strip, or nothing in the full-panel mode (where the chrome paints the
* strip over the window while the sidebar has focus).
*/
export function sidebarWidth(): number {
return displayMode() === "640x480" ? 0 : SIDEBAR_WIDTH;
}
/**
* Whether the sidebar strip is on screen: always when it reserves width; in
* the full-panel mode (where it overlays the window) only while it has focus.
*/
export function sidebarStripVisible(focus: "sidebar" | "window"): boolean {
return sidebarWidth() > 0 || focus === "sidebar";
}
/**
* The height an app's requested mode actually gets: the band mode honours
* it, the taller modes give every window the whole screen.
*/
export function effectiveHeightMode(mode: WindowHeightMode): WindowHeightMode {
return displayMode() === "576x288" ? mode : "max";
}
/**
* X of the display's true horizontal centre, in app-viewport coordinates. The
* sidebar pushes the viewport to the right, so UI the wearer physically aims
@@ -17,7 +49,7 @@ export const SIDEBAR_WIDTH = 64;
* than use the viewport's own centre.
*/
export function screenCenterInViewportX(): number {
return Math.round(G2_LENS_WIDTH / 2) - SIDEBAR_WIDTH;
return Math.round(G2_LENS_WIDTH / 2) - sidebarWidth();
}
/**
@@ -43,7 +75,7 @@ export const MIN_WINDOW_MAX_TOP = G2_LENS_HEIGHT - MIN_WINDOW_HEIGHT;
/** Total height (top bar + content) of a window's band in the given mode. */
export function windowBandHeight(mode: WindowHeightMode): number {
switch (mode) {
switch (effectiveHeightMode(mode)) {
case "max":
return G2_LENS_HEIGHT;
case "medium":
@@ -89,7 +121,7 @@ export function windowTop(mode: WindowHeightMode): number {
/** App-content viewport size for a height mode (independent of vertical position). */
export function appViewportSize(mode: WindowHeightMode): { width: number; height: number } {
return {
width: G2_LENS_WIDTH - SIDEBAR_WIDTH,
width: G2_LENS_WIDTH - sidebarWidth(),
height: windowBandHeight(mode) - TOP_BAR_HEIGHT,
};
}
@@ -102,7 +134,7 @@ export function appViewportRect(mode: WindowHeightMode): {
height: number;
} {
return {
x: SIDEBAR_WIDTH,
x: sidebarWidth(),
y: windowTop(mode) + TOP_BAR_HEIGHT,
...appViewportSize(mode),
};
+22
View File
@@ -168,6 +168,9 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
title: options.title,
surfaceId: `window:${options.windowId}`,
closeable: options.closeable,
// The window's own LayerStack decides per layer whether a swipe is
// directional or falls back to click / double-click.
acceptsDirectional: true,
heightMode,
close: () => {
closed = true;
@@ -195,6 +198,16 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
await render(frameId);
},
requestRender,
relayout: () => {
stack.setBaseSize(appViewportSize(heightMode));
options.reconfigureSurface?.(heightMode);
requestRender();
},
hitTest: async (x, y) => {
const handled = await stack.hitTest(x, y);
if (handled) requestRender();
return handled;
},
receiveTextInput: options.receiveTextInput,
setForeground: (foreground) => {
options.setSurfaceVisible(foreground);
@@ -223,6 +236,15 @@ export class YieldAtRootLayer implements Layer {
return this.inner.paintOverBase;
}
/** Directional swipes reach the inner layer only if it understands them. */
get acceptsDirectional(): boolean | undefined {
return this.inner.acceptsDirectional;
}
hitTest(x: number, y: number, ctx: LayerContext): Promise<boolean> | boolean {
return this.inner.hitTest ? this.inner.hitTest(x, y, ctx) : false;
}
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
return this.inner.paint(ctx, paintBelow);
}
+19 -14
View File
@@ -4,16 +4,20 @@ import { DashboardInputEvent, Layer, LayerActions, LayerContext, LayerStack, Pai
import { appViewportRect, appViewportSize, SHELL_OPAQUE_BLACK } from "./geometry";
// The modal covers most of the min-height app viewport, leaving a little of
// the foreground app visible around the edges. Its size is fixed (min-height
// windows have a fixed viewport size); its position follows the vertical
// position setting, so it is computed per paint.
// the foreground app visible around the edges. Both its size and position are
// computed per paint: the display-mode setting changes the viewport size at
// runtime, and the vertical position setting moves the band.
const MODAL_MARGIN = 14;
const MODAL_PADDING = 4;
export const MODAL_INTERIOR = {
width: appViewportSize("min").width - 2 * MODAL_MARGIN - 2 * MODAL_PADDING,
height: appViewportSize("min").height - 2 * MODAL_MARGIN - 2 * MODAL_PADDING,
} as const;
/** Content (inner layer stack) size of the modal box. */
function modalInterior(): { width: number; height: number } {
const viewport = appViewportSize("min");
return {
width: viewport.width - 2 * MODAL_MARGIN - 2 * MODAL_PADDING,
height: viewport.height - 2 * MODAL_MARGIN - 2 * MODAL_PADDING,
};
}
/** Screen rect of the modal box, aligned to the min-height window band. */
export function modalRect(): { x: number; y: number; width: number; height: number } {
@@ -36,17 +40,18 @@ export class ShellModalLayer implements Layer {
private readonly stack: LayerStack;
constructor(baseLayer: Layer, actions: LayerActions) {
this.stack = new LayerStack(baseLayer, actions, {
width: MODAL_INTERIOR.width,
height: MODAL_INTERIOR.height,
});
this.stack = new LayerStack(baseLayer, actions, modalInterior());
}
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
paint(_ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
const image = paintBelow();
// Track a display-mode switch while the modal is up, so the inner stack
// paints at the same size the box below is drawn with.
const interior = modalInterior();
this.stack.setBaseSize(interior);
// Flattening bakes the inner stack's planes (glyphs included) so the blit
// below transplants the finished modal content into this layer's plane.
const inner = flattenPlanes(this.stack.paint(), MODAL_INTERIOR);
const inner = flattenPlanes(this.stack.paint(), interior);
const rect = modalRect();
image.fillRoundedRect(rect.x, rect.y, rect.width, rect.height, SHELL_OPAQUE_BLACK, 8);
image.drawRoundedRect(rect.x, rect.y, rect.width, rect.height, 110, 8);
@@ -54,7 +59,7 @@ export class ShellModalLayer implements Layer {
return image;
}
async handleInput(event: DashboardInputEvent, ctx: LayerContext): Promise<void> {
async handleInput(event: DashboardInputEvent, _ctx: LayerContext): Promise<void> {
await this.stack.handleInput(event);
}
}
+188 -25
View File
@@ -1,9 +1,19 @@
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
import { singlePlane, type Plane } from "../../graphics/plane";
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { EvenAIStatus, EventSourceType, OsEventTypeList } from "../../g2/events";
import { EvenAIStatus, EventSourceType, OsEventTypeList, WatchGestureType } from "../../g2/events";
import type { RawInputEvent } from "../../native/faceclaw-communicator";
import { DashboardInputEvent, Layer, LayerActions, LayerContext, LayerStack, noopLayerActions } from "../layers";
import {
DashboardInputEvent,
directionalFallback,
type InputSource,
isDirectionalInput,
Layer,
LayerActions,
LayerContext,
LayerStack,
noopLayerActions,
} from "../layers";
import { MenuLayer, type MenuItem } from "../menu";
import { VoiceInputLayer, type VoiceSendTarget } from "./voice-input";
import { voiceActivity } from "./voice-activity";
@@ -26,13 +36,14 @@ import {
timeFormatSetting,
wakeWordActionSetting,
} from "../dashboard-settings";
import { onAmbientCardsChanged } from "./ambient-cards";
import { ShellChromeLayer, sidebarContentLeft, type ShellChromeState, type ShellChromeWindow } from "./chrome-layer";
import { ShellModalLayer } from "./modal-layer";
import { ToolDebugMenuLayer } from "./tool-debug-layer";
import { toolRegistry } from "../../assistant/tool-registry";
import {
minWindowTop,
SIDEBAR_WIDTH,
sidebarWidth,
TOP_BAR_HEIGHT,
windowBandHeight,
windowTop,
@@ -62,6 +73,11 @@ export type ShellWindow = {
surfaceId: string;
/** Whether close menu entries (app menu default, shell escape menu) apply (the launcher is pinned). */
closeable: boolean;
/**
* True when the window gives swipe-left / swipe-right (watch directional
* input) a meaning; otherwise the shell forwards directionalFallback(event).
*/
acceptsDirectional?: boolean;
/**
* Window height: the standard 288px band ("min") or the full screen
* ("max", terminal views). Decides the surface rect and where the shell
@@ -79,6 +95,17 @@ export type ShellWindow = {
handleInput: (event: DashboardInputEvent, frameId: number) => Promise<void> | void;
/** Repaint and resubmit this window's surface. */
requestRender: () => void;
/**
* Re-measure against the current display mode (viewport size / band) and
* repaint. Windows without it (workers, whose canvas is fixed at open) are
* closed and relaunched by the controller instead.
*/
relayout?: () => void;
/**
* A touch from the phone's mirror at (x, y) in app-viewport coordinates.
* True if the window acted on it; otherwise the controller sends a select.
*/
hitTest?: (x: number, y: number) => Promise<boolean> | boolean;
/**
* Deliver a text string to the window (e.g. finalized voice input). Optional:
* only windows that consume typed text (the terminal) implement it.
@@ -104,7 +131,18 @@ export type ShellConfig = {
/** Which surfaces need re-rendering after an input event. */
export type ShellInputOutcome = { shell: boolean; window: boolean };
type FocusKind = "sidebar" | "window";
/**
* Assistant overlay activity, for mirrors outside the glasses (the watch).
* "streaming" carries the reply so far (replace semantics); "done" the final
* reply; "error" the message; "closed" fires when the overlay leaves the
* stack by any path.
*/
export type AssistantActivityEvent = {
phase: "thinking" | "streaming" | "done" | "error" | "closed";
text: string;
};
export type FocusKind = "sidebar" | "window";
const noopActions: LayerActions = noopLayerActions;
@@ -119,9 +157,10 @@ const LONG_PRESS_ESCAPE_MENU_MS = 4000;
class ShellOverlayMenuLayer extends MenuLayer {
constructor(items: MenuItem[], private readonly onClosed: () => void) {
// Aligned to the min-height window band (like the sidebar), wherever the
// vertical position setting currently puts it.
// vertical position setting currently puts it; past the sidebar strip
// where one reserves width (none in the full-panel mode).
super(null, items, {
x: SIDEBAR_WIDTH + 8,
x: sidebarWidth() + 8,
y: minWindowTop() + TOP_BAR_HEIGHT + 8,
width: 272,
minHeight: 0,
@@ -209,6 +248,8 @@ class Shell {
private activeVoiceLayer: VoiceInputLayer | null = null;
private assistantSession: AssistantSession | null = null;
private assistantLayer: AssistantLayer | null = null;
private readonly assistantActivityListeners = new Set<(event: AssistantActivityEvent) => void>();
private readonly alertListeners = new Set<(text: string) => void>();
private escapeMenuTimer: ReturnType<typeof setTimeout> | null = null;
private readonly actions: LayerActions = { ...noopActions };
private config: ShellConfig = {
@@ -217,10 +258,8 @@ class Shell {
requestShellRender: () => {},
onScreenStateChanged: () => {},
};
private readonly stack = new LayerStack(
new ShellChromeLayer(() => this.chromeState()),
this.actions,
);
private readonly chrome = new ShellChromeLayer(() => this.chromeState());
private readonly stack = new LayerStack(this.chrome, this.actions);
// Top-bar settings we mirror into the chrome; a change to either repaints
// the shell surface so the top bar reflects it immediately.
@@ -232,6 +271,21 @@ class Shell {
this.config = config;
this.stack.setActions(config.actions);
this.subscribeToTopBarSettings();
this.subscribeToAmbientCards();
}
// Ambient (encounter) cards live in the chrome paint; a posted or expired
// card repaints the shell surface so it appears and disappears on time.
private ambientCardsSubscribed = false;
private subscribeToAmbientCards(): void {
if (this.ambientCardsSubscribed) return;
this.ambientCardsSubscribed = true;
onAmbientCardsChanged(() => {
if (this.screenOn) {
this.config.requestShellRender();
}
});
}
private subscribeToTopBarSettings(): void {
@@ -379,6 +433,22 @@ class Shell {
this.lastInputAtMs = nowMs;
}
/** Where input currently goes: the sidebar strip or the foreground window. */
getFocus(): FocusKind {
return this.focus;
}
/** True while a shell overlay (menu, dialog, voice input) is above the chrome. */
hasOverlay(): boolean {
return !this.stack.isAtBase();
}
/** The window whose sidebar icon is at screen (x, y), for mirror touches. */
windowAtSidebarPoint(x: number, y: number): ShellWindow | null {
const index = this.chrome.windowIndexAt(x, y, this.windows.length);
return index === null ? null : this.windows[index] ?? null;
}
/** Turn the screen on (if off) and set focus. Returns whether it was off. */
wake(focus: FocusKind, nowMs = Date.now()): boolean {
this.lastInputAtMs = nowMs;
@@ -572,7 +642,8 @@ class Shell {
const window = this.foregroundWindow();
if (window) {
// The window owns frameId from here (render or explicit finish).
await window.handleInput(event, frameId);
const delivered = isDirectionalInput(event) && !window.acceptsDirectional ? directionalFallback(event) : event;
await window.handleInput(delivered, frameId);
return { shell: false, window: true };
}
return { shell: false, window: false };
@@ -630,15 +701,23 @@ class Shell {
private handleSidebarInput(event: DashboardInputEvent): ShellInputOutcome {
switch (event.type) {
case "double-click":
// A double-tap at the root (the app switcher selected) turns the
// display off — from the ring and the watch scheme alike; watch-scheme
// gestures wake it again (or a ring double-tap does).
this.sleep();
return { shell: true, window: false };
case "scroll-up":
case "swipe-up":
this.moveSelection(-1);
return { shell: true, window: false };
case "scroll-down":
case "swipe-down":
this.moveSelection(1);
return { shell: true, window: false };
case "click":
case "swipe-right":
// Right: into the selected window (spatially, the window is to the
// sidebar's right). Left has nowhere further to go and is ignored.
if (this.windows.length) {
this.focus = "window";
// Repaint the window now so its selection highlight reflects focus
@@ -763,10 +842,44 @@ class Shell {
this.config.requestShellRender();
}
private isAssistantAvailable(): boolean {
isAssistantAvailable(): boolean {
return this.resolveAssistantConfiguration() !== null;
}
/** Observe assistant turns (see AssistantActivityEvent). */
onAssistantActivity(listener: (event: AssistantActivityEvent) => void): () => void {
this.assistantActivityListeners.add(listener);
return () => {
this.assistantActivityListeners.delete(listener);
};
}
/** Observe showAlert popups (mirrored to the watch). */
onAlertShown(listener: (text: string) => void): () => void {
this.alertListeners.add(listener);
return () => {
this.alertListeners.delete(listener);
};
}
private emitAssistantActivity(event: AssistantActivityEvent): void {
for (const listener of Array.from(this.assistantActivityListeners)) {
try {
listener(event);
} catch (error) {
console.warn("assistant activity listener failed", error);
}
}
}
/**
* Dismiss the assistant overlay (cancelling any in-flight turn), as Done
* would. Returns whether an overlay was actually open to close.
*/
closeAssistant(): boolean {
return this.closeAssistantLayer();
}
private ensureAssistantSession(): AssistantSession | null {
const config = this.resolveAssistantConfiguration();
if (!config) return null;
@@ -834,6 +947,7 @@ class Shell {
// stop the turn and drop the reference so a later query starts clean.
this.assistantSession?.cancel();
if (this.assistantLayer === created) this.assistantLayer = null;
this.emitAssistantActivity({ phase: "closed", text: "" });
},
});
layer = created;
@@ -846,11 +960,23 @@ class Shell {
private runAssistantTurn(session: AssistantSession, layer: AssistantLayer, text: string): void {
layer.startTurn();
let replySoFar = "";
this.emitAssistantActivity({ phase: "thinking", text: "" });
session.sendUtterance(text, this.buildAssistantContext(), {
onTextDelta: (delta, textSoFar) => layer.onTextDelta(delta, textSoFar),
onTextDelta: (delta, textSoFar) => {
replySoFar = textSoFar;
layer.onTextDelta(delta, textSoFar);
this.emitAssistantActivity({ phase: "streaming", text: textSoFar });
},
onToolActivity: (label) => layer.onToolActivity(label),
onTurnDone: () => layer.onTurnDone(),
onError: (message) => layer.onError(message),
onTurnDone: () => {
layer.onTurnDone();
this.emitAssistantActivity({ phase: "done", text: replySoFar });
},
onError: (message) => {
layer.onError(message);
this.emitAssistantActivity({ phase: "error", text: message });
},
});
}
@@ -889,18 +1015,28 @@ class Shell {
this.config.requestShellRender();
}
private closeAssistantLayer(): void {
private closeAssistantLayer(): boolean {
// Popping fires the layer's onRemoved, which cancels the turn and clears
// this.assistantLayer.
// this.assistantLayer. popThrough also closes anything stacked above the
// overlay (a follow-up voice dialog, an alert), so a close command works
// no matter what the conversation is showing.
const layer = this.assistantLayer;
if (layer) this.stack.popIfTop((top) => top === layer);
const closed = layer ? this.stack.popThrough(layer) : false;
this.noteUserActivity();
this.config.requestShellRender();
return closed;
}
/** Show a brief text popup on the lenses (assistant show_alert / notices). */
showAlert(text: string): void {
if (!this.screenOn) this.wake("sidebar");
for (const listener of Array.from(this.alertListeners)) {
try {
listener(text);
} catch (error) {
console.warn("alert listener failed", error);
}
}
const layer = new ShellAlertLayer(text, () => {
this.stack.popIfTop((top) => top === layer);
this.config.requestShellRender();
@@ -1024,17 +1160,29 @@ export function rawInputEventToInputEvent(event: RawInputEvent): DashboardInputE
source: eventSourceToString(event.eventSource),
};
} else if (event.eventType === OsEventTypeList.SCROLL_BOTTOM_EVENT) {
return { type: "scroll-down" };
return scrollEvent("scroll-down", event.eventSource);
} else if (event.eventType === OsEventTypeList.SCROLL_TOP_EVENT) {
return { type: "scroll-up" };
return scrollEvent("scroll-up", event.eventSource);
} else if (event.eventType === OsEventTypeList.RING_LONG_PRESS_EVENT) {
// CFW-forwarded long-press (replaces the firmware's force-quit dialog).
// The CFW gates this to the ring, so eventSource may be 0 (unknown);
// eventSourceToString falls back to "ring".
// Current CFW supplies the physical source for ring and temple presses;
// eventSourceToString's ring fallback keeps older CFW builds compatible.
return { type: "long-press", source: eventSourceToString(event.eventSource) };
} else if (event.eventType === OsEventTypeList.RING_LONG_PRESS_RELEASE_EVENT) {
return { type: "long-press-release", source: eventSourceToString(event.eventSource) };
}
} else if (event.kind === "watch-gesture") {
// Synthetic, from the Wear OS remote (app/g2/wear-remote.ts); the glasses
// firmware never produces these.
if (event.eventType === WatchGestureType.SWIPE_LEFT) {
return { type: "swipe-left", source: "watch" };
} else if (event.eventType === WatchGestureType.SWIPE_RIGHT) {
return { type: "swipe-right", source: "watch" };
} else if (event.eventType === WatchGestureType.SWIPE_UP) {
return { type: "swipe-up", source: "watch" };
} else if (event.eventType === WatchGestureType.SWIPE_DOWN) {
return { type: "swipe-down", source: "watch" };
}
} else if (event.kind === "even-ai") {
// sid 0x07 EvenAIDataPackage; eventType carries eEvenAIStatus. Only the
// wakeword interests us -- ENTER means the user manually opened the stock
@@ -1048,9 +1196,9 @@ export function rawInputEventToInputEvent(event: RawInputEvent): DashboardInputE
return { type: "display-wake" };
} else if (event.kind === "text-click") {
if (event.eventType === OsEventTypeList.SCROLL_BOTTOM_EVENT) {
return { type: "scroll-down" };
return scrollEvent("scroll-down", event.eventSource);
} else if (event.eventType === OsEventTypeList.SCROLL_TOP_EVENT) {
return { type: "scroll-up" };
return scrollEvent("scroll-up", event.eventSource);
}
}
return {
@@ -1061,13 +1209,20 @@ export function rawInputEventToInputEvent(event: RawInputEvent): DashboardInputE
};
}
function eventSourceToString(eventSource: number): "ring" | "left-arm" | "right-arm" {
/** Scroll events only carry a source when it is the watch (the stock ones never needed one). */
function scrollEvent(type: "scroll-up" | "scroll-down", eventSource: number): DashboardInputEvent {
return eventSource === EventSourceType.TOUCH_EVENT_FROM_WATCH ? { type, source: "watch" } : { type };
}
function eventSourceToString(eventSource: number): InputSource {
if (eventSource === EventSourceType.TOUCH_EVENT_FROM_RING) {
return "ring";
} else if (eventSource === EventSourceType.TOUCH_EVENT_FROM_GLASSES_L) {
return "left-arm";
} else if (eventSource === EventSourceType.TOUCH_EVENT_FROM_GLASSES_R) {
return "right-arm";
} else if (eventSource === EventSourceType.TOUCH_EVENT_FROM_WATCH) {
return "watch";
}
return "ring";
}
@@ -1086,6 +1241,14 @@ export function inputEventToString(event: DashboardInputEvent): string {
return `Long press from ${event.source}`;
case "long-press-release":
return `Long press release from ${event.source}`;
case "swipe-left":
return `Swipe left from ${event.source}`;
case "swipe-right":
return `Swipe right from ${event.source}`;
case "swipe-up":
return `Swipe up from ${event.source}`;
case "swipe-down":
return `Swipe down from ${event.source}`;
case "display-wake":
return `Display wake`;
case "wakeword":
+18 -9
View File
@@ -5,7 +5,7 @@ import { clamp } from "../../util/numeric-util";
import type { ToolDebugEntry } from "../../assistant/tool-registry";
import { DashboardInputEvent, Layer, LayerContext, PaintBelow } from "../layers";
import { MenuLayer, drawListScrollbar, type MenuItem } from "../menu";
import { MIN_WINDOW_HEIGHT, minWindowTop, SIDEBAR_WIDTH, TOP_BAR_HEIGHT } from "./geometry";
import { MIN_WINDOW_HEIGHT, minWindowTop, sidebarWidth, TOP_BAR_HEIGHT } from "./geometry";
import { lineStep } from "../metrics";
/**
@@ -15,13 +15,20 @@ import { lineStep } from "../metrics";
* page with its full name, gating state, and description.
*/
const DIALOG_X = SIDEBAR_WIDTH + 8;
const DIALOG_WIDTH = 420;
const DETAIL_WIDTH = G2_LENS_WIDTH - DIALOG_X - 8;
// Shell overlays align to the min-height window band; the detail box fills
// the band below the top bar with an 8px margin on each side.
const DETAIL_HEIGHT = MIN_WINDOW_HEIGHT - TOP_BAR_HEIGHT - 16;
/** Dialog left edge: past the sidebar strip where one reserves width. */
function dialogX(): number {
return sidebarWidth() + 8;
}
function detailWidth(): number {
return G2_LENS_WIDTH - dialogX() - 8;
}
/** Dialog top edge, aligned to the min-height band's content area. */
function dialogY(): number {
return minWindowTop() + TOP_BAR_HEIGHT + 8;
@@ -31,7 +38,7 @@ const DETAIL_PADDING = 14;
export class ToolDebugMenuLayer extends MenuLayer {
constructor(appId: string | null, entries: ToolDebugEntry[], private readonly onClosed: () => void) {
super(appId ? `Assistant tools: ${appId}` : "Assistant tools", buildItems(appId, entries), {
x: DIALOG_X,
x: dialogX(),
y: dialogY(),
width: DIALOG_WIDTH,
minHeight: 0,
@@ -78,12 +85,14 @@ class ToolDetailLayer implements Layer {
paint(_ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
const image = paintBelow();
const font = getDefaultSmallFont();
const left = dialogX();
const width = detailWidth();
const top = dialogY();
image.fillRoundedRect(DIALOG_X, top, DETAIL_WIDTH, DETAIL_HEIGHT, 1, 10);
image.drawRoundedRect(DIALOG_X, top, DETAIL_WIDTH, DETAIL_HEIGHT, 72, 10);
image.fillRoundedRect(left, top, width, DETAIL_HEIGHT, 1, 10);
image.drawRoundedRect(left, top, width, DETAIL_HEIGHT, 72, 10);
const textX = DIALOG_X + DETAIL_PADDING;
const textWidth = DETAIL_WIDTH - 2 * DETAIL_PADDING - 8;
const textX = left + DETAIL_PADDING;
const textWidth = width - 2 * DETAIL_PADDING - 8;
const lines = this.buildLines(textWidth);
const detailLineH = lineStep(font);
const visibleRowCount = Math.max(1, ((DETAIL_HEIGHT - 2 * DETAIL_PADDING) / detailLineH) | 0);
@@ -98,7 +107,7 @@ class ToolDetailLayer implements Layer {
if (lines.length > visibleRowCount) {
drawListScrollbar(
image,
DIALOG_X + DETAIL_WIDTH - 7,
left + width - 7,
top + DETAIL_PADDING,
DETAIL_HEIGHT - 2 * DETAIL_PADDING,
this.scrollRow,