forked from Blendman974/faceclaw
EvenHub compativility fixes: Z-order changes, different text color distribution, text containers scroll
This commit is contained in:
1 parent
c713815694
commit
10a9c85f27
22 files changed
+1545
-610
No files matched your search
@@ -130,9 +130,9 @@ test("a layout font is the default for text and list containers, which override
|
||||
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 }],
|
||||
["i", undefined],
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
// updateImageRawData conversion (app/apps/evenhub/image-pipeline.ts), checked
|
||||
// against what the Even phone app's decompiled _prepare / _prepareLegacyRaw do.
|
||||
const test = require("node:test");
|
||||
const assert = require("node:assert/strict");
|
||||
const UPNG = require("upng-js");
|
||||
|
||||
const {
|
||||
IMAGE_EXCEPTION,
|
||||
IMAGE_SEND_FAILED,
|
||||
IMAGE_SIZE_INVALID,
|
||||
IMAGE_SUCCESS,
|
||||
detectImageFormat,
|
||||
grayLevel,
|
||||
prepareImageUpdate,
|
||||
resizeRgbaCover,
|
||||
} = require("../.test-build/app/apps/evenhub/image-pipeline.js");
|
||||
|
||||
const noNative = () => null;
|
||||
const request = (over) => ({
|
||||
imageData: [],
|
||||
compressMode: 2,
|
||||
requestWidth: 0,
|
||||
requestHeight: 0,
|
||||
geometry: { width: 20, height: 20 },
|
||||
decodeNative: noNative,
|
||||
stockLimits: true,
|
||||
...over,
|
||||
});
|
||||
|
||||
/** A PNG of the given RGBA pixels. */
|
||||
function png(width, height, rgba) {
|
||||
return Array.from(new Uint8Array(UPNG.encode([Uint8Array.from(rgba).buffer], width, height, 0)));
|
||||
}
|
||||
|
||||
test("imageData must be an array of integers", () => {
|
||||
assert.equal(prepareImageUpdate(request({ imageData: "AAAA" })).result, IMAGE_SEND_FAILED);
|
||||
assert.equal(prepareImageUpdate(request({ imageData: { 0: 1, 1: 2 } })).result, IMAGE_SEND_FAILED);
|
||||
assert.equal(prepareImageUpdate(request({ imageData: [1, 2.5] })).result, IMAGE_SEND_FAILED);
|
||||
});
|
||||
|
||||
test("formats are recognized by their magic bytes", () => {
|
||||
assert.equal(detectImageFormat(Uint8Array.from(png(1, 1, [0, 0, 0, 255]))), "png");
|
||||
assert.equal(detectImageFormat(Uint8Array.from([0xff, 0xd8, 0xff, 0xe0])), "jpeg");
|
||||
assert.equal(detectImageFormat(Uint8Array.from([0x52, 0x49, 0x46, 0x46, 0, 0, 0, 0, 0x57, 0x45, 0x42, 0x50])), "webp");
|
||||
assert.equal(detectImageFormat(Uint8Array.from([0x47, 0x49, 0x46, 0x38, 0x39, 0x61])), "gif");
|
||||
assert.equal(detectImageFormat(Uint8Array.from([0x42, 0x4d, 0, 0])), "bmp");
|
||||
assert.equal(detectImageFormat(Uint8Array.from([1, 2, 3])), "raw");
|
||||
});
|
||||
|
||||
test("grey uses 299/587/114 weights rounded to 16 levels, ignoring alpha", () => {
|
||||
assert.equal(grayLevel(255, 0, 0), 4);
|
||||
assert.equal(grayLevel(255, 255, 255), 15);
|
||||
assert.equal(grayLevel(0, 0, 0), 0);
|
||||
// A transparent white pixel is white: the phone app never looks at alpha.
|
||||
const result = prepareImageUpdate(request({ imageData: png(20, 20, new Array(20 * 20).fill([255, 255, 255, 0]).flat()) }));
|
||||
assert.equal(result.result, IMAGE_SUCCESS);
|
||||
assert.ok(result.levels.every((level) => level === 15));
|
||||
});
|
||||
|
||||
test("an encoded image is scaled to cover the container and centre-cropped", () => {
|
||||
// 4x2: columns 0..3 lit 0, 85, 170, 255. Covering 20x20 scales by 10 to
|
||||
// 40x20 and crops 10px a side, so only columns 1 and 2 survive.
|
||||
const row = [0, 85, 170, 255].flatMap((v) => [v, v, v, 255]);
|
||||
const result = prepareImageUpdate(request({ imageData: png(4, 2, [...row, ...row]) }));
|
||||
assert.equal(result.result, IMAGE_SUCCESS);
|
||||
assert.deepEqual([result.width, result.height], [20, 20]);
|
||||
assert.deepEqual(Array.from(result.levels.slice(0, 20)), [...new Array(10).fill(grayLevel(85, 85, 85)), ...new Array(10).fill(grayLevel(170, 170, 170))]);
|
||||
});
|
||||
|
||||
test("the cover resize samples source pixel centres", () => {
|
||||
const source = { width: 3, height: 1, rgba: Uint8Array.from([10, 0, 0, 0, 20, 0, 0, 0, 30, 0, 0, 0]) };
|
||||
const wide = resizeRgbaCover(source, 6, 2);
|
||||
assert.deepEqual(Array.from(wide.rgba.filter((_, i) => i % 4 === 0)), [10, 10, 20, 20, 30, 30, 10, 10, 20, 20, 30, 30]);
|
||||
});
|
||||
|
||||
test("width and height sent with the update replace the container's", () => {
|
||||
const black = new Array(30 * 30).fill([0, 0, 0, 255]).flat();
|
||||
const result = prepareImageUpdate(request({ imageData: png(30, 30, black), requestWidth: 40, requestHeight: 25 }));
|
||||
assert.deepEqual([result.width, result.height], [40, 25]);
|
||||
});
|
||||
|
||||
test("without a usable container size, the decoded size must itself be in range", () => {
|
||||
const tiny = new Array(10 * 10).fill([0, 0, 0, 255]).flat();
|
||||
assert.equal(prepareImageUpdate(request({ imageData: png(10, 10, tiny), geometry: null })).result, IMAGE_SIZE_INVALID);
|
||||
});
|
||||
|
||||
test("JPEG, WebP and GIF go to the native decoder; a failed decode is an exception", () => {
|
||||
const jpeg = [0xff, 0xd8, 0xff, 0xe0];
|
||||
const decoded = prepareImageUpdate(request({
|
||||
imageData: jpeg,
|
||||
decodeNative: () => ({ width: 20, height: 20, rgba: new Uint8Array(20 * 20 * 4).fill(255) }),
|
||||
}));
|
||||
assert.equal(decoded.result, IMAGE_SUCCESS);
|
||||
assert.equal(decoded.format, "jpeg");
|
||||
assert.equal(prepareImageUpdate(request({ imageData: jpeg })).result, IMAGE_EXCEPTION);
|
||||
});
|
||||
|
||||
test("raw pixels need compressMode 2 and exactly the container's size", () => {
|
||||
const raw = new Array(400).fill(0);
|
||||
assert.equal(prepareImageUpdate(request({ imageData: raw })).result, IMAGE_SUCCESS);
|
||||
assert.equal(prepareImageUpdate(request({ imageData: raw, compressMode: 0 })).result, IMAGE_EXCEPTION);
|
||||
assert.equal(prepareImageUpdate(request({ imageData: raw.slice(1) })).result, IMAGE_EXCEPTION);
|
||||
assert.equal(prepareImageUpdate(request({ imageData: raw, geometry: { width: 400, height: 1 } })).result, IMAGE_SIZE_INVALID);
|
||||
});
|
||||
|
||||
test("raw bytes up to 15 are already 4-bit levels; larger ones are 8-bit grey", () => {
|
||||
const raw = new Array(400).fill(0);
|
||||
raw.splice(0, 4, 15, 16, 128, 255);
|
||||
const { levels } = prepareImageUpdate(request({ imageData: raw }));
|
||||
assert.deepEqual(Array.from(levels.slice(0, 4)), [15, 1, 8, 15]);
|
||||
});
|
||||
|
||||
test("4-bit raw rows are padded to whole bytes", () => {
|
||||
// 21 wide: 11 bytes a row, high nibble first, the last low nibble unused.
|
||||
const rows = [];
|
||||
for (let y = 0; y < 20; y++) rows.push(0xf0, ...new Array(9).fill(0), 0x0f << 4);
|
||||
const { result, levels } = prepareImageUpdate(request({ imageData: rows, geometry: { width: 21, height: 20 } }));
|
||||
assert.equal(result, IMAGE_SUCCESS);
|
||||
assert.deepEqual([levels[0], levels[1], levels[20], levels[21]], [15, 0, 15, 15]);
|
||||
});
|
||||
|
||||
test("extended layouts skip the stock size and compressMode rules", () => {
|
||||
const big = new Array(400 * 200).fill(0);
|
||||
const result = prepareImageUpdate(request({ imageData: big, compressMode: 0, geometry: { width: 400, height: 200 }, stockLimits: false }));
|
||||
assert.equal(result.result, IMAGE_SUCCESS);
|
||||
});
|
||||
@@ -1,18 +1,10 @@
|
||||
// The EvenHub layout debug log: the stock container-order rules it compares
|
||||
// our paint order against (from the evenRealities-openCFW reconstruction of
|
||||
// evenhub_ui_containers.c), and the stock notes it attaches to updates.
|
||||
// The EvenHub layout debug log (app/apps/evenhub/layout-debug.ts): page notes
|
||||
// and the per-update lines it writes to logcat.
|
||||
const test = require("node:test");
|
||||
const assert = require("node:assert/strict");
|
||||
|
||||
const { parsePage, paintOrder } = require("../.test-build/app/apps/evenhub/containers.js");
|
||||
const {
|
||||
describeImageUpdate,
|
||||
describePage,
|
||||
stockDifferences,
|
||||
stockPaintOrder,
|
||||
} = require("../.test-build/app/apps/evenhub/layout-debug.js");
|
||||
|
||||
const names = (containers) => containers.map((c) => c.name);
|
||||
const { parsePage } = require("../.test-build/app/apps/evenhub/containers.js");
|
||||
const { describeImageUpdate, describePage, pageNotes } = require("../.test-build/app/apps/evenhub/layout-debug.js");
|
||||
|
||||
const iconOverBody = (extra = {}) =>
|
||||
parsePage({
|
||||
@@ -21,102 +13,51 @@ const iconOverBody = (extra = {}) =>
|
||||
imageObject: [{ containerID: 2, containerName: "icon", xPosition: 8, yPosition: 8, width: 24, height: 24, ...extra.image }],
|
||||
});
|
||||
|
||||
test("without zOrderIndex, stock orders lists, then texts, then images", () => {
|
||||
const page = parsePage({
|
||||
imageObject: [{ containerID: 1, containerName: "img" }],
|
||||
textObject: [{ containerID: 2, containerName: "txt" }],
|
||||
listObject: [{ containerID: 3, containerName: "lst" }],
|
||||
});
|
||||
assert.deepEqual(names(stockPaintOrder(page.containers)), ["lst", "txt", "img"]);
|
||||
// ...where we put images at the bottom.
|
||||
assert.deepEqual(names(paintOrder(page.containers)), ["img", "lst", "txt"]);
|
||||
});
|
||||
|
||||
test("stock sorts by zOrderIndex only when every container has one", () => {
|
||||
const all = iconOverBody({ text: { zOrderIndex: 2 }, image: { zOrderIndex: 1 } });
|
||||
assert.deepEqual(names(stockPaintOrder(all.containers)), ["icon", "body"]);
|
||||
assert.deepEqual(names(paintOrder(all.containers)), ["icon", "body"]);
|
||||
|
||||
const some = iconOverBody({ text: { zOrderIndex: 2 } });
|
||||
assert.deepEqual(names(stockPaintOrder(some.containers)), ["body", "icon"]);
|
||||
assert.deepEqual(names(paintOrder(some.containers)), ["icon", "body"]);
|
||||
assert.ok(stockDifferences(some).some((note) => note.includes("zOrderIndex is set on 1 of 2")));
|
||||
});
|
||||
|
||||
test("an image overlapping text is flagged when the two orders disagree", () => {
|
||||
const notes = stockDifferences(iconOverBody());
|
||||
assert.ok(notes.some((note) => note.startsWith("paint order differs")));
|
||||
assert.ok(notes.includes('image#2 "icon" overlaps text#1 "body": we draw text#1 "body" on top, stock draws image#2 "icon" on top'));
|
||||
});
|
||||
|
||||
test("non-overlapping containers in a different order raise no overlap note", () => {
|
||||
const notes = stockDifferences(iconOverBody({ text: { yPosition: 100, height: 100 } }));
|
||||
assert.ok(!notes.some((note) => note.includes("overlaps")));
|
||||
});
|
||||
|
||||
test("image containers outside stock's size limits are flagged", () => {
|
||||
const notes = stockDifferences(iconOverBody({ image: { width: 16, height: 16 } }));
|
||||
assert.ok(notes.some((note) => note.includes("16x16") && note.includes("fails the whole page")));
|
||||
});
|
||||
|
||||
test("a shared container id resolves to the first container in stock order", () => {
|
||||
const page = iconOverBody({ image: { containerID: 1 } });
|
||||
assert.ok(stockDifferences(page).includes('id 1 is shared by text#1 "body", image#1 "icon"; stock resolves it to text#1 "body" only'));
|
||||
const lines = describeImageUpdate({
|
||||
page,
|
||||
sentId: 1,
|
||||
sentName: "",
|
||||
container: page.containers.find((c) => c.kind === "image"),
|
||||
raw: [],
|
||||
bytes: null,
|
||||
decoded: null,
|
||||
result: 1,
|
||||
});
|
||||
assert.ok(lines.some((line) => line.includes("stock drops this update")));
|
||||
});
|
||||
|
||||
test("image updates note base64 payloads, size mismatches and blank images", () => {
|
||||
const page = iconOverBody();
|
||||
const icon = page.containers.find((c) => c.kind === "image");
|
||||
const lines = describeImageUpdate({
|
||||
page,
|
||||
sentId: 2,
|
||||
sentName: "icon",
|
||||
container: icon,
|
||||
raw: "AAAA",
|
||||
bytes: new Uint8Array(3),
|
||||
decoded: { pixels: new Uint8Array(4), width: 2, height: 2 },
|
||||
result: 0,
|
||||
});
|
||||
assert.match(lines[0], /payload=string\(4 chars\)/);
|
||||
assert.match(lines[0], /decoded=2x2 blank/);
|
||||
assert.ok(lines.some((line) => line.includes("base64-string")));
|
||||
assert.ok(lines.some((line) => line.includes("exactly the container's size (24x24)")));
|
||||
});
|
||||
|
||||
test("lit pixels are summarized with a bounding box", () => {
|
||||
const page = iconOverBody();
|
||||
const icon = page.containers.find((c) => c.kind === "image");
|
||||
const pixels = new Uint8Array(24 * 24);
|
||||
pixels[24 * 3 + 5] = 200;
|
||||
pixels[24 * 10 + 7] = 255;
|
||||
const [first] = describeImageUpdate({
|
||||
page,
|
||||
sentId: 2,
|
||||
sentName: "",
|
||||
container: icon,
|
||||
raw: Array.from(pixels),
|
||||
bytes: pixels,
|
||||
decoded: { pixels, width: 24, height: 24 },
|
||||
result: 0,
|
||||
});
|
||||
assert.match(first, /format=raw8 decoded=24x24 lit=2px max=255 bbox=5,3-7,10 result=0$/);
|
||||
});
|
||||
|
||||
test("describePage lists containers bottom to top and ends with the raw payload", () => {
|
||||
const lines = describePage("rebuildPageContainer", iconOverBody(), { containerTotalNum: 2 });
|
||||
assert.match(lines[0], /^rebuildPageContainer: 2 containers \(0 list, 1 text, 1 image\), containerTotalNum=2/);
|
||||
assert.match(lines[1], /^ {2}0: image#2 "icon" @8,8 24x24 no pixels yet$/);
|
||||
assert.match(lines[2], /^ {2}1: text#1 "body" @0,0 576x288 capture len=0 ""$/);
|
||||
assert.match(lines[1], /^ {2}0: text#1 "body" @0,0 576x288 capture len=0 ""$/);
|
||||
assert.match(lines[2], /^ {2}1: image#2 "icon" @8,8 24x24 no pixels yet$/);
|
||||
assert.equal(lines.at(-1), ' raw: {"containerTotalNum":2}');
|
||||
});
|
||||
|
||||
test("a shared container id is noted with the container it resolves to", () => {
|
||||
assert.ok(pageNotes(iconOverBody({ image: { containerID: 1 } })).includes(
|
||||
'id 1 is shared by text#1 "body", image#1 "icon"; updates and events resolve to text#1 "body" only',
|
||||
));
|
||||
});
|
||||
|
||||
test("capture-container problems and a wrong containerTotalNum are noted", () => {
|
||||
assert.ok(pageNotes(iconOverBody({ text: { isEventCapture: 0 } })).some((n) => n.startsWith("no event-capture container")));
|
||||
assert.ok(pageNotes(iconOverBody(), 3).some((n) => n.startsWith("containerTotalNum is 3 but 2")));
|
||||
assert.deepEqual(pageNotes(iconOverBody(), 2), []);
|
||||
});
|
||||
|
||||
const prepared = (over = {}) => ({ result: 0, levels: null, width: 0, height: 0, format: "raw", reason: "", ...over });
|
||||
|
||||
test("an update lists payload, size, lit pixels and outcome", () => {
|
||||
const page = iconOverBody();
|
||||
const levels = new Uint8Array(24 * 24);
|
||||
levels[24 * 3 + 5] = 9;
|
||||
levels[24 * 10 + 7] = 15;
|
||||
const [line] = describeImageUpdate({
|
||||
sentId: 2, sentName: "icon", raw: Array.from(levels), target: page.containers[1],
|
||||
prepared: prepared({ levels, width: 24, height: 24 }), shown: true, result: 0,
|
||||
});
|
||||
assert.equal(line, 'updateImageRawData id=2 "icon" -> image#2 "icon" payload=number[576] format=raw 24x24 lit=2px max=15/15 bbox=5,3-7,10 result=0 shown');
|
||||
});
|
||||
|
||||
test("an update says why it wasn't shown", () => {
|
||||
const page = iconOverBody({ image: { containerID: 1 } });
|
||||
const toText = describeImageUpdate({
|
||||
sentId: 1, sentName: "", raw: [], target: page.containers[0],
|
||||
prepared: prepared({ levels: new Uint8Array(1), width: 1, height: 1 }), shown: false, result: 4,
|
||||
});
|
||||
assert.ok(toText.some((line) => line.includes('resolves to text#1 "body", so the glasses refuse')));
|
||||
const failed = describeImageUpdate({
|
||||
sentId: 2, sentName: "", raw: "AAAA", target: undefined,
|
||||
prepared: prepared({ result: 4, format: null, reason: "imageData is not an array of integers" }), shown: false, result: 4,
|
||||
});
|
||||
assert.match(failed[0], /payload=string\(4 chars\) result=4 not shown$/);
|
||||
assert.equal(failed[1], " imageData is not an array of integers");
|
||||
});
|
||||
@@ -0,0 +1,61 @@
|
||||
// The Even phone app's checks before it sends a page or text upgrade to the
|
||||
// glasses (app/apps/evenhub/payload-validation.ts).
|
||||
const test = require("node:test");
|
||||
const assert = require("node:assert/strict");
|
||||
|
||||
const { stockPayloadError } = require("../.test-build/app/apps/evenhub/payload-validation.js");
|
||||
|
||||
// What SDK 0.0.16 sends for a small page (captured with a stub bridge).
|
||||
const sdkPage = () => ({
|
||||
containerTotalNum: 2,
|
||||
textObject: [{ containerID: 1, containerName: "t", xPosition: 0, yPosition: 0, width: 200, height: 100, content: "hi", isEventCapture: 1, borderWidth: 2 }],
|
||||
imageObject: [{ containerID: 2, containerName: "i", xPosition: 0, yPosition: 0, width: 40, height: 40 }],
|
||||
listObject: [{ containerID: 3, containerName: "l", itemContainer: { itemCount: 2, itemName: ["a", "b"], isItemSelectBorderEn: 1 } }],
|
||||
menuObject: { menuItems: [{ itemName: "Pause", itemID: 1 }] },
|
||||
});
|
||||
|
||||
test("SDK-shaped payloads pass", () => {
|
||||
assert.equal(stockPayloadError("create", sdkPage()), null);
|
||||
assert.equal(stockPayloadError("rebuild", sdkPage()), null);
|
||||
assert.equal(stockPayloadError("textUpgrade", { containerID: 1, containerName: "t", contentOffset: 2, contentLength: 3, content: "abc" }), null);
|
||||
});
|
||||
|
||||
test("unknown keys fail, numeric tag keys pass", () => {
|
||||
const page = sdkPage();
|
||||
page.textObject[0].Container_ID = 1;
|
||||
assert.match(stockPayloadError("create", page), /unknown key textObject\[0\]\.Container_ID/);
|
||||
assert.match(stockPayloadError("rebuild", { ...sdkPage(), widgetId: 1 }), /unknown key widgetId/);
|
||||
assert.equal(stockPayloadError("create", { ...sdkPage(), 7: 1 }), null);
|
||||
});
|
||||
|
||||
test("numeric fields take integers or numeric strings only", () => {
|
||||
const withField = (value) => {
|
||||
const page = sdkPage();
|
||||
page.textObject[0].xPosition = value;
|
||||
return stockPayloadError("create", page);
|
||||
};
|
||||
assert.equal(withField(-10), null, "negative values wrap rather than fail");
|
||||
assert.equal(withField("12"), null);
|
||||
assert.match(withField(10.5), /must be an integer/);
|
||||
assert.match(withField(true), /must be an integer/);
|
||||
assert.match(withField(null), /is null/);
|
||||
assert.match(withField("left"), /must be an integer/);
|
||||
});
|
||||
|
||||
test("string and repeated fields are type-checked", () => {
|
||||
const page = sdkPage();
|
||||
page.textObject[0].content = 5;
|
||||
assert.match(stockPayloadError("create", page), /content must be a string/);
|
||||
const list = sdkPage();
|
||||
list.listObject[0].itemContainer.itemName = "a";
|
||||
assert.match(stockPayloadError("create", list), /itemName must be an array/);
|
||||
});
|
||||
|
||||
test("textColor must be an integer 0..4 wherever it appears", () => {
|
||||
const page = sdkPage();
|
||||
page.textObject[0].textColor = 4;
|
||||
assert.equal(stockPayloadError("create", page), null);
|
||||
page.textObject[0].textColor = 15;
|
||||
assert.match(stockPayloadError("create", page), /textColor must be an integer from 0 to 4/);
|
||||
assert.match(stockPayloadError("textUpgrade", { containerID: 1, content: "x", textColor: "3" }), /textColor/);
|
||||
});
|
||||
@@ -0,0 +1,161 @@
|
||||
// EvenHubSession behaviors that follow stock (the Even phone app plus
|
||||
// firmware 2.2.9.22, as decompiled and run in the firmware emulator): text
|
||||
// scrolling and its boundary events, text upgrades, image routing, and what a
|
||||
// page the firmware can't build does.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const vm = require('node:vm');
|
||||
const { loader } = require('./helpers/load-typescript.cjs');
|
||||
|
||||
// A face with 10px characters and 27px lines, wrapping only at '\n'.
|
||||
const face = {
|
||||
lineHeight: 27,
|
||||
measureLine: text => text.length * 10,
|
||||
wrap: text => text.split('\n'),
|
||||
drawText() {},
|
||||
drawTextWrapped() {},
|
||||
};
|
||||
|
||||
function harness() {
|
||||
const timers = [];
|
||||
const load = loader({ global: { isIOS: true }, setTimeout: fn => { timers.push(fn); return timers.length; }, clearTimeout() {}, Promise }, {
|
||||
'@nativescript/core': { ApplicationSettings: { getString: (_k, d) => d, setString() {} } },
|
||||
'upng-js': require('upng-js'),
|
||||
'../../graphics/evenhub-font': { EvenHubFont: { get: () => face } },
|
||||
'./fonts': { containerFace: () => face, availableFontFamilies: () => [], measureContainerText: () => ({ width: 0, lineHeight: 27 }) },
|
||||
'../../ui/dashboard-settings': {}, '../../ui/sound-effects': {}, './api-key-dialog': {},
|
||||
'./mic-router': { evenHubMicRouter: {} }, './imu-router': { evenHubImuRouter: {} },
|
||||
'./compass-router': { evenHubCompassRouter: {} }, '../../assistant/tool-registry': {},
|
||||
'../../native/location': {}, '../../native/location-tracker': {}, '../../native/location-permissions': {},
|
||||
'../../native/image-rgba': { decodeImageRgba: () => null },
|
||||
});
|
||||
const api = load('app/apps/evenhub/session.ts');
|
||||
const session = new api.EvenHubSession({ name: 'Probe', packageId: 'test.stock', permissions: [] }, '/test/dist', () => {}, '');
|
||||
let windowClosed = false;
|
||||
session.attachWindow({ requestRender() {}, windowId: 'probe', closeWindow: () => { windowClosed = true; } });
|
||||
const web = vm.createContext({ Promise, Map, Date, console });
|
||||
web.window = web;
|
||||
web.__faceclawEvenHub = { postMessage: (name, args, id) => session.handleBridgeCall(name, args, id) };
|
||||
session.attachWebView({ evaluateJs: script => vm.runInContext(script, web), destroy() {} });
|
||||
vm.runInContext(api.EVENHUB_BRIDGE_INJECT_SCRIPT, web);
|
||||
const events = [];
|
||||
web._listenEvenAppMessage = value => {
|
||||
const message = typeof value === 'string' ? JSON.parse(value) : value;
|
||||
if (message.method === 'evenHubEvent') events.push(JSON.parse(JSON.stringify(message.data)));
|
||||
};
|
||||
const call = (method, data = {}) => web.flutter_inappwebview.callHandler('evenAppMessage', JSON.stringify({ method, data }));
|
||||
const runTimers = () => { for (const fn of timers.splice(0)) fn(); };
|
||||
return { session, call, events, runTimers, windowClosed: () => windowClosed };
|
||||
}
|
||||
|
||||
const lines = n => Array.from({ length: n }, (_, i) => `line ${i}`).join('\n');
|
||||
const textPage = (content, extra = {}) => ({
|
||||
containerTotalNum: 1,
|
||||
textObject: [{ containerID: 1, containerName: 'body', xPosition: 0, yPosition: 0, width: 300, height: 100, content, isEventCapture: 1, ...extra }],
|
||||
});
|
||||
const swipe = (h, direction) => h.session.handleGesture({ type: direction === 'down' ? 'scroll-down' : 'scroll-up' });
|
||||
|
||||
test('an overflowing capture text container scrolls itself and reports only at its ends', async () => {
|
||||
const h = harness();
|
||||
// 6 lines = 162px in a 100px window: 62px to scroll, three 28px swipes.
|
||||
assert.equal(await h.call('createStartUpPageContainer', textPage(lines(6))), 0);
|
||||
h.events.length = 0;
|
||||
swipe(h, 'down'); swipe(h, 'down'); swipe(h, 'down');
|
||||
assert.deepEqual(h.events, [], 'no events while scrolling, nor for the swipe that reaches the end');
|
||||
swipe(h, 'down');
|
||||
assert.deepEqual(h.events, [{ type: 'textEvent', jsonData: { containerID: 1, containerName: 'body', eventType: 2 } }]);
|
||||
h.events.length = 0;
|
||||
swipe(h, 'up'); swipe(h, 'up'); swipe(h, 'up');
|
||||
assert.deepEqual(h.events, []);
|
||||
swipe(h, 'up');
|
||||
assert.deepEqual(h.events, [{ type: 'textEvent', jsonData: { containerID: 1, containerName: 'body', eventType: 1 } }]);
|
||||
});
|
||||
|
||||
test('text that fits reports every swipe as reaching an end', async () => {
|
||||
const h = harness();
|
||||
await h.call('createStartUpPageContainer', textPage('short'));
|
||||
h.events.length = 0;
|
||||
swipe(h, 'down'); swipe(h, 'down');
|
||||
assert.equal(h.events.filter(e => e.type === 'textEvent' && e.jsonData.eventType === 2).length, 2);
|
||||
});
|
||||
|
||||
test('text upgrades replace the whole text by id, ignore offsets, and keep old text when emptied', async () => {
|
||||
const h = harness();
|
||||
await h.call('createStartUpPageContainer', textPage('Hello world'));
|
||||
const body = () => h.session.page.containers[0];
|
||||
assert.equal(await h.call('textContainerUpgrade', { containerID: 1, containerName: 'other name', contentOffset: 3, contentLength: 2, content: 'XY' }), true);
|
||||
assert.equal(body().content, 'XY');
|
||||
assert.equal(await h.call('textContainerUpgrade', { containerID: 1, content: '' }), true);
|
||||
assert.equal(body().content, 'XY', 'an empty upgrade leaves the old text showing');
|
||||
assert.equal(await h.call('textContainerUpgrade', { containerID: 9, content: 'nope' }), false);
|
||||
assert.equal(await h.call('textContainerUpgrade', { containerID: 1, content: 'x', junk: 1 }), false, 'unknown keys are refused');
|
||||
});
|
||||
|
||||
test('an upgrade scrolls the text back to the top', async () => {
|
||||
const h = harness();
|
||||
await h.call('createStartUpPageContainer', textPage(lines(6)));
|
||||
swipe(h, 'down');
|
||||
assert.equal(h.session.page.containers[0].scrollY, 28);
|
||||
await h.call('textContainerUpgrade', { containerID: 1, content: lines(7) });
|
||||
assert.equal(h.session.page.containers[0].scrollY, 0);
|
||||
});
|
||||
|
||||
test('image updates need a page, an image at that id, and a usable payload', async () => {
|
||||
const h = harness();
|
||||
const raw = new Array(400).fill(0);
|
||||
assert.equal(await h.call('updateImageRawData', { containerID: 2, imageData: raw, compressMode: 2 }), 4, 'no page yet');
|
||||
await h.call('createStartUpPageContainer', {
|
||||
containerTotalNum: 3,
|
||||
textObject: [{ containerID: 1, containerName: 'body', width: 300, height: 100, content: 'x', isEventCapture: 1 },
|
||||
{ containerID: 3, containerName: 'label', width: 50, height: 30, content: 'y' }],
|
||||
imageObject: [{ containerID: 2, containerName: 'icon', width: 20, height: 20 }, { containerID: 3, containerName: 'shadowed', width: 20, height: 20 }],
|
||||
});
|
||||
assert.equal(await h.call('updateImageRawData', { containerID: 2, imageData: raw, compressMode: 2 }), 0);
|
||||
assert.equal(await h.call('updateImageRawData', { containerID: 2, imageData: 'AAAA', compressMode: 2 }), 4, 'base64 is refused');
|
||||
assert.equal(await h.call('updateImageRawData', { containerID: 3, imageData: raw, compressMode: 2 }), 4, 'id 3 resolves to the text container');
|
||||
// With no image at that id the Even app has no size for raw pixels: 0x0 is out of range.
|
||||
assert.equal(await h.call('updateImageRawData', { containerID: 7, imageData: raw, compressMode: 2 }), 2);
|
||||
});
|
||||
|
||||
test('a page the firmware cannot build fails create, and a failed rebuild closes the app', async () => {
|
||||
const h = harness();
|
||||
const tinyImage = { ...textPage('x'), imageObject: [{ containerID: 2, containerName: 'dot', width: 10, height: 10 }] };
|
||||
assert.equal(await h.call('createStartUpPageContainer', tinyImage), 1);
|
||||
assert.equal(await h.call('rebuildPageContainer', textPage('x')), false, 'nothing to rebuild before a page exists');
|
||||
assert.equal(await h.call('createStartUpPageContainer', textPage('x')), 0);
|
||||
h.events.length = 0;
|
||||
assert.equal(await h.call('rebuildPageContainer', tinyImage), false);
|
||||
assert.equal(h.session.page.containers.length, 0);
|
||||
assert.ok(h.events.some(e => e.type === 'sysEvent' && e.jsonData.eventType === 6), 'ABNORMAL_EXIT');
|
||||
h.runTimers();
|
||||
assert.equal(h.windowClosed(), true);
|
||||
});
|
||||
|
||||
test('the Even app refuses malformed pages before they reach the glasses', async () => {
|
||||
const h = harness();
|
||||
assert.equal(await h.call('createStartUpPageContainer', textPage('x', { isEventCapture: true })), 1);
|
||||
assert.equal(await h.call('createStartUpPageContainer', textPage('x', { textColor: 7 })), 1);
|
||||
assert.equal(await h.call('createStartUpPageContainer', textPage('x')), 0);
|
||||
assert.equal(await h.call('rebuildPageContainer', { ...textPage('y'), Container_Total_Num: 1 }), false);
|
||||
assert.equal(h.session.page.containers[0].content, 'x', 'a refused rebuild leaves the page alone');
|
||||
});
|
||||
|
||||
test('borders use the colour index, overflowing text gets a scrollbar, and images cover text', async () => {
|
||||
const h = harness();
|
||||
// 300x100 with a 2px border of colour 3; 6 lines overflow the 96px window by 66px.
|
||||
await h.call('createStartUpPageContainer', {
|
||||
containerTotalNum: 2,
|
||||
textObject: [{ containerID: 1, containerName: 'body', xPosition: 0, yPosition: 0, width: 300, height: 100, content: lines(6), isEventCapture: 1, borderWidth: 2, borderColor: 3 }],
|
||||
imageObject: [{ containerID: 2, containerName: 'icon', xPosition: 0, yPosition: 40, width: 20, height: 20 }],
|
||||
});
|
||||
await h.call('updateImageRawData', { containerID: 2, imageData: new Array(400).fill(0), compressMode: 2 });
|
||||
const image = h.session.paint({ width: 576, height: 288 }, true);
|
||||
const at = (x, y) => image.pixels[y * 576 + x];
|
||||
assert.equal(at(150, 0), 3 * 17, 'border grey');
|
||||
assert.equal(at(0, 50), 0, 'the black image covers the border under it');
|
||||
// Track 6..94 (88px); length floor(88 * 100 / 166) = 53; x 290..293.
|
||||
assert.deepEqual([at(290, 7), at(291, 7), at(293, 7), at(289, 7), at(294, 7)], [187, 187, 187, 0, 0]);
|
||||
assert.deepEqual([at(290, 6), at(291, 6), at(292, 6), at(293, 6)], [0, 187, 187, 0], 'chamfered top row');
|
||||
assert.equal(at(291, 58), 187);
|
||||
assert.equal(at(291, 59), 0, 'bar ends after 53 rows');
|
||||
});
|
||||
@@ -0,0 +1,81 @@
|
||||
// Stock container-model rules the EvenHub emulation follows: stacking order,
|
||||
// which container captures input, id resolution, firmware clamps and border
|
||||
// greys. Source: the evenRealities-openCFW reconstruction of firmware 2.2.6.10
|
||||
// (evenhub_ui_containers.c, evenhub_ui_page.c, common_text/list_container.c).
|
||||
const test = require("node:test");
|
||||
const assert = require("node:assert/strict");
|
||||
|
||||
const {
|
||||
borderGrey,
|
||||
clampToStockLimits,
|
||||
containerById,
|
||||
eventCaptureContainer,
|
||||
paintOrder,
|
||||
parsePage,
|
||||
} = require("../.test-build/app/apps/evenhub/containers.js");
|
||||
|
||||
const names = (containers) => containers.map((c) => c.name);
|
||||
|
||||
test("without zOrderIndex containers stack lists, then texts, then images", () => {
|
||||
const page = parsePage({
|
||||
imageObject: [{ containerID: 1, containerName: "img" }],
|
||||
textObject: [{ containerID: 2, containerName: "txt" }],
|
||||
listObject: [{ containerID: 3, containerName: "lst" }],
|
||||
});
|
||||
assert.deepEqual(names(paintOrder(page.containers)), ["lst", "txt", "img"]);
|
||||
});
|
||||
|
||||
test("zOrderIndex sorts only when every container has one", () => {
|
||||
const all = parsePage({
|
||||
textObject: [{ containerID: 1, containerName: "body", zOrderIndex: 2 }],
|
||||
imageObject: [{ containerID: 2, containerName: "icon", zOrderIndex: 1 }],
|
||||
});
|
||||
assert.deepEqual(names(paintOrder(all.containers)), ["icon", "body"]);
|
||||
const some = parsePage({
|
||||
textObject: [{ containerID: 1, containerName: "body", zOrderIndex: 2 }],
|
||||
imageObject: [{ containerID: 2, containerName: "icon" }],
|
||||
});
|
||||
assert.deepEqual(names(paintOrder(some.containers)), ["body", "icon"]);
|
||||
});
|
||||
|
||||
test("the first capture container in stacking order owns input", () => {
|
||||
const page = parsePage({
|
||||
textObject: [
|
||||
{ containerID: 1, containerName: "a", isEventCapture: 1, zOrderIndex: 5 },
|
||||
{ containerID: 2, containerName: "b", isEventCapture: 1, zOrderIndex: 3 },
|
||||
],
|
||||
});
|
||||
assert.equal(eventCaptureContainer(page).name, "b");
|
||||
});
|
||||
|
||||
test("an id resolves to its first container in stacking order, whatever the kind", () => {
|
||||
const page = parsePage({
|
||||
textObject: [{ containerID: 7, containerName: "label" }],
|
||||
imageObject: [{ containerID: 7, containerName: "icon" }],
|
||||
});
|
||||
assert.equal(containerById(page, 7).kind, "text");
|
||||
assert.equal(containerById(page, 8), undefined);
|
||||
});
|
||||
|
||||
test("stock clamps text and list geometry but leaves image sizes alone", () => {
|
||||
const page = parsePage({
|
||||
textObject: [{ containerID: 1, containerName: "t", xPosition: 900, yPosition: 400, width: 800, height: 400, borderColor: 40, borderRadius: 30, paddingLength: 50 }],
|
||||
listObject: [{ containerID: 2, containerName: "l", itemContainer: { itemName: Array.from({ length: 25 }, (_, i) => `item ${i}`) } }],
|
||||
imageObject: [{ containerID: 3, containerName: "i", xPosition: 600, width: 400, height: 200 }],
|
||||
});
|
||||
clampToStockLimits(page);
|
||||
const [list, text, image] = page.containers;
|
||||
assert.deepEqual([text.x, text.y, text.width, text.height], [576, 288, 576, 288]);
|
||||
assert.deepEqual([text.borderColor, text.borderRadius, text.paddingLength], [16, 10, 32]);
|
||||
assert.equal(list.itemNames.length, 20);
|
||||
assert.deepEqual([image.x, image.width, image.height], [576, 400, 200]);
|
||||
});
|
||||
|
||||
test("border color indices are 16 grey steps, with 16 meaning white", () => {
|
||||
assert.equal(borderGrey(0), 0);
|
||||
assert.equal(borderGrey(3), 0x33);
|
||||
assert.equal(borderGrey(15), 0xff);
|
||||
assert.equal(borderGrey(16), 0xff);
|
||||
const page = parsePage({ textObject: [{ containerID: 1, containerName: "t", borderWidth: 2 }] });
|
||||
assert.equal(page.containers[0].borderColor, 0, "an omitted borderColor is the protobuf default, black");
|
||||
});
|
||||
@@ -87,7 +87,8 @@ function sessionHarness(overrides = {}, playBuzzer = () => {}, { packageId = 'te
|
||||
'../../ui/dashboard-settings': {}, '../../ui/sound-effects': {}, './api-key-dialog': {},
|
||||
'./mic-router': { evenHubMicRouter: {} }, './imu-router': { evenHubImuRouter: {} },
|
||||
'./compass-router': { evenHubCompassRouter: {} }, '../../assistant/tool-registry': {},
|
||||
'../../native/location': {}, '../../native/location-tracker': {}, '../../native/location-permissions': {}, ...overrides,
|
||||
'../../native/location': {}, '../../native/location-tracker': {}, '../../native/location-permissions': {},
|
||||
'../../native/image-rgba': { decodeImageRgba: () => null }, ...overrides,
|
||||
});
|
||||
const api = load('app/apps/evenhub/session.ts');
|
||||
const session = new api.EvenHubSession({ name: 'Probe', packageId, permissions: [] }, '/test/dist', line => logs.push(line), '', playBuzzer);
|
||||
@@ -105,10 +106,12 @@ function sessionHarness(overrides = {}, playBuzzer = () => {}, { packageId = 'te
|
||||
test('injected EvenHub RPC creates, updates and composites an image page with no Android globals', async () => {
|
||||
const h = sessionHarness();
|
||||
assert.equal(await h.call('createStartUpPageContainer', { containerTotalNum: 1,
|
||||
imageObject: [{ containerID: 1, containerName: 'board', xPosition: 0, yPosition: 0, width: 2, height: 2 }] }), 0);
|
||||
assert.equal(await h.call('updateImageRawData', { containerID: 1, containerName: 'board', imageData: [0, 80, 160, 255] }), 0);
|
||||
imageObject: [{ containerID: 1, containerName: 'board', xPosition: 0, yPosition: 0, width: 20, height: 20 }] }), 0);
|
||||
// Raw 8-bit grey as the SDK sends it (compressMode 2), quantized to 4-bit levels as the Even app does.
|
||||
const raw = new Array(400).fill(0); raw.splice(0, 4, 0, 80, 160, 255);
|
||||
assert.equal(await h.call('updateImageRawData', { containerID: 1, containerName: 'board', imageData: raw, compressMode: 2 }), 0);
|
||||
const painted = h.session.paint({ width: 576, height: 288 }, true);
|
||||
assert.deepEqual([painted.pixels[0], painted.pixels[1], painted.pixels[576], painted.pixels[577]], [0, 80, 160, 255]);
|
||||
assert.deepEqual(Array.from(painted.pixels.slice(0, 4)), [0, 5 * 17, 9 * 17, 255]);
|
||||
assert.equal(await h.call('setLocalStorage', { key: 'score', value: '42' }), true);
|
||||
assert.equal(await h.call('getLocalStorage', { key: 'score' }), '42');
|
||||
const events = [];
|
||||
|
||||
+22
-32
@@ -1,45 +1,35 @@
|
||||
// EvenHub text-container wrapping (app/graphics/lvgl-wrap.ts): pretext's
|
||||
// breaks, except that leading spaces survive at the start of the text and
|
||||
// after '\n' — apps indent with them to clear icons placed beside the text.
|
||||
// EvenHub text-container wrapping (app/graphics/lvgl-wrap.ts), against what
|
||||
// stock firmware 2.2.9.22 drew in the g2-firmware-emulator: spaces are kept
|
||||
// everywhere, including ones that overflow onto a soft-wrapped line.
|
||||
const test = require("node:test");
|
||||
const assert = require("node:assert/strict");
|
||||
|
||||
const { wrapLvglText } = require("../.test-build/app/graphics/lvgl-wrap.js");
|
||||
|
||||
// Spaces are 4px like the stock 20px font; everything else 10px.
|
||||
const fixed = (cp) => (cp === 32 ? 4 : 10);
|
||||
// The stock 20px font's advances for these: H 12px, E 11px, space 5px.
|
||||
const ADVANCES = { H: 12, E: 11, " ": 5 };
|
||||
const advance = (cp) => ADVANCES[String.fromCodePoint(cp)] ?? 10;
|
||||
|
||||
test("indentation after a newline is kept (Iris Pro's icon-clearing indent)", () => {
|
||||
const content = " \n R E C O R D\n Conversation";
|
||||
const lines = wrapLvglText(content, 248, fixed);
|
||||
assert.deepEqual(lines, [" ", " R E C O R D", " Conversation"]);
|
||||
test("indentation after a newline and at the start is kept (Iris Pro's icon-clearing indent)", () => {
|
||||
assert.deepEqual(wrapLvglText(" \n R E C O R D", 248, advance), [" ", " R E C O R D"]);
|
||||
assert.deepEqual(wrapLvglText("AB\n CD", 248, advance), ["AB", " CD"]);
|
||||
assert.deepEqual(wrapLvglText(" EF", 248, advance), [" EF"]);
|
||||
});
|
||||
|
||||
test("indentation at the very start of the text is kept", () => {
|
||||
assert.deepEqual(wrapLvglText(" 55°", 248, fixed), [" 55°"]);
|
||||
test("spaces that overflow a line start the next one (emulator Q3)", () => {
|
||||
const text = "HHHHHHHH EEEE";
|
||||
assert.deepEqual(wrapLvglText(text, 100, advance), ["HHHHHHHH", " EEEE"]);
|
||||
assert.deepEqual(wrapLvglText(text, 110, advance), ["HHHHHHHH ", " EEEE"]);
|
||||
assert.deepEqual(wrapLvglText(text, 120, advance), ["HHHHHHHH ", "EEEE"]);
|
||||
});
|
||||
|
||||
test("a soft-wrapped continuation line drops its leading spaces", () => {
|
||||
// "aaaa" (40px) fits; the space after it overflows at width 40 and is
|
||||
// discarded, and the next space would lead the continuation line.
|
||||
assert.deepEqual(wrapLvglText("aaaa bbbb", 40, fixed), ["aaaa", "bbbb"]);
|
||||
// Wrapping at an earlier break opportunity.
|
||||
assert.deepEqual(wrapLvglText("aa bb cc", 54, fixed), ["aa bb", "cc"]);
|
||||
test("a word that overflows wraps after the last space or hyphen", () => {
|
||||
assert.deepEqual(wrapLvglText("HH EEEEEEEE", 100, advance), ["HH ", "EEEEEEEE"]);
|
||||
assert.deepEqual(wrapLvglText("HH-EEEEEEEE", 100, advance), ["HH-", "EEEEEEEE"]);
|
||||
});
|
||||
|
||||
test("unindented text breaks exactly where pretext's measureTextWrap says", async () => {
|
||||
const pretext = await import("@evenrealities/pretext");
|
||||
const advance = (a, b) => (b ? pretext.getTextWidth(String.fromCodePoint(a, b)) - pretext.getTextWidth(String.fromCodePoint(b)) : pretext.getTextWidth(String.fromCodePoint(a)));
|
||||
const samples = [
|
||||
"Market moving from feature flex to everyday integration",
|
||||
"No one owns human, calm intelligence\nConversation likely becomes next differentiation layer",
|
||||
"Supercalifragilisticexpialidocious-and-then-some words that will not fit on one line at all",
|
||||
"short\n\nlines\nhere",
|
||||
];
|
||||
for (const text of samples) {
|
||||
for (let width = 40; width <= 560; width += 7) {
|
||||
const ours = wrapLvglText(text, width, advance);
|
||||
assert.equal(ours.length, pretext.measureTextWrap(text, width).lineCount, `${JSON.stringify(text)} at ${width}px`);
|
||||
}
|
||||
}
|
||||
test("a run with no break opportunity breaks before the overflowing character", () => {
|
||||
assert.deepEqual(wrapLvglText("HHHHHHHHHH", 50, advance), ["HHHH", "HHHH", "HH"]);
|
||||
// A character wider than the line still gets one to itself.
|
||||
assert.deepEqual(wrapLvglText("HH", 5, advance), ["H", "H"]);
|
||||
});
|
||||
@@ -57,6 +57,8 @@
|
||||
"../app/apps/microphones/name-guess.ts",
|
||||
"../app/apps/evenhub/containers.ts",
|
||||
"../app/apps/evenhub/layout-debug.ts",
|
||||
"../app/apps/evenhub/image-pipeline.ts",
|
||||
"../app/apps/evenhub/payload-validation.ts",
|
||||
"../app/apps/evenhub/list-menu.ts",
|
||||
"../app/apps/evenhub/device-status.ts",
|
||||
"../app/apps/evenhub/font-spec.ts",
|
||||
|
||||
Reference in new issue
Block a user