EvenHub extensions: Fonts, window icons, touch-start events

This commit is contained in:
James Babcock committed 2026-10-07 01:22:42 -07:00
1 parent 4ee0af86cc
commit 84baee9c76
25 files changed
+1884 -127

No files matched your search

+23
View File
@@ -118,3 +118,26 @@ test("flags accept booleans (extension layouts) as well as 0/1 (stock)", () => {
);
assert.equal(page.containers[0].selectBorder, true);
});
test("a layout font is the default for text and list containers, which override it field by field", () => {
const page = parsePage({
font: { family: "Inter", size: 24 },
listObject: [{ containerID: 1, containerName: "l", font: { weight: "bold" } }],
textObject: [{ containerID: 2, containerName: "t" }, { containerID: 3, containerName: "u", font: { family: "Terminus" } }],
imageObject: [{ containerID: 4, containerName: "i" }],
});
assert.deepEqual(
page.containers.map((c) => [c.name, c.font]),
[
["l", { family: "Inter", size: 24, weight: 700 }],
["i", undefined],
["t", { family: "Inter", size: 24 }],
["u", { family: "Terminus", size: 24 }],
],
);
});
test("containers without a font anywhere keep the stock font", () => {
const page = parsePage({ textObject: [{ containerID: 1, containerName: "t", content: "x" }] });
assert.equal(page.containers[0].font, undefined);
});
+45
View File
@@ -0,0 +1,45 @@
// The stock DeviceStatus an EvenHub app sees (getGlassesInfo().status and the
// deviceStatusChanged push), built from Faceclaw's view of the glasses.
const test = require("node:test");
const assert = require("node:assert/strict");
const { buildEvenHubDeviceStatus, sameDeviceStatus, PLACEHOLDER_SERIAL } = require("../.test-build/app/apps/evenhub/device-status.js");
const worn = { serial: "S200LAAJ0123", connected: true, worn: true, battery: 73, charging: false };
test("connected, worn glasses report their real values", () => {
assert.deepEqual(buildEvenHubDeviceStatus(worn), {
sn: "S200LAAJ0123",
connectType: "connected",
isWearing: true,
batteryLevel: 73,
isCharging: false,
isInCase: false,
});
});
test("charging means in the case, since the G2 only charges there", () => {
const status = buildEvenHubDeviceStatus({ ...worn, worn: false, charging: true });
assert.equal(status.isCharging, true);
assert.equal(status.isInCase, true);
assert.equal(status.isWearing, false);
});
test("unknown wear state and battery are omitted, not guessed", () => {
const status = buildEvenHubDeviceStatus({ serial: null, connected: false, worn: null, battery: null, charging: false });
assert.deepEqual(status, { sn: PLACEHOLDER_SERIAL, connectType: "disconnected", isCharging: false, isInCase: false });
assert.equal("isWearing" in status, false);
assert.equal("batteryLevel" in status, false);
});
test("a blank serial falls back to the placeholder", () => {
assert.equal(buildEvenHubDeviceStatus({ ...worn, serial: " " }).sn, PLACEHOLDER_SERIAL);
});
test("sameDeviceStatus compares every field", () => {
const a = buildEvenHubDeviceStatus(worn);
assert.equal(sameDeviceStatus(a, buildEvenHubDeviceStatus(worn)), true);
assert.equal(sameDeviceStatus(a, buildEvenHubDeviceStatus({ ...worn, battery: 72 })), false);
assert.equal(sameDeviceStatus(a, buildEvenHubDeviceStatus({ ...worn, worn: null })), false);
assert.equal(sameDeviceStatus(a, buildEvenHubDeviceStatus({ ...worn, connected: false })), false);
});
+63
View File
@@ -99,3 +99,66 @@ test('assistant tools send specs to the host and run handlers on invoke', async
const results = posted.filter((p) => p.name === 'faceclawExtToolResult').map((p) => p.args).sort((a, b) => a[0] - b[0]);
assert.deepEqual(results, [[7, true, 42], [8, false, 'nope'], [9, false, 'unknown tool missing']]);
});
test('touch-down and text input are requested while someone listens, and unsubscribing twice is harmless', () => {
const { win, fc, posted } = page();
const seen = [];
const offTouch = fc.addTouchDownListener((e) => seen.push(`touch:${e.source}`));
const offText1 = fc.addTextInputListener((e) => seen.push(`text1:${e.text}`));
const offText2 = fc.addTextInputListener((e) => seen.push(`text2:${e.text}`));
win.__fcExtEvent('touchDown', { source: 'watch', timestampMs: 5 });
win.__fcExtEvent('textInput', { text: 'hi' });
offText1();
offText1();
win.__fcExtEvent('textInput', { text: 'again' });
offText2();
offTouch();
assert.deepEqual(seen, ['touch:watch', 'text1:hi', 'text2:hi', 'text2:again']);
assert.deepEqual(posted.map((p) => p.args), [
['setTouchDown', true],
['setTextInput', true],
['setTextInput', false],
['setTouchDown', false],
]);
});
test('window icons are sent as plain arrays, and clearing sends null', async () => {
const { win, fc, posted } = page();
const set = fc.setWindowIcon({ width: 1, height: 2, data: new Uint8ClampedArray([7, 9]) });
const clear = fc.setWindowIcon(null);
assert.deepEqual(posted.map((p) => p.args), [
['setWindowIcon', { width: 1, height: 2, data: [7, 9] }],
['setWindowIcon', null],
]);
win.__fcExtResolve(posted[0].id, true, null);
win.__fcExtResolve(posted[1].id, false, 'setWindowIcon: bad');
await set;
await assert.rejects(clear, /setWindowIcon: bad/);
});
test('window controls are fire-and-forget; startVoiceInput resolves the host answer', async () => {
const { win, fc, posted } = page();
fc.setAttention(1);
fc.setKeepScreenOn(false);
const voice = fc.startVoiceInput();
assert.deepEqual(posted.map((p) => [p.args, p.id === 0]), [
[['setAttention', true], true],
[['setKeepScreenOn', false], true],
[['startVoiceInput'], false],
]);
win.__fcExtResolve(posted[2].id, true, false);
assert.equal(await voice, false);
});
test('font queries are calls; measureText sends null for no font', () => {
const { fc, posted } = page();
void fc.getFonts();
void fc.measureText('hi');
void fc.measureText(42, { family: 'Inter', size: 30 });
assert.deepEqual(posted.map((p) => p.args), [
['getFonts'],
['measureText', 'hi', null],
['measureText', '42', { family: 'Inter', size: 30 }],
]);
assert.ok(posted.every((p) => p.id > 0));
});
+84
View File
@@ -0,0 +1,84 @@
// Font options for EvenHub text and list containers (extension layouts):
// parsing, layout-default inheritance, and choosing a face.
const test = require("node:test");
const assert = require("node:assert/strict");
const {
parseFontSpec,
mergeFontSpecs,
selectFontFace,
describeFontFamilies,
MAX_FONT_SIZE,
} = require("../.test-build/app/apps/evenhub/font-spec.js");
const TERMINUS_SIZES = [12, 14, 16, 18, 20, 22, 24, 28, 32];
const ttf = (family, weight, monospace = false) => ({ family, weight, sizes: null, monospace, key: `ttf:${family}:${weight}` });
const FACES = [
{ family: "EvenHub", weight: 400, sizes: [20], monospace: false, key: "stock" },
{ family: "Terminus", weight: 400, sizes: TERMINUS_SIZES, monospace: true, key: "terminus:400" },
{ family: "Terminus", weight: 700, sizes: TERMINUS_SIZES, monospace: true, key: "terminus:700" },
ttf("Inter 18pt", 300), ttf("Inter 18pt", 400), ttf("Inter 18pt", 700),
ttf("Roboto", 300), ttf("Roboto", 400), ttf("Roboto", 700),
ttf("Roboto Mono", 300, true), ttf("Roboto Mono", 400, true), ttf("Roboto Mono", 700, true),
];
const pick = (spec, faces = FACES) => {
const choice = selectFontFace(spec, faces);
return choice && `${choice.face.key}@${choice.size}`;
};
test("no font object means no spec (the stock font); an empty one means the defaults", () => {
assert.equal(parseFontSpec(undefined), undefined);
assert.equal(parseFontSpec("Roboto"), undefined);
assert.deepEqual(parseFontSpec({}), {});
assert.equal(pick({}), "ttf:Roboto:400@20");
});
test("sizes are rounded and clamped, weights take keywords and numeric strings", () => {
assert.deepEqual(parseFontSpec({ family: " Inter ", size: 17.6, weight: "bold" }), { family: "Inter", size: 18, weight: 700 });
assert.deepEqual(parseFontSpec({ size: 1000, weight: "normal" }), { size: MAX_FONT_SIZE, weight: 400 });
assert.deepEqual(parseFontSpec({ size: 2, weight: "300" }), { size: 6, weight: 300 });
assert.deepEqual(parseFontSpec({ family: "", size: "x", weight: "heavy" }), {});
});
test("a container's font overrides the layout default field by field", () => {
assert.deepEqual(mergeFontSpecs({ family: "Inter", size: 24 }, { size: 30 }), { family: "Inter", size: 30 });
assert.deepEqual(mergeFontSpecs(undefined, { size: 30 }), { size: 30 });
assert.deepEqual(mergeFontSpecs({ family: "Inter" }, undefined), { family: "Inter" });
assert.equal(mergeFontSpecs(undefined, undefined), undefined);
});
test("families match loosely, including without an optical-size suffix", () => {
assert.equal(pick({ family: "inter" }), "ttf:Inter 18pt:400@20");
assert.equal(pick({ family: "Inter 18pt" }), "ttf:Inter 18pt:400@20");
assert.equal(pick({ family: "robotomono", size: 14 }), "ttf:Roboto Mono:400@14");
assert.equal(pick({ family: "ROBOTO" }), "ttf:Roboto:400@20", "Roboto doesn't pick up Roboto Mono");
});
test("an unknown family falls back to Roboto, and with no Roboto there is no choice", () => {
assert.equal(pick({ family: "Comic Sans", weight: 700 }), "ttf:Roboto:700@20");
assert.equal(pick({ family: "Comic Sans" }, FACES.slice(0, 3)), null);
});
test("weights follow CSS matching", () => {
assert.equal(pick({ family: "Inter", weight: 500 }), "ttf:Inter 18pt:400@20", "400-500 look lighter before heavier");
assert.equal(pick({ family: "Inter", weight: 600 }), "ttf:Inter 18pt:700@20", "heavier requests look heavier first");
assert.equal(pick({ family: "Inter", weight: 350 }), "ttf:Inter 18pt:300@20", "lighter requests look lighter first");
assert.equal(pick({ family: "Inter", weight: 100 }), "ttf:Inter 18pt:300@20");
assert.equal(pick({ family: "Inter", weight: 900 }), "ttf:Inter 18pt:700@20");
});
test("bitmap families snap to their nearest size", () => {
assert.equal(pick({ family: "Terminus", size: 25 }), "terminus:400@24");
assert.equal(pick({ family: "Terminus", size: 26, weight: 700 }), "terminus:700@24", "a tie takes the smaller size");
assert.equal(pick({ family: "Terminus", size: 100 }), "terminus:400@32");
assert.equal(pick({ family: "EvenHub", size: 40, weight: 700 }), "stock@20");
});
test("families are listed once each, by their app-facing name", () => {
const families = describeFontFamilies(FACES);
assert.deepEqual(families.map((f) => f.family), ["EvenHub", "Inter", "Roboto", "Roboto Mono", "Terminus"]);
const terminus = families.find((f) => f.family === "Terminus");
assert.deepEqual(terminus, { family: "Terminus", weights: [400, 700], sizes: TERMINUS_SIZES, monospace: true });
const inter = families.find((f) => f.family === "Inter");
assert.deepEqual(inter, { family: "Inter", weights: [300, 400, 700], monospace: false });
});
+56
View File
@@ -0,0 +1,56 @@
// App-supplied switcher icons (extension setWindowIcon): parsing the pixel
// buffer from the bridge, and scaling it to the switcher's icon size.
const test = require("node:test");
const assert = require("node:assert/strict");
const { parseWindowIcon, WindowIconRenderer, MAX_WINDOW_ICON_DIMENSION } = require("../.test-build/app/apps/evenhub/window-icon.js");
test("grayscale data is taken as-is", () => {
const icon = parseWindowIcon({ width: 2, height: 2, data: [0, 64, 128, 255] });
assert.deepEqual([...icon.pixels], [0, 64, 128, 255]);
});
test("RGBA data (an ImageData) becomes luminance times alpha", () => {
const icon = parseWindowIcon({
width: 3,
height: 1,
data: [255, 255, 255, 255, 255, 255, 255, 0, 0, 255, 0, 255],
});
assert.deepEqual([...icon.pixels], [255, 0, 182]);
});
test("a JSON-ified typed array parses like a plain array", () => {
const icon = parseWindowIcon({ width: 2, height: 1, data: { 0: 10, 1: 20 } });
assert.deepEqual([...icon.pixels], [10, 20]);
});
test("malformed icons are refused", () => {
assert.equal(parseWindowIcon(null), null);
assert.equal(parseWindowIcon({ width: 2, height: 2, data: [1, 2, 3] }), null, "wrong length");
assert.equal(parseWindowIcon({ width: 0, height: 2, data: [] }), null, "empty");
assert.equal(parseWindowIcon({ width: 1.5, height: 2, data: [1, 2, 3] }), null, "fractional size");
assert.equal(parseWindowIcon({ width: 1, height: 1, data: ["x"] }), null, "non-numeric data");
const big = MAX_WINDOW_ICON_DIMENSION + 1;
assert.equal(parseWindowIcon({ width: big, height: 1, data: new Array(big).fill(0) }), null, "too wide");
});
test("icons shrink to fit the box, keeping their aspect ratio and averaging pixels", () => {
const data = [];
for (let y = 0; y < 4; y++) for (let x = 0; x < 8; x++) data.push(x < 4 ? 0 : 200);
const renderer = new WindowIconRenderer(parseWindowIcon({ width: 8, height: 4, data }));
const small = renderer.render(4);
assert.equal(small.width, 4);
assert.equal(small.height, 2);
assert.deepEqual([...small.pixels], [0, 0, 200, 200, 0, 0, 200, 200]);
const odd = renderer.render(3);
assert.equal(odd.width, 3);
// The middle column straddles the edge between the halves.
assert.equal(odd.pixels[1], 100);
});
test("renders are cached per size, and a fitting icon is used unscaled", () => {
const source = parseWindowIcon({ width: 4, height: 4, data: new Array(16).fill(9) });
const renderer = new WindowIconRenderer(source);
assert.equal(renderer.render(32), renderer.render(32));
assert.equal(renderer.render(4), source);
});
+1
View File
@@ -146,6 +146,7 @@ function fixture() {
'../native/weather': { weatherBridge: { setSessionActive() {} } },
'./glance-host': { GlanceHost }, './events': events,
'./lock-screen': { LOCK_SCREEN_SURFACE_ID: 'lock-screen', createLockScreenImage: () => new images.GrayImage(640, 480, 123) },
'./glasses-presence': load('app/g2/glasses-presence.ts', {}),
'./device-addresses': { loadDeviceAddresses: () => ({ right: 'AA', left: 'BB', ring: '' }) }, './ios-peripheral-identity': { deviceAddressError: () => null },
'./firmware-compat': load('app/g2/firmware-compat.ts', {}), './reconnect-policy': load('app/g2/reconnect-policy.ts', {}),
'../apps/launcher': { launcherEntries: () => [] },
+3
View File
@@ -47,6 +47,9 @@
"../app/apps/microphones/name-guess.ts",
"../app/apps/evenhub/containers.ts",
"../app/apps/evenhub/list-menu.ts",
"../app/apps/evenhub/device-status.ts",
"../app/apps/evenhub/font-spec.ts",
"../app/apps/evenhub/window-icon.ts",
"../app/apps/timer/timer-model.ts",
"../app/apps/teleprompter/script-tracker.ts",
"../app/apps/nightscout/nightscout-alerts.ts",