forked from Blendman974/faceclaw
Use TTF fonts throughout the UI; also add some more functions to app extension API
This commit is contained in:
1 parent
5abbe2a405
commit
96842ceb23
82 files changed
+2666
-288
No files matched your search
@@ -11,7 +11,8 @@ import "@nativescript/core/globals";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { flattenPlanesWithDraws, planesFingerprint, singlePlane, type Plane } from "../../graphics/plane";
|
||||
import { prepareFrameDraws } from "../../graphics/glyph-wire";
|
||||
import { getDefaultSmallFont, getFont } from "../../graphics/bdffont";
|
||||
import { getFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import * as frameTimings from "../../native/frame-timings";
|
||||
import type { DashboardInputEvent } from "../../ui/layers";
|
||||
import { buildSoundSequencePayload, type Step } from "../../ui/sound-effects";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { getDefaultSmallFont, type BdfFont } from "../../graphics/bdffont";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { GrayImage, type UiFont } from "../../graphics/image";
|
||||
import { wrapText, truncateText } from "../../graphics/textwrap";
|
||||
import { clamp } from "../../util/numeric-util";
|
||||
import { readUpcomingEvents, type CalendarEvent } from "../../native/calendar";
|
||||
@@ -90,7 +90,7 @@ export class CalendarLayer implements Layer {
|
||||
}
|
||||
}
|
||||
|
||||
private paintPermissionPrompt(image: GrayImage, font: BdfFont, width: number, height: number): void {
|
||||
private paintPermissionPrompt(image: GrayImage, font: UiFont, width: number, height: number): void {
|
||||
const message = "Grant calendar permission on your phone to see your events on the glasses.";
|
||||
const lines = wrapText(font, message, width - 48);
|
||||
for (let index = 0; index < lines.length; index++) {
|
||||
@@ -127,7 +127,7 @@ function buildEventRows(events: CalendarEvent[]): EventRow[] {
|
||||
|
||||
function drawEventRow(
|
||||
image: GrayImage,
|
||||
font: BdfFont,
|
||||
font: UiFont,
|
||||
row: EventRow,
|
||||
x: number,
|
||||
y: number,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getDefaultLargeFont, getDefaultMediumFont, getDefaultSmallFont } from "../../graphics/bdffont";
|
||||
import { getDefaultLargeFont, getDefaultMediumFont, getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import {
|
||||
COMPASS_CALIBRATION_COMPLETE,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getDefaultMediumFont, getDefaultSmallFont } from "../../graphics/bdffont";
|
||||
import { getDefaultMediumFont, getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { clamp } from "../../util/numeric-util";
|
||||
import { addImuListener, imuSourceLabel, setImuReportEnabled, type ImuReading } from "../../native/imu";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getDefaultSmallFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { clamp } from "../../util/numeric-util";
|
||||
import { Layer, type DashboardInputEvent, type LayerActions, type LayerContext } from "../../ui/layers";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getDefaultSmallFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { clamp } from "../../util/numeric-util";
|
||||
import { GESTURE_DOUBLE_CLICK } from "../../ui/gestures";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getDefaultSmallFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { Layer, type DashboardInputEvent, type LayerContext } from "../../ui/layers";
|
||||
import { drawListScrollbar } from "../../ui/menu";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getDefaultSmallFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { truncateText } from "../../graphics/textwrap";
|
||||
import { Layer, type DashboardInputEvent, type LayerContext, type PaintBelow } from "../../ui/layers";
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Arbitrates the glasses' magnetometer compass (CFW mode-10 stream) among
|
||||
* running EvenHub apps, mirroring the IMU router. Only the foreground app
|
||||
* receives headings, so a backgrounded app can't keep the sensor running.
|
||||
*
|
||||
* The compass is NOT pre-calibrated — the magnetometer is in the right arm,
|
||||
* which rests on the head with a wearer-dependent curl (see compass-app memory);
|
||||
* headings are relative, not true north.
|
||||
*/
|
||||
import { addCompassListener, setCompassEnabled, COMPASS_CHANGED, type CompassEvent } from "../../native/compass";
|
||||
|
||||
export type EvenHubCompassClient = {
|
||||
readonly windowId: string;
|
||||
isForeground(): boolean;
|
||||
deliverCompass(headingDegrees: number): void;
|
||||
};
|
||||
|
||||
class EvenHubCompassRouter {
|
||||
private readonly requesting = new Set<EvenHubCompassClient>();
|
||||
private active: EvenHubCompassClient | null = null;
|
||||
private unsubscribe: (() => void) | null = null;
|
||||
private enabled = false;
|
||||
|
||||
requestCompass(client: EvenHubCompassClient): void {
|
||||
this.requesting.add(client);
|
||||
this.evaluate();
|
||||
}
|
||||
|
||||
releaseCompass(client: EvenHubCompassClient): void {
|
||||
if (!this.requesting.delete(client)) return;
|
||||
this.evaluate();
|
||||
}
|
||||
|
||||
notifyEligibilityChanged(): void {
|
||||
this.evaluate();
|
||||
}
|
||||
|
||||
private eligible(): EvenHubCompassClient | null {
|
||||
return Array.from(this.requesting).find((client) => client.isForeground()) ?? null;
|
||||
}
|
||||
|
||||
private evaluate(): void {
|
||||
const next = this.eligible();
|
||||
this.active = next;
|
||||
if (next) {
|
||||
if (!this.unsubscribe) {
|
||||
this.unsubscribe = addCompassListener((event: CompassEvent) => {
|
||||
// Only heading updates carry a real heading; calibration events use -1.
|
||||
if (event.command === COMPASS_CHANGED && event.headingDegrees >= 0) {
|
||||
this.active?.deliverCompass(event.headingDegrees);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!this.enabled) {
|
||||
setCompassEnabled(true);
|
||||
this.enabled = true;
|
||||
}
|
||||
} else {
|
||||
if (this.enabled) {
|
||||
setCompassEnabled(false);
|
||||
this.enabled = false;
|
||||
}
|
||||
this.unsubscribe?.();
|
||||
this.unsubscribe = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const evenHubCompassRouter = new EvenHubCompassRouter();
|
||||
@@ -19,6 +19,8 @@ export type EvenHubTextContainer = {
|
||||
paddingLength: number;
|
||||
isEventCapture: boolean;
|
||||
zOrderIndex: number | undefined;
|
||||
/** Extended-layout: inherit content from a same-named container on replace. */
|
||||
preserve: boolean;
|
||||
content: string;
|
||||
};
|
||||
|
||||
@@ -31,6 +33,7 @@ export type EvenHubImageContainer = {
|
||||
width: number;
|
||||
height: number;
|
||||
zOrderIndex: number | undefined;
|
||||
preserve: boolean;
|
||||
/** Decoded 8bpp grayscale, set by updateImageRawData; null until first update. */
|
||||
pixels: Uint8Array | null;
|
||||
pixelsWidth: number;
|
||||
@@ -50,6 +53,7 @@ export type EvenHubListContainer = {
|
||||
paddingLength: number;
|
||||
isEventCapture: boolean;
|
||||
zOrderIndex: number | undefined;
|
||||
preserve: boolean;
|
||||
itemNames: string[];
|
||||
itemWidth: number;
|
||||
selectBorder: boolean;
|
||||
@@ -117,6 +121,7 @@ function parseTextContainer(json: Record<string, unknown>): EvenHubTextContainer
|
||||
paddingLength: readNumber(json, "paddingLength", 0),
|
||||
isEventCapture: readNumber(json, "isEventCapture", 0) !== 0,
|
||||
zOrderIndex: readOptionalNumber(json, "zOrderIndex"),
|
||||
preserve: readNumber(json, "preserve", 0) !== 0,
|
||||
content: readString(json, "content", ""),
|
||||
};
|
||||
}
|
||||
@@ -131,6 +136,7 @@ function parseImageContainer(json: Record<string, unknown>): EvenHubImageContain
|
||||
width: readNumber(json, "width", 0),
|
||||
height: readNumber(json, "height", 0),
|
||||
zOrderIndex: readOptionalNumber(json, "zOrderIndex"),
|
||||
preserve: readNumber(json, "preserve", 0) !== 0,
|
||||
pixels: null,
|
||||
pixelsWidth: 0,
|
||||
pixelsHeight: 0,
|
||||
@@ -154,6 +160,7 @@ function parseListContainer(json: Record<string, unknown>): EvenHubListContainer
|
||||
paddingLength: readNumber(json, "paddingLength", 0),
|
||||
isEventCapture: readNumber(json, "isEventCapture", 0) !== 0,
|
||||
zOrderIndex: readOptionalNumber(json, "zOrderIndex"),
|
||||
preserve: readNumber(json, "preserve", 0) !== 0,
|
||||
itemNames,
|
||||
itemWidth: readNumber(itemContainer, "itemWidth", 0),
|
||||
selectBorder: readNumber(itemContainer, "isItemSelectBorderEn", 0) !== 0,
|
||||
|
||||
@@ -58,6 +58,7 @@ export function createEvenHubWindow(
|
||||
submitFrame: options.submitFrame,
|
||||
setSurfaceVisible: options.setSurfaceVisible,
|
||||
removeSurface: options.removeSurface,
|
||||
reconfigureSurface: options.reconfigureSurface,
|
||||
onClosed: () => {
|
||||
options.onClosed();
|
||||
session.windowClosed();
|
||||
@@ -69,6 +70,10 @@ export function createEvenHubWindow(
|
||||
closeWindow: () => shell.closeWindow(windowId),
|
||||
focusSwitcher: () => shell.yieldFocusToSidebar(),
|
||||
pushOverlay: (layer) => created.stack.push(layer),
|
||||
// The extended layout uses the full 576x452 app area ("max"); stock apps
|
||||
// stay in the 576x288 band ("medium").
|
||||
setTallCanvas: (tall) => created.setHeightMode(tall ? "max" : "medium"),
|
||||
windowId,
|
||||
});
|
||||
|
||||
// FOREGROUND_ENTER/EXIT for the app on shell focus changes.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getDefaultSmallFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { truncateText } from "../../graphics/textwrap";
|
||||
import { Layer, type DashboardInputEvent, type LayerContext, type PaintBelow } from "../../ui/layers";
|
||||
|
||||
+223
-4
@@ -44,6 +44,7 @@ import {
|
||||
readString,
|
||||
type EvenHubImageContainer,
|
||||
type EvenHubListContainer,
|
||||
type EvenHubContainer,
|
||||
type EvenHubPage,
|
||||
} from "./containers";
|
||||
import { compositePage } from "./compositor";
|
||||
@@ -51,7 +52,9 @@ import { type EvenHubManifest } from "./ehpk";
|
||||
import { permissionsIncludeMicrophone, permissionsInclude } from "./permissions";
|
||||
import { evenHubMicRouter, type EvenHubMicClient } from "./mic-router";
|
||||
import { evenHubImuRouter, type EvenHubImuClient } from "./imu-router";
|
||||
import { evenHubCompassRouter, type EvenHubCompassClient } from "./compass-router";
|
||||
import { type ImuReading } from "../../native/imu";
|
||||
import { toolRegistry, type ToolResult, type ToolSpec } from "../../assistant/tool-registry";
|
||||
import { getCurrentLocation } from "../../native/location";
|
||||
import { LocationTracker, type TrackedLocation } from "../../native/location-tracker";
|
||||
import { ensureFineLocationPermission } from "../../g2/android-permissions";
|
||||
@@ -225,6 +228,48 @@ export function buildFaceclawExtensionsScript(versionString: string): string {
|
||||
if (i >= 0) arr.splice(i, 1);
|
||||
};
|
||||
}
|
||||
// Compass: enable on first listener, disable when the last one leaves.
|
||||
var compassListeners = [];
|
||||
function addCompass(cb) {
|
||||
compassListeners.push(cb);
|
||||
if (compassListeners.length === 1) send("setCompass", [true]);
|
||||
var off = on("compass", cb);
|
||||
return function () {
|
||||
off();
|
||||
var i = compassListeners.indexOf(cb);
|
||||
if (i >= 0) compassListeners.splice(i, 1);
|
||||
if (compassListeners.length === 0) send("setCompass", [false]);
|
||||
};
|
||||
}
|
||||
// Voice-assistant tools: specs go to the host; handlers stay here and run when
|
||||
// the host invokes a tool via __fcExtInvokeTool.
|
||||
var toolHandlers = {};
|
||||
window.__fcExtInvokeTool = function (id, name, args) {
|
||||
var handler = toolHandlers[name];
|
||||
function reply(ok, value) {
|
||||
window.__faceclawEvenHub.postMessage("faceclawExtToolResult", JSON.stringify([id, ok, value]), 0);
|
||||
}
|
||||
if (!handler) { reply(false, "unknown tool " + name); return; }
|
||||
Promise.resolve().then(function () { return handler(args); }).then(
|
||||
function (res) { reply(true, res == null ? "" : res); },
|
||||
function (err) { reply(false, String((err && err.message) || err)); }
|
||||
);
|
||||
};
|
||||
function setAssistantTools(tools) {
|
||||
toolHandlers = {};
|
||||
var specs = [];
|
||||
(tools || []).forEach(function (t) {
|
||||
if (!t || !t.name || typeof t.handler !== "function") return;
|
||||
toolHandlers[t.name] = t.handler;
|
||||
specs.push({
|
||||
name: t.name,
|
||||
description: t.description || "",
|
||||
parameters: t.parameters || { type: "object", properties: {} },
|
||||
availability: t.availability === "open" ? "open" : "foreground"
|
||||
});
|
||||
});
|
||||
send("setAssistantTools", [specs]);
|
||||
}
|
||||
var extensions = {
|
||||
getVersion: function () { return VERSION; },
|
||||
returnToAppSwitcher: function () { send("returnToAppSwitcher"); },
|
||||
@@ -232,7 +277,11 @@ export function buildFaceclawExtensionsScript(versionString: string): string {
|
||||
addWindowLifecycleListener: function (cb) { return on("windowLifecycle", cb); },
|
||||
getConfiguredApiKeys: function () { return call("getConfiguredApiKeys"); },
|
||||
requestApiKeyAccess: function (services) { return call("requestApiKeyAccess", [services || []]); },
|
||||
playBuzzer: function (steps) { return call("playBuzzer", [steps || []]); }
|
||||
playBuzzer: function (steps) { return call("playBuzzer", [steps || []]); },
|
||||
addCompassListener: addCompass,
|
||||
createLayout: function (layout) { return call("createLayout", [layout || {}]); },
|
||||
replaceLayout: function (layout) { return call("replaceLayout", [layout || {}]); },
|
||||
setAssistantTools: setAssistantTools
|
||||
};
|
||||
window.getFaceclawExtensions = function () { return extensions; };
|
||||
})();
|
||||
@@ -256,9 +305,13 @@ export type EvenHubWindowHooks = {
|
||||
focusSwitcher: () => void;
|
||||
/** Push a modal overlay layer onto the app window (e.g. a consent prompt). */
|
||||
pushOverlay: (layer: Layer) => void;
|
||||
/** Switch the window between the stock 576x288 band and the full 576x452 canvas. */
|
||||
setTallCanvas: (tall: boolean) => void;
|
||||
/** The shell window id (unique per running instance; used for tool registration). */
|
||||
windowId: string;
|
||||
};
|
||||
|
||||
export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient {
|
||||
export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient, EvenHubCompassClient {
|
||||
readonly manifest: EvenHubManifest;
|
||||
readonly distDir: string;
|
||||
|
||||
@@ -269,6 +322,8 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient {
|
||||
private closed = false;
|
||||
private launchContextPushed = false;
|
||||
private systemExitSent = false;
|
||||
/** The one-shot launch FOREGROUND_ENTER has been delivered (page exists). */
|
||||
private launchEnterSent = false;
|
||||
/** Shell focus state; true from launch (apps open focused). */
|
||||
private foreground = true;
|
||||
/** Phone screen state; the mic goes silent while the screen is off. */
|
||||
@@ -277,8 +332,17 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient {
|
||||
private micRequested = false;
|
||||
/** The app has enabled the accelerometer via imuControl(true). */
|
||||
private imuRequested = false;
|
||||
/** The app has activated the compass (extension addCompassListener). */
|
||||
private compassRequested = false;
|
||||
/** Non-null while the app has an active location subscription. */
|
||||
private locationTracker: LocationTracker | null = null;
|
||||
/** The shell window id, for tool registration (falls back to packageId). */
|
||||
private shellWindowId = "";
|
||||
/** Whether this app has contributed assistant tools (for cleanup). */
|
||||
private hasAppTools = false;
|
||||
/** Pending host→app tool invocations, keyed by call id. */
|
||||
private readonly pendingToolCalls = new Map<number, (result: ToolResult) => void>();
|
||||
private nextToolCallId = 1;
|
||||
// Window-lifecycle tracking for the extension API (apps launch visible+focused).
|
||||
private lastVisible = true;
|
||||
private lastFocused = true;
|
||||
@@ -321,6 +385,7 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient {
|
||||
|
||||
attachWindow(hooks: EvenHubWindowHooks): void {
|
||||
this.windowHooks = hooks;
|
||||
this.shellWindowId = hooks.windowId;
|
||||
}
|
||||
|
||||
windowClosed(): void {
|
||||
@@ -402,6 +467,9 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient {
|
||||
// reads the accelerometer).
|
||||
if (this.micRequested) evenHubMicRouter.notifyEligibilityChanged();
|
||||
if (this.imuRequested) evenHubImuRouter.notifyEligibilityChanged();
|
||||
if (this.compassRequested) evenHubCompassRouter.notifyEligibilityChanged();
|
||||
// Foreground gates which app tools are live; re-list on change.
|
||||
if (this.hasAppTools) toolRegistry.fireToolsChanged();
|
||||
// Focus is unknown until the next paint (a re-shown window repaints and
|
||||
// re-asserts it; a hidden one won't, so treat it as unfocused meanwhile).
|
||||
this.shellFocused = false;
|
||||
@@ -450,7 +518,7 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient {
|
||||
// ----- microphone (EvenHubMicClient) -----
|
||||
|
||||
get windowId(): string {
|
||||
return this.manifest.packageId;
|
||||
return this.shellWindowId || this.manifest.packageId;
|
||||
}
|
||||
|
||||
isForeground(): boolean {
|
||||
@@ -593,6 +661,10 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient {
|
||||
this.handleExtensionCall(argsJson, callId);
|
||||
return;
|
||||
}
|
||||
if (handlerName === "faceclawExtToolResult") {
|
||||
this.handleToolResult(argsJson);
|
||||
return;
|
||||
}
|
||||
void (async () => {
|
||||
let result: unknown = null;
|
||||
try {
|
||||
@@ -676,7 +748,10 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient {
|
||||
this.page = page;
|
||||
this.pageCreated = true;
|
||||
// The launch focus arrived before the page existed; deliver the ENTER now.
|
||||
if (this.foreground) this.emitSysEvent(FOREGROUND_ENTER_EVENT, 0);
|
||||
if (this.foreground && !this.launchEnterSent) {
|
||||
this.launchEnterSent = true;
|
||||
this.emitSysEvent(FOREGROUND_ENTER_EVENT, 0);
|
||||
}
|
||||
this.windowHooks?.requestRender();
|
||||
return 0;
|
||||
}
|
||||
@@ -842,12 +917,126 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient {
|
||||
case "playBuzzer":
|
||||
await this.playBuzzer(Array.isArray(params[0]) ? params[0] : []);
|
||||
return null;
|
||||
case "setCompass":
|
||||
this.setCompass(params[0] === true);
|
||||
return null;
|
||||
case "createLayout":
|
||||
case "replaceLayout":
|
||||
return this.applyExtensionLayout(asRecord(params[0]));
|
||||
case "setAssistantTools":
|
||||
this.setAssistantTools(Array.isArray(params[0]) ? params[0] : []);
|
||||
return null;
|
||||
default:
|
||||
this.log(`evenhub: unknown extension method ${method}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// ----- compass (EvenHubCompassClient) -----
|
||||
|
||||
deliverCompass(headingDegrees: number): void {
|
||||
this.pushExtEvent("compass", { headingDegrees });
|
||||
}
|
||||
|
||||
private setCompass(enable: boolean): void {
|
||||
if (enable) {
|
||||
if (!this.compassRequested) {
|
||||
this.compassRequested = true;
|
||||
evenHubCompassRouter.requestCompass(this);
|
||||
}
|
||||
} else if (this.compassRequested) {
|
||||
this.compassRequested = false;
|
||||
evenHubCompassRouter.releaseCompass(this);
|
||||
}
|
||||
}
|
||||
|
||||
// ----- extended layout -----
|
||||
|
||||
/**
|
||||
* Build/replace the page from an extended layout: full 576x452 canvas, no
|
||||
* container-count limit, and per-container `preserve` (inherit content from a
|
||||
* same-named container in the outgoing layout). Returns true on success.
|
||||
*/
|
||||
private applyExtensionLayout(data: Record<string, unknown>): boolean {
|
||||
const previous = this.page;
|
||||
const page = parsePage(data);
|
||||
for (const container of page.containers) {
|
||||
if (container.preserve) preserveContent(container, previous);
|
||||
}
|
||||
this.page = page;
|
||||
this.pageCreated = true;
|
||||
// The extended layout uses the taller app area.
|
||||
this.windowHooks?.setTallCanvas(true);
|
||||
if (this.foreground && !this.launchEnterSent) {
|
||||
this.launchEnterSent = true;
|
||||
this.emitSysEvent(FOREGROUND_ENTER_EVENT, 0);
|
||||
}
|
||||
this.windowHooks?.requestRender();
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----- assistant tools -----
|
||||
|
||||
private setAssistantTools(rawSpecs: unknown[]): void {
|
||||
const specs: ToolSpec[] = [];
|
||||
for (const raw of rawSpecs) {
|
||||
const record = asRecord(raw);
|
||||
const name = readString(record, "name", "");
|
||||
if (!name) continue;
|
||||
const availability = record.availability === "open" ? "open" : "foreground";
|
||||
specs.push({
|
||||
name,
|
||||
description: readString(record, "description", ""),
|
||||
inputSchema: asRecord(record.parameters),
|
||||
availability,
|
||||
});
|
||||
}
|
||||
if (specs.length === 0 && !this.hasAppTools) return;
|
||||
toolRegistry.setAppTools({
|
||||
windowId: this.windowId,
|
||||
// Prefix tools with the app's package name, per the extension contract.
|
||||
appId: this.manifest.packageId,
|
||||
specs,
|
||||
invoke: (toolName, args) => this.invokeAppTool(toolName, args),
|
||||
isForeground: () => this.foreground,
|
||||
});
|
||||
this.hasAppTools = specs.length > 0;
|
||||
}
|
||||
|
||||
/** Invoke one of the app's tools by dispatching into the webview and awaiting its reply. */
|
||||
private invokeAppTool(toolName: string, args: unknown): Promise<ToolResult> {
|
||||
return new Promise((resolve) => {
|
||||
if (!this.webViewHandle || this.closed) {
|
||||
resolve({ ok: false, error: "app not available" });
|
||||
return;
|
||||
}
|
||||
const id = this.nextToolCallId++;
|
||||
this.pendingToolCalls.set(id, resolve);
|
||||
this.webViewHandle.evaluateJs(
|
||||
`window.__fcExtInvokeTool && window.__fcExtInvokeTool(${id}, ${JSON.stringify(toolName)}, ${JSON.stringify(args ?? {})})`,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
private handleToolResult(argsJson: string): void {
|
||||
try {
|
||||
const args = JSON.parse(argsJson) as unknown[];
|
||||
const id = Number(args[0]);
|
||||
const ok = args[1] === true;
|
||||
const value = args[2];
|
||||
const resolve = this.pendingToolCalls.get(id);
|
||||
if (!resolve) return;
|
||||
this.pendingToolCalls.delete(id);
|
||||
if (ok) {
|
||||
resolve({ ok: true, content: typeof value === "string" ? value : JSON.stringify(value ?? null) });
|
||||
} else {
|
||||
resolve({ ok: false, error: typeof value === "string" ? value : "tool failed" });
|
||||
}
|
||||
} catch (error) {
|
||||
this.log(`evenhub: bad tool result: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompt the user (on the glasses) to share configured API keys with the app,
|
||||
* resolving with the granted values. Services already granted this session
|
||||
@@ -916,6 +1105,16 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient {
|
||||
this.imuRequested = false;
|
||||
evenHubImuRouter.releaseImu(this);
|
||||
}
|
||||
if (this.compassRequested) {
|
||||
this.compassRequested = false;
|
||||
evenHubCompassRouter.releaseCompass(this);
|
||||
}
|
||||
if (this.hasAppTools) {
|
||||
this.hasAppTools = false;
|
||||
toolRegistry.removeAppTools(this.windowId);
|
||||
}
|
||||
for (const resolve of this.pendingToolCalls.values()) resolve({ ok: false, error: "app closed" });
|
||||
this.pendingToolCalls.clear();
|
||||
this.locationTracker?.stop();
|
||||
this.locationTracker = null;
|
||||
if (!this.systemExitSent) {
|
||||
@@ -996,6 +1195,26 @@ function activeCommunicator(): any {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy content into a `preserve` container from the same-named, same-kind
|
||||
* container in the previous page (if any), so a replaceLayout keeps its pixels /
|
||||
* text / list state instead of blanking.
|
||||
*/
|
||||
function preserveContent(target: EvenHubContainer, previous: EvenHubPage | null): void {
|
||||
const source = previous?.containers.find((c) => c.kind === target.kind && c.name === target.name);
|
||||
if (!source) return;
|
||||
if (target.kind === "text" && source.kind === "text") {
|
||||
target.content = source.content;
|
||||
} else if (target.kind === "image" && source.kind === "image") {
|
||||
target.pixels = source.pixels;
|
||||
target.pixelsWidth = source.pixelsWidth;
|
||||
target.pixelsHeight = source.pixelsHeight;
|
||||
} else if (target.kind === "list" && source.kind === "list") {
|
||||
target.itemNames = source.itemNames;
|
||||
target.selectedIndex = Math.min(source.selectedIndex, Math.max(0, target.itemNames.length - 1));
|
||||
}
|
||||
}
|
||||
|
||||
/** The API-key services the extension API can surface, and their settings. */
|
||||
const API_KEY_SERVICES = [
|
||||
{ id: "openai", setting: openAiApiKeySetting },
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getDefaultSmallFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { truncateText, wrapText } from "../../graphics/textwrap";
|
||||
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL } from "../../ui/gestures";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getDefaultSmallFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { truncateText, wrapText } from "../../graphics/textwrap";
|
||||
import { clamp } from "../../util/numeric-util";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { getDefaultSmallFont, type BdfFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { truncateText, truncateLeft } from "../../graphics/textwrap";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { GrayImage, type UiFont } from "../../graphics/image";
|
||||
import { renderIcon, type IconName } from "../../graphics/icons";
|
||||
import { clamp } from "../../util/numeric-util";
|
||||
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL } from "../../ui/gestures";
|
||||
@@ -149,7 +149,7 @@ export class FileBrowserLayer implements Layer {
|
||||
return image;
|
||||
}
|
||||
|
||||
private paintList(image: GrayImage, font: BdfFont, rows: BrowserItem[], ctx: LayerContext): void {
|
||||
private paintList(image: GrayImage, font: UiFont, rows: BrowserItem[], ctx: LayerContext): void {
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
this.listIndex = clamp(this.listIndex, 0, Math.max(0, rows.length - 1));
|
||||
|
||||
@@ -172,7 +172,7 @@ export class FileBrowserLayer implements Layer {
|
||||
image.drawText(font, 20, height - 16, `${GESTURE_CLICK} open ${GESTURE_DOUBLE_CLICK} up / back`, 110);
|
||||
}
|
||||
|
||||
private paintIcons(image: GrayImage, font: BdfFont, rows: BrowserItem[], ctx: LayerContext): void {
|
||||
private paintIcons(image: GrayImage, font: UiFont, rows: BrowserItem[], ctx: LayerContext): void {
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const focused = ctx.stack.isFocused();
|
||||
const iconRows = buildIconRows(rows);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getDefaultSmallFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { wrapText } from "../../graphics/textwrap";
|
||||
import type { DirectoryEntry } from "../../native/file-access";
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { readTextFile, type DirectoryEntry } from "../../native/file-access";
|
||||
import { isFontFile } from "../../native/font-files";
|
||||
import { installFontFile, isFontInstalled } from "../../graphics/installed-fonts";
|
||||
import { isDecodableImageFile } from "../../native/image-files";
|
||||
import { readEvenHubPackageManifest } from "../evenhub/installed-apps";
|
||||
import { EvenHubPermissionDialogLayer } from "../evenhub/permission-dialog";
|
||||
@@ -227,6 +228,16 @@ function fileOpenActions(entry: DirectoryEntry, options: FilesAppOptions): FileI
|
||||
];
|
||||
}
|
||||
if (isFontFile(entry.name)) {
|
||||
// Install copies into the app-internal fonts directory, making the face
|
||||
// available in the Settings font pickers. The row relabels itself with
|
||||
// the result (the dialog re-reads labels each paint).
|
||||
const install: FileInfoAction = {
|
||||
label: isFontInstalled(entry.path) ? "Reinstall" : "Install",
|
||||
onSelect: () => {
|
||||
const error = installFontFile(entry.path);
|
||||
install.label = error ?? "Installed";
|
||||
},
|
||||
};
|
||||
return [
|
||||
{
|
||||
label: "Preview here",
|
||||
@@ -242,6 +253,7 @@ function fileOpenActions(entry: DirectoryEntry, options: FilesAppOptions): FileI
|
||||
options.openFontWindow(entry.name, entry.path);
|
||||
},
|
||||
},
|
||||
install,
|
||||
];
|
||||
}
|
||||
return [];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getDefaultSmallFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { truncateText } from "../../graphics/textwrap";
|
||||
import {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { getDefaultSmallFont, type BdfFont } from "../../graphics/bdffont";
|
||||
import { type BdfFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { truncateText } from "../../graphics/textwrap";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { loadImageFileAsGray } from "../../native/image-files";
|
||||
|
||||
@@ -1,15 +1,33 @@
|
||||
import { wrapText, truncateText } from "../../graphics/textwrap";
|
||||
import { getDefaultSmallFont, type BdfFont } from "../../graphics/bdffont";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { getDefaultSmallFont, getUiFontSelection } from "../../graphics/ui-fonts";
|
||||
import { TtfFont } from "../../graphics/ttf-font";
|
||||
import { GrayImage, type UiFont } from "../../graphics/image";
|
||||
import { Layer, type DashboardInputEvent, type LayerContext } from "../../ui/layers";
|
||||
|
||||
const MARGIN_X = 18;
|
||||
const TITLE_Y = 16;
|
||||
const BODY_X = 18;
|
||||
const BODY_Y = 44;
|
||||
const LINE_STEP = 14;
|
||||
const FOOTER_MARGIN = 36;
|
||||
|
||||
/**
|
||||
* Body text: the user's UI font when it's a TTF; otherwise bundled Inter
|
||||
* Light (the document viewer stays antialiased even while the UI default is
|
||||
* still a bitmap face), with the bitmap UI font as the last fallback.
|
||||
*/
|
||||
const FALLBACK_BODY_FONT_SIZE_PX = 16;
|
||||
/** Line step for the BDF fallback (the 12px font plus leading, as before). */
|
||||
const BDF_LINE_STEP = 14;
|
||||
|
||||
function getViewerFont(): UiFont {
|
||||
if (getUiFontSelection().kind === "ttf") return getDefaultSmallFont();
|
||||
return TtfFont.bundled("inter-light", FALLBACK_BODY_FONT_SIZE_PX) ?? getDefaultSmallFont();
|
||||
}
|
||||
|
||||
function lineStepOf(font: UiFont): number {
|
||||
return font instanceof TtfFont ? font.lineHeight : BDF_LINE_STEP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Paged text viewer for a document. Sized to its hosting stack (a Files
|
||||
* document window, or pushed over the file browser for view-in-place).
|
||||
@@ -17,6 +35,7 @@ const FOOTER_MARGIN = 36;
|
||||
export class TextViewerLayer implements Layer {
|
||||
private lines: string[] | null = null;
|
||||
private wrappedForWidth = 0;
|
||||
private wrappedWithFont = 0;
|
||||
private firstLine = 0;
|
||||
private bodyLineCount = 14;
|
||||
|
||||
@@ -26,17 +45,18 @@ export class TextViewerLayer implements Layer {
|
||||
) {}
|
||||
|
||||
paint(ctx: LayerContext): GrayImage {
|
||||
const font = getDefaultSmallFont();
|
||||
const font = getViewerFont();
|
||||
const lineStep = lineStepOf(font);
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const image = new GrayImage(width, height, 0);
|
||||
const footerY = height - FOOTER_MARGIN;
|
||||
this.bodyLineCount = Math.max(1, Math.floor((footerY - BODY_Y) / LINE_STEP));
|
||||
this.bodyLineCount = Math.max(1, Math.floor((footerY - BODY_Y) / lineStep));
|
||||
image.drawText(font, MARGIN_X + 4, TITLE_Y, truncateText(font, this.title, width - 2 * MARGIN_X - 8), 220);
|
||||
|
||||
const lines = this.getLines(font, width);
|
||||
const visibleLines = lines.slice(this.firstLine, this.firstLine + this.bodyLineCount);
|
||||
for (let index = 0; index < visibleLines.length; index++) {
|
||||
image.drawText(font, BODY_X, BODY_Y + index * LINE_STEP, visibleLines[index]!, 230);
|
||||
image.drawText(font, BODY_X, BODY_Y + index * lineStep, visibleLines[index]!, 230);
|
||||
}
|
||||
|
||||
const currentPage = Math.floor(this.firstLine / this.pageStep()) + 1;
|
||||
@@ -74,14 +94,15 @@ export class TextViewerLayer implements Layer {
|
||||
this.firstLine = Math.max(0, Math.min(maxFirstLine, this.firstLine + delta));
|
||||
}
|
||||
|
||||
private getLines(font: BdfFont, width: number): string[] {
|
||||
if (this.lines === null || this.wrappedForWidth !== width) {
|
||||
private getLines(font: UiFont, width: number): string[] {
|
||||
if (this.lines === null || this.wrappedForWidth !== width || this.wrappedWithFont !== font.fingerprintId) {
|
||||
const normalized = this.documentText.replace(/\t/g, " ").replace(/\r/g, "");
|
||||
this.lines = wrapText(font, normalized, width - BODY_X - 12, {
|
||||
preserveLeadingWhitespace: true,
|
||||
breakLongWords: true,
|
||||
});
|
||||
this.wrappedForWidth = width;
|
||||
this.wrappedWithFont = font.fingerprintId;
|
||||
}
|
||||
return this.lines;
|
||||
}
|
||||
@@ -93,4 +114,3 @@ export class TextViewerLayer implements Layer {
|
||||
return Math.ceil((lineCount - this.bodyLineCount) / this.pageStep()) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@ import "@nativescript/core/globals";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { flattenPlanesWithDraws, planesFingerprint, singlePlane, type Plane } from "../../graphics/plane";
|
||||
import { prepareFrameDraws } from "../../graphics/glyph-wire";
|
||||
import { getDefaultSmallFont, getFont } from "../../graphics/bdffont";
|
||||
import { getFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import * as frameTimings from "../../native/frame-timings";
|
||||
import type { DashboardInputEvent } from "../../ui/layers";
|
||||
import { buildSoundSequencePayload, type Step } from "../../ui/sound-effects";
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { getDefaultSmallFont, type BdfFont } from "../../graphics/bdffont";
|
||||
import { type BdfFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { truncateText } from "../../graphics/textwrap";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { type Plane } from "../../graphics/plane";
|
||||
|
||||
@@ -15,7 +15,8 @@ import "@nativescript/core/globals";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { flattenPlanesWithDraws, planesFingerprint, singlePlane, type Plane } from "../../graphics/plane";
|
||||
import { prepareFrameDraws } from "../../graphics/glyph-wire";
|
||||
import { getDefaultSmallFont, getFont } from "../../graphics/bdffont";
|
||||
import { getFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import * as frameTimings from "../../native/frame-timings";
|
||||
import type { DashboardInputEvent } from "../../ui/layers";
|
||||
import { buildSoundSequencePayload, type Step } from "../../ui/sound-effects";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { getDefaultSmallFont, type BdfFont } from "../../graphics/bdffont";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { GrayImage, type UiFont } from "../../graphics/image";
|
||||
import { clamp } from "../../util/numeric-util";
|
||||
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL } from "../../ui/gestures";
|
||||
import {
|
||||
@@ -285,7 +285,7 @@ export class MediaBrowseLayer implements Layer {
|
||||
}
|
||||
}
|
||||
|
||||
function truncateRight(font: BdfFont, text: string, maxWidth: number): string {
|
||||
function truncateRight(font: UiFont, text: string, maxWidth: number): string {
|
||||
if (font.measureText(text) <= maxWidth) return text;
|
||||
let out = text;
|
||||
while (out.length > 1 && font.measureText(`${out}...`) > maxWidth) {
|
||||
@@ -294,7 +294,7 @@ function truncateRight(font: BdfFont, text: string, maxWidth: number): string {
|
||||
return `${out}...`;
|
||||
}
|
||||
|
||||
function truncateLeft(font: BdfFont, text: string, maxWidth: number): string {
|
||||
function truncateLeft(font: UiFont, text: string, maxWidth: number): string {
|
||||
if (font.measureText(text) <= maxWidth) return text;
|
||||
let out = text;
|
||||
while (out.length > 1 && font.measureText(`...${out}`) > maxWidth) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getDefaultMediumFont, getDefaultSmallFont } from "../../graphics/bdffont";
|
||||
import { getDefaultMediumFont, getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { wrapText, truncateText } from "../../graphics/textwrap";
|
||||
import { clamp } from "../../util/numeric-util";
|
||||
|
||||
@@ -10,7 +10,8 @@ import "@nativescript/core/globals";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { flattenPlanesWithDraws, planesFingerprint, singlePlane, type Plane } from "../../graphics/plane";
|
||||
import { prepareFrameDraws } from "../../graphics/glyph-wire";
|
||||
import { getDefaultSmallFont, getFont } from "../../graphics/bdffont";
|
||||
import { getFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import * as frameTimings from "../../native/frame-timings";
|
||||
import type { DashboardInputEvent } from "../../ui/layers";
|
||||
import { defaultWindowMenuItems, WindowMenu } from "../../ui/window-menu";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getDefaultSmallFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { nightscoutBridge, type NightscoutState } from "../../native/nightscout-bridge";
|
||||
import { NightscoutLayer } from "./nightscout";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { BdfFont, getDefaultLargeFont, getDefaultSmallFont } from "../../graphics/bdffont";
|
||||
import { GrayImage, imageFromAsciiArt } from "../../graphics/image";
|
||||
import { getDefaultLargeFont, getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { GrayImage, imageFromAsciiArt, type UiFont } from "../../graphics/image";
|
||||
import { DashboardInputEvent, Layer, LayerContext } from "../../ui/layers";
|
||||
import { nightscoutBridge, type NightscoutState } from "../../native/nightscout-bridge";
|
||||
import {
|
||||
@@ -20,7 +20,7 @@ const NIGHTSCOUT_GRAPH_TIME_QUANTUM_MS = 60 * 1000;
|
||||
|
||||
function drawDirectionIndicator(
|
||||
image: GrayImage,
|
||||
font: BdfFont,
|
||||
font: UiFont,
|
||||
x: number,
|
||||
y: number,
|
||||
direction: string,
|
||||
@@ -43,7 +43,7 @@ function drawDirectionIndicator(
|
||||
}
|
||||
}
|
||||
|
||||
function directionGlyphLabel(font: BdfFont, direction: string): string {
|
||||
function directionGlyphLabel(font: UiFont, direction: string): string {
|
||||
switch (direction) {
|
||||
case "DoubleUp":
|
||||
return font.hasGlyph("↑".codePointAt(0)!) ? "↑↑" : "";
|
||||
@@ -98,7 +98,7 @@ function drawNightscoutGraph(
|
||||
bounds: { x: number; y: number; width: number; height: number },
|
||||
nightscout: NightscoutState,
|
||||
nowMs: number,
|
||||
font: BdfFont,
|
||||
font: UiFont,
|
||||
): void {
|
||||
if (bounds.width <= 2 || bounds.height <= 2) {
|
||||
return;
|
||||
@@ -195,7 +195,7 @@ function drawNightscoutBasalOverlay(
|
||||
function drawNightscoutCarbMarkers(
|
||||
image: GrayImage,
|
||||
bounds: { x: number; y: number; width: number; height: number },
|
||||
font: BdfFont,
|
||||
font: UiFont,
|
||||
carbEvents: NightscoutState["carbs"],
|
||||
nowMs: number,
|
||||
): void {
|
||||
@@ -216,7 +216,7 @@ function drawNightscoutCarbMarkers(
|
||||
function drawNightscoutBolusMarkers(
|
||||
image: GrayImage,
|
||||
bounds: { x: number; y: number; width: number; height: number },
|
||||
font: BdfFont,
|
||||
font: UiFont,
|
||||
bolusEvents: NightscoutState["boluses"],
|
||||
nowMs: number,
|
||||
): void {
|
||||
@@ -246,7 +246,7 @@ function drawNightscoutBolusMarkers(
|
||||
|
||||
function drawTextCentered(
|
||||
image: GrayImage,
|
||||
font: BdfFont,
|
||||
font: UiFont,
|
||||
centerX: number,
|
||||
y: number,
|
||||
text: string,
|
||||
|
||||
@@ -21,7 +21,8 @@ import "@nativescript/core/globals";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { flattenPlanesWithDraws, planesFingerprint, singlePlane, type Plane } from "../../graphics/plane";
|
||||
import { prepareFrameDraws } from "../../graphics/glyph-wire";
|
||||
import { getDefaultSmallFont, getFont } from "../../graphics/bdffont";
|
||||
import { getFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import * as frameTimings from "../../native/frame-timings";
|
||||
import { getStringSetting, setStringSetting } from "../../native/settings-store";
|
||||
import type { DashboardInputEvent } from "../../ui/layers";
|
||||
|
||||
@@ -9,7 +9,7 @@ import "@nativescript/core/globals";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { flattenPlanesWithDraws, planesFingerprint, singlePlane, type Plane } from "../../graphics/plane";
|
||||
import { prepareFrameDraws } from "../../graphics/glyph-wire";
|
||||
import { getDefaultSmallFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { truncateText, wrapText } from "../../graphics/textwrap";
|
||||
import * as frameTimings from "../../native/frame-timings";
|
||||
import type { DashboardInputEvent } from "../../ui/layers";
|
||||
|
||||
@@ -31,10 +31,10 @@
|
||||
* re-attach snapshot resyncs contents and scrollback only once it's needed.
|
||||
*/
|
||||
import "@nativescript/core/globals";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { GrayImage, type UiFont } from "../../graphics/image";
|
||||
import { flattenPlanesWithDraws, planesFingerprint, singlePlane, type Plane } from "../../graphics/plane";
|
||||
import { prepareFrameDraws } from "../../graphics/glyph-wire";
|
||||
import { getFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont, getTerminalFontConfig } from "../../graphics/ui-fonts";
|
||||
import { TERMINAL_ICON_GLYPHS } from "../../graphics/icons";
|
||||
import * as frameTimings from "../../native/frame-timings";
|
||||
import { GESTURE_DOUBLE_CLICK } from "../../ui/gestures";
|
||||
@@ -77,19 +77,25 @@ import type { ToolResult, ToolSpec } from "../../assistant/tool-registry";
|
||||
declare const global: any;
|
||||
declare const com: any;
|
||||
|
||||
// Terminus-12 has a 6x12 cell; each window derives its grid from the
|
||||
// viewport in its open-window message (the hub is min-height, session views
|
||||
// full-height). The websocket init handshake declares the view grid.
|
||||
const terminalFont = getFont("terminus12");
|
||||
const CELL_WIDTH = 6;
|
||||
const CELL_HEIGHT = 12;
|
||||
// Cell geometry comes from the terminal font setting (Settings > Terminal >
|
||||
// Font; the default is Terminus-12's 6x12). Each window derives its grid from
|
||||
// the viewport in its open-window message (the hub is min-height, session
|
||||
// views full-height). Grid dimensions are baked into each session's websocket
|
||||
// handshake, so windows and control connections capture the cell size at
|
||||
// creation — a font change applies to ones (re)opened afterwards.
|
||||
function chromeFont(): UiFont {
|
||||
return getDefaultSmallFont();
|
||||
}
|
||||
// Grid of a session view window (full-height); also declared on the control
|
||||
// connections so sessions launched from presets come up at view size.
|
||||
const VIEW_VIEWPORT = appViewportSize("max");
|
||||
const VIEW_GRID = {
|
||||
cols: Math.floor(VIEW_VIEWPORT.width / CELL_WIDTH),
|
||||
rows: Math.floor(VIEW_VIEWPORT.height / CELL_HEIGHT),
|
||||
};
|
||||
function viewGrid(): { cols: number; rows: number } {
|
||||
const { cellWidth, cellHeight } = getTerminalFontConfig();
|
||||
return {
|
||||
cols: Math.floor(VIEW_VIEWPORT.width / cellWidth),
|
||||
rows: Math.floor(VIEW_VIEWPORT.height / cellHeight),
|
||||
};
|
||||
}
|
||||
const DEVICE_NAME = "Faceclaw G2";
|
||||
const HUB_ROW_HEIGHT = 20;
|
||||
const RENDER_COALESCE_MS = 33;
|
||||
@@ -148,6 +154,10 @@ type HubWindow = BaseWindow & {
|
||||
|
||||
type ViewWindow = BaseWindow & {
|
||||
kind: "view";
|
||||
/** Grid font and integer cell pitch, captured at window creation. */
|
||||
font: UiFont;
|
||||
cellWidth: number;
|
||||
cellHeight: number;
|
||||
connectionId: string;
|
||||
socket: string;
|
||||
label: string;
|
||||
@@ -427,14 +437,15 @@ function openWindow(windowId: string, surfaceId: string, viewport: { width: numb
|
||||
renderHubWindows();
|
||||
return;
|
||||
}
|
||||
const hubCell = getTerminalFontConfig();
|
||||
windows.set(windowId, {
|
||||
kind: "hub",
|
||||
windowId,
|
||||
surfaceId,
|
||||
viewportWidth: viewport.width,
|
||||
viewportHeight: viewport.height,
|
||||
gridCols: Math.floor(viewport.width / CELL_WIDTH),
|
||||
gridRows: Math.floor(viewport.height / CELL_HEIGHT),
|
||||
gridCols: Math.floor(viewport.width / hubCell.cellWidth),
|
||||
gridRows: Math.floor(viewport.height / hubCell.cellHeight),
|
||||
foreground: false,
|
||||
focused: false,
|
||||
renderScheduled: false,
|
||||
@@ -490,8 +501,7 @@ function clientOptionsFor(connection: TerminalConnection): G2MirrorClientOptions
|
||||
return {
|
||||
...parsed,
|
||||
deviceName: DEVICE_NAME,
|
||||
cols: VIEW_GRID.cols,
|
||||
rows: VIEW_GRID.rows,
|
||||
...viewGrid(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -686,8 +696,12 @@ function createViewWindow(
|
||||
view: PendingView,
|
||||
): ViewWindow {
|
||||
const { connectionId, socket, label, glyph } = view;
|
||||
const gridCols = Math.floor(viewport.width / CELL_WIDTH);
|
||||
const gridRows = Math.floor(viewport.height / CELL_HEIGHT);
|
||||
// Capture the terminal font at open time: the grid dims go into the
|
||||
// websocket handshake and the emulator, so they must not change under a
|
||||
// live window (a font-setting change applies to the next window).
|
||||
const cell = getTerminalFontConfig();
|
||||
const gridCols = Math.floor(viewport.width / cell.cellWidth);
|
||||
const gridRows = Math.floor(viewport.height / cell.cellHeight);
|
||||
const client = new G2MirrorClient({ ...view.options, cols: gridCols, rows: gridRows });
|
||||
const window: ViewWindow = {
|
||||
kind: "view",
|
||||
@@ -697,6 +711,9 @@ function createViewWindow(
|
||||
viewportHeight: viewport.height,
|
||||
gridCols,
|
||||
gridRows,
|
||||
font: cell.font,
|
||||
cellWidth: cell.cellWidth,
|
||||
cellHeight: cell.cellHeight,
|
||||
foreground: false,
|
||||
focused: false,
|
||||
renderScheduled: false,
|
||||
@@ -1386,13 +1403,13 @@ function paintHub(window: HubWindow): GrayImage {
|
||||
}
|
||||
const image = new GrayImage(window.viewportWidth, window.viewportHeight, 0);
|
||||
// No border box: the shell chrome (top bar + sidebar) already frames the app.
|
||||
image.drawText(terminalFont, 18, 10, window.mode === "connections" ? "Terminal - Connections" : "Terminal", 220);
|
||||
image.drawText(terminalFont, 24, 30, hubStatusLine(window), 170);
|
||||
image.drawText(chromeFont(), 18, 10, window.mode === "connections" ? "Terminal - Connections" : "Terminal", 220);
|
||||
image.drawText(chromeFont(), 24, 30, hubStatusLine(window), 170);
|
||||
|
||||
let listTop = 52;
|
||||
if (window.mode === "sessions" && controls.size === 0) {
|
||||
image.drawText(terminalFont, 24, 46, "Add a g2mirror:// connection to get started, see:", 150);
|
||||
image.drawText(terminalFont, 24, 60, "https://github.com/jimrandomh/g2mirror", 190);
|
||||
image.drawText(chromeFont(), 24, 46, "Add a g2mirror:// connection to get started, see:", 150);
|
||||
image.drawText(chromeFont(), 24, 60, "https://github.com/jimrandomh/g2mirror", 190);
|
||||
listTop += 28;
|
||||
}
|
||||
|
||||
@@ -1405,7 +1422,7 @@ function paintHub(window: HubWindow): GrayImage {
|
||||
const y = listTop + (index - window.scrollRow) * HUB_ROW_HEIGHT;
|
||||
const item = items[index]!;
|
||||
if (item.heading) {
|
||||
image.drawText(terminalFont, 20, y + 2, item.label, 140);
|
||||
image.drawText(chromeFont(), 20, y + 2, item.label, 140);
|
||||
continue;
|
||||
}
|
||||
const selected = index === window.selectedIndex;
|
||||
@@ -1414,7 +1431,7 @@ function paintHub(window: HubWindow): GrayImage {
|
||||
// an outline-only selection signals the sidebar owns input.
|
||||
drawSelectionHighlight(image, 20, y - 2, window.viewportWidth - 40, HUB_ROW_HEIGHT - 1, window.focused, 8);
|
||||
}
|
||||
image.drawText(terminalFont, 32, y + 2, item.label, selected ? 255 : 200);
|
||||
image.drawText(chromeFont(), 32, y + 2, item.label, selected ? 255 : 200);
|
||||
}
|
||||
if (items.length > visibleRowCount) {
|
||||
drawListScrollbar(
|
||||
@@ -1428,21 +1445,21 @@ function paintHub(window: HubWindow): GrayImage {
|
||||
);
|
||||
}
|
||||
|
||||
image.drawText(terminalFont, 24, window.viewportHeight - 24, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
image.drawText(chromeFont(), 24, window.viewportHeight - 24, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
function paintAddConnection(window: HubWindow): GrayImage {
|
||||
const image = new GrayImage(window.viewportWidth, window.viewportHeight, 0);
|
||||
image.drawText(terminalFont, 18, 10, "Add connection", 220);
|
||||
image.drawText(terminalFont, 24, 34, "Type the g2mirror://token@host string in the", 170);
|
||||
image.drawText(terminalFont, 24, 48, "phone app (or use voice input from the menu).", 170);
|
||||
image.drawText(chromeFont(), 18, 10, "Add connection", 220);
|
||||
image.drawText(chromeFont(), 24, 34, "Type the g2mirror://token@host string in the", 170);
|
||||
image.drawText(chromeFont(), 24, 48, "phone app (or use voice input from the menu).", 170);
|
||||
const draft = terminalNewConnectionSetting.get();
|
||||
image.drawText(terminalFont, 24, 76, truncateLabel(draft || "(empty)", 52), 220);
|
||||
image.drawText(chromeFont(), 24, 76, truncateLabel(draft || "(empty)", 52), 220);
|
||||
if (window.addError) {
|
||||
image.drawText(terminalFont, 24, 96, window.addError, 150);
|
||||
image.drawText(chromeFont(), 24, 96, window.addError, 150);
|
||||
}
|
||||
image.drawText(terminalFont, 24, window.viewportHeight - 24, `click save ${GESTURE_DOUBLE_CLICK} cancel`, 110);
|
||||
image.drawText(chromeFont(), 24, window.viewportHeight - 24, `click save ${GESTURE_DOUBLE_CLICK} cancel`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -1467,11 +1484,37 @@ function hubStatusLine(window: HubWindow): string {
|
||||
return anyRetrying ? `${summary} Retrying...` : summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw one terminal row at a fixed integer cell pitch, so glyph columns stay
|
||||
* aligned with the emulator's grid arithmetic even when a TTF face has
|
||||
* fractional advances. Identical to drawText for the 6px bitmap default.
|
||||
*/
|
||||
function drawGridRow(
|
||||
image: GrayImage,
|
||||
font: UiFont,
|
||||
cellWidth: number,
|
||||
rowY: number,
|
||||
text: string,
|
||||
value: number,
|
||||
): void {
|
||||
let col = 0;
|
||||
for (const char of text) {
|
||||
const codePoint = char.codePointAt(0) ?? 32;
|
||||
if (codePoint !== 32) {
|
||||
const glyph = font.getGlyph(codePoint);
|
||||
if (glyph && glyph.bbxWidth > 0) {
|
||||
image.drawGlyph(font, glyph, col * cellWidth, rowY, value);
|
||||
}
|
||||
}
|
||||
col++;
|
||||
}
|
||||
}
|
||||
|
||||
function paintView(window: ViewWindow): GrayImage {
|
||||
const image = new GrayImage(window.viewportWidth, window.viewportHeight, 0);
|
||||
if (!window.receivedData) {
|
||||
image.drawText(terminalFont, 24, 110, window.status, 170);
|
||||
image.drawText(terminalFont, 24, 130, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
image.drawText(chromeFont(), 24, 110, window.status, 170);
|
||||
image.drawText(chromeFont(), 24, 130, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -1485,7 +1528,7 @@ function paintView(window: ViewWindow): GrayImage {
|
||||
// Draw the cursor only if its line is within the visible window.
|
||||
const cursorScreenRow = historyNext + window.emulator.cursorRow() - top;
|
||||
if (cursorScreenRow >= 0 && cursorScreenRow < rows) {
|
||||
image.fillRect(window.emulator.cursorCol() * CELL_WIDTH, cursorScreenRow * CELL_HEIGHT, CELL_WIDTH, CELL_HEIGHT, 70);
|
||||
image.fillRect(window.emulator.cursorCol() * window.cellWidth, cursorScreenRow * window.cellHeight, window.cellWidth, window.cellHeight, 70);
|
||||
}
|
||||
|
||||
// Stale content stays visible across a disconnect, so flag it: a status
|
||||
@@ -1493,12 +1536,12 @@ function paintView(window: ViewWindow): GrayImage {
|
||||
// Text is deferred glyphs (always on top of raster), so the covered rows
|
||||
// must be suppressed rather than painted over.
|
||||
const statusBannerY = window.client.state().phase !== "attached"
|
||||
? window.viewportHeight - CELL_HEIGHT
|
||||
? window.viewportHeight - window.cellHeight
|
||||
: null;
|
||||
|
||||
for (let row = 0; row < rows; row++) {
|
||||
const rowY = row * CELL_HEIGHT;
|
||||
if (statusBannerY !== null && rowY + CELL_HEIGHT > statusBannerY) continue;
|
||||
const rowY = row * window.cellHeight;
|
||||
if (statusBannerY !== null && rowY + window.cellHeight > statusBannerY) continue;
|
||||
const absolute = top + row;
|
||||
let text = "";
|
||||
if (absolute >= historyNext) {
|
||||
@@ -1507,15 +1550,15 @@ function paintView(window: ViewWindow): GrayImage {
|
||||
} else if (absolute >= window.archiveStart) {
|
||||
text = window.archive[absolute - window.archiveStart] ?? "";
|
||||
}
|
||||
if (text.length) image.drawText(terminalFont, 0, rowY, text, 200);
|
||||
if (text.length) drawGridRow(image, window.font, window.cellWidth, rowY, text, 200);
|
||||
}
|
||||
|
||||
if (!following) {
|
||||
drawScrollIndicator(image, top, window.archiveStart, bottomTop);
|
||||
}
|
||||
if (statusBannerY !== null) {
|
||||
image.fillRect(0, statusBannerY, window.viewportWidth, CELL_HEIGHT, 0);
|
||||
image.drawText(terminalFont, 0, statusBannerY, window.status, 170);
|
||||
image.fillRect(0, statusBannerY, window.viewportWidth, window.cellHeight, 0);
|
||||
image.drawText(chromeFont(), 0, statusBannerY, window.status, 170);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@ import "@nativescript/core/globals";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { flattenPlanesWithDraws, planesFingerprint, singlePlane, type Plane } from "../../graphics/plane";
|
||||
import { prepareFrameDraws } from "../../graphics/glyph-wire";
|
||||
import { getDefaultSmallFont, getFont } from "../../graphics/bdffont";
|
||||
import { getFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import * as frameTimings from "../../native/frame-timings";
|
||||
import {
|
||||
cancelTimerNotification,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { getDefaultSmallFont, type BdfFont } from "../../graphics/bdffont";
|
||||
import { GrayImage, type UiFont } from "../../graphics/image";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { writeTextToDownloads } from "../../native/file-access";
|
||||
import { voiceControlBridge, type VoiceTranscriptEvent } from "../../native/voice-control";
|
||||
import { Layer, type DashboardInputEvent, type LayerContext } from "../../ui/layers";
|
||||
@@ -112,7 +112,7 @@ function transcriptTimestamp(): string {
|
||||
);
|
||||
}
|
||||
|
||||
function wrapTranscribeText(font: BdfFont, text: string, maxWidth: number): string[] {
|
||||
function wrapTranscribeText(font: UiFont, text: string, maxWidth: number): string[] {
|
||||
const words = text.split(/\s+/).filter(Boolean);
|
||||
const lines: string[] = [];
|
||||
let line = "";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { getDefaultLargeFont, getDefaultMediumFont, getDefaultSmallFont, type BdfFont } from "../../graphics/bdffont";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { getDefaultLargeFont, getDefaultMediumFont, getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { GrayImage, type UiFont } from "../../graphics/image";
|
||||
import { wrapText, truncateText } from "../../graphics/textwrap";
|
||||
import { clamp } from "../../util/numeric-util";
|
||||
import { type ForecastPeriod, type WeatherState } from "../../native/weather";
|
||||
@@ -167,7 +167,7 @@ export class WeatherLayer implements Layer {
|
||||
|
||||
private drawMessage(
|
||||
image: GrayImage,
|
||||
font: BdfFont,
|
||||
font: UiFont,
|
||||
width: number,
|
||||
height: number,
|
||||
message: string,
|
||||
|
||||
Reference in new issue
Block a user