[verified] merge upstream c162c8e6 into all-features

This commit is contained in:
MasterControl committed 2026-11-14 23:24:08 +00:00
commit 5790e98d27
176 files changed
+5311 -2307

No files matched your search

+38 -2
View File
@@ -4,6 +4,7 @@ const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ts = require('typescript');
const { bordered, unbordered, edged } = require('./helpers/viewport.cjs');
function load(file, deps, globals = {}) {
const exports = {};
@@ -256,6 +257,7 @@ function shellEnv({ wakeAction = 'voice-input', skipConfirmation = false } = {})
const timings = { spanCurrent: (_, fn) => fn(), span: (_, __, fn) => fn(), spanAsync: (_, __, fn) => fn(),
startFrame: () => 0, annotateFrame() {}, finishFrame() {}, runWithFrame: (_, fn) => fn() };
const layers = load('app/ui/layers.ts', {
'./viewport': require('../.test-build/app/ui/viewport.js'),
'../graphics/image': images, '../graphics/plane': { dimPlanes: (planes) => planes },
'../native/frame-timings': timings, './gestures': gestures,
'../graphics/screen-size': { screenWidth: () => 640, screenHeight: () => 480 },
@@ -299,7 +301,7 @@ function shellEnv({ wakeAction = 'voice-input', skipConfirmation = false } = {})
'../../graphics/image': images, '../../native/frame-timings': timings,
'../../util/render-freshness': { beginRenderPass() {}, endRenderPass: () => false },
'../layers': layers, '../window-menu': { WindowMenuLayer: Menu },
'./chrome-layer': { windowIcon: () => () => null }, './geometry': { appViewportSize: () => ({ width: 576, height: 260 }), setAppImmersive: () => false },
'./chrome-layer': { windowIcon: () => () => null }, './geometry': { appViewport: () => ({ width: 576, height: 260 }), setAppImmersive: () => false },
'./shell': { shell },
});
const input = [], menus = [];
@@ -404,7 +406,9 @@ function chatLayerEnv() {
});
createAiChatWindow({ actions: {}, setSurfaceVisible() {}, onClosed() {} });
const layer = windowOptions.baseLayer;
return { ...env, layer, paint: (width = 576, height = 260) => layer.paint({ stack: { getBaseSize: () => ({ width, height }) } }) };
// A framed window (8px of padding all round) unless a viewport says otherwise.
return { ...env, layer, paint: (width = 576, height = 260, viewport = bordered(width, height)) =>
layer.paint({ stack: { getBaseSize: () => viewport } }) };
}
test('scrollback stays anchored during streaming, follows at the bottom and resets on session switch', () => {
@@ -446,3 +450,35 @@ test('chat paints at both window heights with pending speech pinned beneath hist
}
}
});
test('chat keeps inside the padding of the edges a border runs along, and uses the room where there is none', () => {
const env = chatLayerEnv();
const session = env.store.ensureSession();
for (let i = 0; i < 30; i++) session.transcript.push({ role: i % 2 ? 'assistant' : 'user', text: `Message ${i}: sample conversation text.` });
// The rows and columns holding any ink, text included.
const inkBounds = (image) => {
const baked = image.withDrawsBaked();
const bounds = { left: Infinity, top: Infinity, right: -1, bottom: -1 };
for (let y = 0; y < baked.height; y++) for (let x = 0; x < baked.width; x++) {
if (!baked.getPixel(x, y)) continue;
bounds.left = Math.min(bounds.left, x); bounds.right = Math.max(bounds.right, x);
bounds.top = Math.min(bounds.top, y); bounds.bottom = Math.max(bounds.bottom, y);
}
return bounds;
};
for (const viewport of [
bordered(576, 260), unbordered(576, 260), edged(576, 260, 'top', 'left'), edged(576, 452, 'bottom', 'right'),
bordered(476, 155), unbordered(476, 155), edged(640, 480, 'bottom'),
]) {
const { width, height, padding } = viewport;
const where = JSON.stringify(viewport);
const ink = inkBounds(env.paint(width, height, viewport));
assert.ok(env.layer.maxFirstLine > 0, where);
// The footer's rule starts right at the left padding and the scrollbar hugs the right.
assert.equal(ink.left, padding.left, where);
assert.equal(ink.right, width - padding.right - 1, where);
// The title's line starts at the top padding and the footer's last line ends at the bottom.
assert.ok(ink.top >= padding.top && ink.top < padding.top + 12, where);
assert.ok(ink.bottom < height - padding.bottom && ink.bottom >= height - padding.bottom - 12, where);
}
});
+231 -29
View File
@@ -4,6 +4,7 @@ const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ts = require('typescript');
const { bordered, unbordered, edged, sameViewport } = require('./helpers/viewport.cjs');
const read = (file) => fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
const js = (source) => ts.transpileModule(source, {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
@@ -14,12 +15,13 @@ function geometry(screen = { width: 640, height: 480 }) {
const settings = Object.fromEntries(Object.entries({
displayLayoutSetting: 'band-middle', navigateDisplayLayoutSetting: 'global', terminalDisplayLayoutSetting: 'default',
appSwitcherPositionSetting: 'left', uiDepthSetting: '0', statusBarPositionSetting: 'top',
statusBarVisibilitySetting: 'always', windowBorderSetting: true,
statusBarVisibilitySetting: 'always', windowBorderSetting: 'all',
}).map(([name, value]) => [name, { value, get() { return this.value; } }]));
const fullscreen = new Map();
settings.appFullscreenSetting = id => ({ get: () => fullscreen.get(id) ?? false, set: value => fullscreen.set(id, value) });
const context = { exports: {}, require: (name) => {
if (name === '../../graphics/screen-size') return { screenWidth: () => screen.width, screenHeight: () => screen.height };
if (name === '../viewport') return require('../.test-build/app/ui/viewport.js');
assert.equal(name, '../dashboard-settings');
return settings;
} };
@@ -120,18 +122,22 @@ test('Full Screen widens Tall windows to the panel and drops depth, beside a bot
test('all display modes and layouts stay within the display and align content below the bar', () => {
const g = geometry();
g.settings.uiDepthSetting.value = '48';
const combos = [['left', 'top'], ['right', 'top'], ['bottom', 'top'], ['bottom', 'bottom'], ['left', 'bottom']];
// A side strip has no choice of border: the setting doesn't reach it.
const combos = [['left', 'top'], ['right', 'top'], ['left', 'bottom'], ['right', 'top', 'always', 'none']];
for (const statusBar of ['top', 'bottom']) {
for (const visibility of ['always', 'switcher']) {
for (const border of [true, false]) combos.push(['popup', statusBar, visibility, border]);
for (const border of ['all', 'status', 'none']) {
combos.push(['bottom', statusBar, 'always', border]);
for (const visibility of ['always', 'switcher']) combos.push(['popup', statusBar, visibility, border]);
}
}
for (const [switcher, statusBar, visibility = 'always', border = true] of combos) {
for (const [switcher, statusBar, visibility = 'always', border = 'all'] of combos) {
g.settings.appSwitcherPositionSetting.value = switcher;
g.settings.statusBarPositionSetting.value = statusBar;
g.settings.statusBarVisibilitySetting.value = visibility;
g.settings.windowBorderSetting.value = border;
const side = switcher === 'left' || switcher === 'right';
// Only no border at all drops the line between a status bar and the window.
assert.equal(g.statusBarDivider(), side || border !== 'none');
for (const globalMode of LAYOUTS) {
g.settings.displayLayoutSetting.value = globalMode;
for (const appId of ['navigate', 'terminal']) {
@@ -148,15 +154,18 @@ test('all display modes and layouts stay within the display and align content be
if (switcher === 'popup') {
// Each edge has the status bar's rows (unless it only
// overlays), else the frame's side, else nothing.
assert.equal(g.windowFramed(appId), border && !wide);
assert.equal(g.windowFramed(appId), border === 'all' && !wide);
const edge = (side) => visibility === 'always' && statusBar === side ? g.TOP_BAR_HEIGHT : g.windowFramed(appId) ? 1 : 0;
assert.deepEqual([header, footer], [edge('top'), edge('bottom')]);
// The status bar's rows lie within the band, at its edge.
const top = g.windowTop(heightMode, appId), band = g.windowBandHeight(heightMode, appId);
assert.equal(g.statusBarTop(heightMode, appId), statusBar === 'top' ? top : top + band - g.TOP_BAR_HEIGHT);
} else {
assert.equal(g.windowFramed(appId), switcher === 'bottom' && !wide);
assert.equal(g.windowFramed(appId), switcher === 'bottom' && border === 'all' && !wide);
assert.deepEqual([header, footer], [!g.statusInSwitcherRow(appId) ? g.TOP_BAR_HEIGHT : g.windowFramed(appId) ? 1 : 0, 0]);
// A bottom row's top edge is a line with every border, or as
// the status line where the status bar is in the row.
if (switcher === 'bottom') assert.equal(g.switcherRowDivider(appId), border === 'all' || (border === 'status' && statusBar === 'bottom'));
}
assert.equal(rect.y, g.windowTop(heightMode, appId) + header);
assert.equal(rect.height + header + footer, g.windowBandHeight(heightMode, appId));
@@ -217,13 +226,16 @@ test('a popup app switcher centres 576-wide windows, whose edges the status bar
assert.deepEqual(g.rect('min'), { x: 32, y: 97, width: 576, height: 286 });
assert.deepEqual(g.rect('max', 'terminal'), { x: 32, y: 1, width: 576, height: 478 });
assert.equal(g.statusBarTop('min'), 356);
// Without the frame too, windows have no chrome rows at all.
g.settings.windowBorderSetting.value = false;
assert.equal(g.windowFramed(), false);
assert.deepEqual(g.rect('max', 'terminal'), { x: 32, y: 0, width: 576, height: 480 });
assert.deepEqual(g.rect('medium'), { x: 32, y: 96, width: 576, height: 288 });
// Without the frame too (just the status line, or no border), windows
// have no chrome rows at all.
for (const border of ['status', 'none']) {
g.settings.windowBorderSetting.value = border;
assert.equal(g.windowFramed(), false);
assert.deepEqual(g.rect('max', 'terminal'), { x: 32, y: 0, width: 576, height: 480 });
assert.deepEqual(g.rect('medium'), { x: 32, y: 96, width: 576, height: 288 });
}
// Full Screen: the status bar keeps its edge, but there's no room for a frame.
g.settings.windowBorderSetting.value = true;
g.settings.windowBorderSetting.value = 'all';
g.settings.statusBarVisibilitySetting.value = 'always';
g.settings.displayLayoutSetting.value = 'fullscreen';
assert.equal(g.windowFramed(), false);
@@ -357,6 +369,96 @@ test('on a RayNeo iO the chrome paints the screen\'s size, its strip and row wit
}
});
test('each window edge is labelled by whether a border line runs along it, with padding only there', () => {
const g = geometry();
// top, right, bottom, left: B = a border line right outside it, o = nothing.
const edges = (appId) => {
const e = g.windowEdges(appId);
return [e.top, e.right, e.bottom, e.left].map((kind) => (kind === 'border' ? 'B' : 'o')).join('');
};
const set = (switcher, statusBar = 'top', border = 'all', visibility = 'always') => {
g.settings.appSwitcherPositionSetting.value = switcher;
g.settings.statusBarPositionSetting.value = statusBar;
g.settings.windowBorderSetting.value = border;
g.settings.statusBarVisibilitySetting.value = visibility;
};
// A side strip: the top bar's divider and the strip's separator; the
// other side and the bottom are the screen's edge or blank. The Border
// setting doesn't reach it.
set('left');
assert.equal(edges(), 'BooB');
set('right', 'top', 'none');
assert.equal(edges(), 'BBoo');
// A bottom row: the frame all round; with only the status line, the edge
// the status bar is past; with no border, nothing.
set('bottom');
assert.equal(edges(), 'BBBB');
set('bottom', 'bottom');
assert.equal(edges(), 'BBBB');
set('bottom', 'top', 'status');
assert.equal(edges(), 'Booo');
set('bottom', 'bottom', 'status');
assert.equal(edges(), 'ooBo');
set('bottom', 'top', 'none');
assert.equal(edges(), 'oooo');
set('bottom', 'bottom', 'none');
assert.equal(edges(), 'oooo');
// A popup: the frame, or the line by a status bar with rows of its own
// (one that only overlays has none).
set('popup');
assert.equal(edges(), 'BBBB');
set('popup', 'bottom', 'status');
assert.equal(edges(), 'ooBo');
set('popup', 'top', 'status');
assert.equal(edges(), 'Booo');
set('popup', 'top', 'status', 'switcher');
assert.equal(edges(), 'oooo');
set('popup', 'top', 'all', 'switcher');
assert.equal(edges(), 'BBBB');
set('popup', 'top', 'none');
assert.equal(edges(), 'oooo');
// Full Screen has no room for the frame's sides: the status bar's divider
// and the switcher row's separator are the lines left.
g.settings.displayLayoutSetting.value = 'fullscreen';
set('bottom');
assert.equal(edges(), 'BoBo');
set('bottom', 'bottom');
assert.equal(edges(), 'ooBo');
set('bottom', 'top', 'status');
assert.equal(edges(), 'Booo');
set('popup');
assert.equal(edges(), 'Booo');
set('popup', 'bottom');
assert.equal(edges(), 'ooBo');
// An immersive window has the whole panel.
g.settings.displayLayoutSetting.value = 'band-middle';
set('bottom');
g.setAppImmersive('onboarding', true);
assert.equal(edges('onboarding'), 'oooo');
assert.equal(edges('launcher'), 'BBBB');
set('left');
assert.equal(edges('onboarding'), 'oooo');
g.setAppImmersive('onboarding', false);
// The viewport a window lays out in carries the labels and the padding
// suggested for them: 8px beside a line, none beside blank space.
const plain = (value) => JSON.parse(JSON.stringify(value));
set('left');
assert.deepEqual(plain(g.appViewport('min')), {
width: 576, height: 260,
edges: { top: 'border', right: 'offscreen', bottom: 'offscreen', left: 'border' },
padding: { top: 8, right: 0, bottom: 0, left: 8 },
});
set('bottom', 'bottom', 'none');
assert.deepEqual(plain(g.appViewport('min').padding), { top: 0, right: 0, bottom: 0, left: 0 });
set('bottom', 'bottom');
assert.deepEqual(plain(g.appViewport('min').padding), { top: 8, right: 8, bottom: 8, left: 8 });
for (const mode of ['min', 'medium', 'max']) {
const { width, height } = g.appViewport(mode, 'terminal');
assert.deepEqual({ width, height }, { ...g.appViewportSize(mode, 'terminal') });
}
});
test('the phone mirror zooms to the area the shell uses, centred at the panel\'s 4:3', () => {
const g = geometry();
const preview = (mode, appId) => {
@@ -865,9 +967,9 @@ test('a popup switcher\'s status bar can sit at the bottom, show only in the swi
g.settings.statusBarPositionSetting.value = 'bottom';
[bar] = chrome.paintParts();
assert.deepEqual([bar.y, at(bar, 300, 356), at(bar, 300, 383)], [356, 40, 1]);
// Always shown without a frame, a divider still separates bar and window.
// Always shown with only the status line, a divider still separates bar and window.
g.settings.statusBarVisibilitySetting.value = 'always';
g.settings.windowBorderSetting.value = false;
g.settings.windowBorderSetting.value = 'status';
state.focus = 'window';
const parts = chrome.paintParts();
assert.deepEqual(Array.from(parts, (p) => p.shellKey), [2]);
@@ -875,6 +977,93 @@ test('a popup switcher\'s status bar can sit at the bottom, show only in the swi
g.settings.statusBarPositionSetting.value = 'top';
[bar] = chrome.paintParts();
assert.deepEqual([bar.y, at(bar, 300, 123)], [96, 40]);
// With no border the bar is all there is, at either edge.
g.settings.windowBorderSetting.value = 'none';
[bar] = chrome.paintParts();
assert.deepEqual([bar.y, at(bar, 300, 123)], [96, 1]);
g.settings.statusBarPositionSetting.value = 'bottom';
assert.deepEqual(Array.from(chrome.paintParts(), (p) => [p.shellKey, p.y, at(p, 300, 356)]), [[2, 356, 1]]);
});
test('a bottom app switcher\'s border can be just the line by the status bar, or nothing', () => {
const g = geometry();
g.settings.appSwitcherPositionSetting.value = 'bottom';
g.settings.statusBarPositionSetting.value = 'bottom';
g.settings.windowBorderSetting.value = 'status';
const { chrome, state } = chromeLayer(g, { windows: 2 });
state.selectedIndex = 1;
const frames = (parts) => parts.flatMap((p) => p.image.draws.filter((d) => d.presentation?.displayList));
const at = (p, x, y) => p.image.pixels[(y - p.y) * p.image.width + x - p.x];
// With the status bar in the row, the line is the row's top edge, straight
// across the window's width; no frame, so the content takes the header's
// row and the row's surface is no wider than the window.
assert.deepEqual(g.rect('min'), { x: 32, y: 78, width: 576, height: 288 });
let parts = chrome.paintParts();
let [row] = parts;
assert.equal(frames(parts).length, 0);
assert.deepEqual([row.x, row.y, row.image.width], [32, 366, 576]);
assert.deepEqual([at(row, 32, 366), at(row, 300, 366), at(row, 607, 366)], [40, 40, 40]);
// The first cell (the launcher's) starts at the row's end, in line with
// the window's edge, and the selection is still a tab diverting the line.
assert.deepEqual([chrome.windowIndexAt(31, 380, 2), chrome.windowIndexAt(32, 380, 2), chrome.windowIndexAt(72, 380, 2)], [null, 0, 1]);
assert.deepEqual([at(row, 71, 366), at(row, 72, 366), at(row, 90, 366), at(row, 72, 380)], [40, 150, 1, 150]);
// The launcher's own tab runs down the window's edge from the line's start.
state.selectedIndex = 0;
[row] = chrome.paintParts();
assert.deepEqual([at(row, 32, 366), at(row, 32, 380), at(row, 50, 366), at(row, 68, 366)], [150, 150, 1, 40]);
state.selectedIndex = 1;
// The flat paint has no frame either.
assert.equal(chrome.paint().draws.filter((d) => d.presentation?.displayList).length, 0);
// With the status bar on top, the line is the top bar's divider, and the
// row has none: its selection is a box, as in a second row.
g.settings.statusBarPositionSetting.value = 'top';
assert.deepEqual(g.rect('min'), { x: 32, y: 106, width: 576, height: 260 });
parts = chrome.paintParts();
let bar;
[bar, row] = parts;
assert.deepEqual([Array.from(parts, (p) => p.shellKey), frames(parts).length], [[2, 1], 0]);
assert.deepEqual([at(bar, 32, 105), at(bar, 607, 105)], [40, 40]);
assert.deepEqual([at(row, 32, 366), at(row, 300, 366)], [1, 1]);
assert.deepEqual([at(row, 90, 366), at(row, 72, 380), at(row, 90, 401)], [150, 150, 150]);
// Focused, the box fills round the icon.
state.focus = 'sidebar';
[, row] = chrome.paintParts();
assert.deepEqual([at(row, 73, 380), at(row, 90, 380)], [255, 120]);
state.focus = 'window';
// No border: neither line, wherever the status bar is.
g.settings.windowBorderSetting.value = 'none';
[bar, row] = chrome.paintParts();
assert.deepEqual([at(bar, 300, 105), at(row, 300, 366), at(row, 90, 366)], [1, 1, 150]);
g.settings.statusBarPositionSetting.value = 'bottom';
parts = chrome.paintParts();
[row] = parts;
assert.deepEqual([frames(parts).length, at(row, 32, 366), at(row, 300, 366), at(row, 90, 366)], [0, 1, 1, 150]);
assert.deepEqual(g.rect('min'), { x: 32, y: 78, width: 576, height: 288 });
assert.deepEqual([chrome.windowIndexAt(31, 380, 2), chrome.windowIndexAt(32, 380, 2)], [null, 0]);
// A Full Screen window's row starts its cells at the screen's edge.
g.settings.displayLayoutSetting.value = 'fullscreen';
chrome.paintParts();
assert.deepEqual([chrome.windowIndexAt(0, 460, 2), chrome.windowIndexAt(40, 460, 2)], [0, 1]);
g.settings.displayLayoutSetting.value = 'band-middle';
// All around, a Full Screen window has no room for a frame and keeps its
// straight lines, as beside a side strip.
g.settings.windowBorderSetting.value = 'all';
g.settings.statusBarPositionSetting.value = 'top';
g.settings.displayLayoutSetting.value = 'fullscreen';
[bar, row] = chrome.paintParts();
assert.deepEqual([at(bar, 300, 27), at(row, 0, 444), at(row, 639, 444)], [40, 40, 40]);
// Its cells keep their margin from the row's end.
assert.deepEqual([chrome.windowIndexAt(7, 460, 2), chrome.windowIndexAt(8, 460, 2)], [null, 0]);
// Scrolled past the launcher, a row without the frame keeps the left
// chevron's margin too.
const narrow = geometry();
narrow.settings.appSwitcherPositionSetting.value = 'bottom';
narrow.settings.windowBorderSetting.value = 'none';
const scrolled = chromeLayer(narrow, { windows: 40 });
scrolled.state.selectedIndex = 39;
scrolled.chrome.paintParts();
assert.equal(scrolled.chrome.windowIndexAt(35, 380, 40), null);
assert.notEqual(scrolled.chrome.windowIndexAt(41, 380, 40), null);
});
test('a notification the switcher selects sits in a box, filled with its icon inverted while the switcher has focus', () => {
@@ -977,33 +1166,42 @@ test('with the selection out on a notification, the windows stay scrolled as the
});
// Exercise the real worker message handler with platform work stubbed out.
function resizeHandler(file, globals) {
// `own` names the worker's own functions and constants the handler runs with.
function resizeHandler(file, globals, own = []) {
const source = ts.createSourceFile(file, read(file), ts.ScriptTarget.Latest, true);
const handler = source.statements.find((s) => ts.isExpressionStatement(s)
&& ts.isBinaryExpression(s.expression) && s.expression.left.getText(source) === 'global.onmessage');
assert.ok(handler);
const named = source.statements.filter((s) => ts.isFunctionDeclaration(s) && own.includes(s.name?.text)
|| ts.isVariableStatement(s) && s.declarationList.declarations.some((d) => own.includes(d.name.getText(source))));
assert.equal(named.length, own.length);
const context = { global: {}, ...globals };
vm.runInNewContext(js(handler.getText(source)), context);
vm.runInNewContext(js([...named, handler].map((s) => s.getText(source)).join('\n')), context);
return (viewport) => context.global.onmessage({ data: { type: 'resize-window', windowId: 'test', viewport } });
}
test('Navigate resize preserves its active route and window, and remeasures an open menu', () => {
let paints = 0;
let menuSize;
const window = { windowId: 'test', viewportWidth: 640, viewportHeight: 452,
const window = { windowId: 'test', viewportWidth: 640, viewportHeight: 452, viewport: bordered(640, 452),
menu: { resize: (size) => { menuSize = size; } }, lastSubmittedFingerprint: 'old' };
const route = { destination: 'Home' };
const resize = resizeHandler('app/apps/navigate/navigate-app.worker.ts', {
window, route, phase: 'navigating', render: () => { paints++; },
window, route, phase: 'navigating', render: () => { paints++; }, sameViewport,
});
resize({ width: 576, height: 260 });
resize(bordered(576, 260));
assert.equal(window.viewportHeight, 260);
assert.equal(window.viewportWidth, 576);
assert.deepEqual(window.viewport, bordered(576, 260));
assert.equal(window.lastSubmittedFingerprint, '');
assert.equal(route.destination, 'Home');
assert.deepEqual(menuSize, { width: 576, height: 260 });
resize({ width: 576, height: 260 });
assert.deepEqual(menuSize, bordered(576, 260));
resize(bordered(576, 260));
assert.equal(paints, 1);
// What the edges touch changing is a new layout too, at the same size.
resize(edged(576, 260, 'top'));
assert.equal(paints, 2);
assert.deepEqual(menuSize, edged(576, 260, 'top'));
});
test('Terminal resize keeps the view identity, negotiates its grid and skips position-only changes', () => {
@@ -1047,13 +1245,17 @@ test('the games and Roam resize in place, keeping their state, and repaint when
}
let paints = 0, viewSize;
const window = { windowId: 'test', viewportWidth: 576, viewportHeight: 443, menu: null, lastSubmittedFingerprint: 'old',
view: { resize: (...size) => { viewSize = size; } } };
const resize = resizeHandler('app/apps/roam/roam-app.worker.ts', {
window, render: () => paints++, DOC_MARGIN: 6, HEADER_HEIGHT: 30, BOTTOM_MARGIN: 6,
});
resize({ width: 576, height: 415 });
// The document re-wraps for the region under its header.
assert.deepEqual([window.viewportHeight, viewSize, window.lastSubmittedFingerprint, paints], [415, [564, 379], '', 1]);
view: { resize: (size) => { viewSize = { ...size }; } } };
const resize = resizeHandler('app/apps/roam/roam-app.worker.ts', { window, render: () => paints++ },
['HEADER_HEIGHT', 'headerBottom', 'documentBox']);
resize(bordered(576, 415));
// The document re-wraps for the region under its header: between the side
// padding and down to the window's bottom edge, whose padding goes inside it.
assert.deepEqual([window.viewportHeight, viewSize, window.lastSubmittedFingerprint, paints],
[415, { x: 8, y: 32, width: 560, height: 383, padBottom: 8 }, '', 1]);
assert.deepEqual(window.viewport, bordered(576, 415));
resize(unbordered(576, 415));
assert.deepEqual(viewSize, { x: 0, y: 24, width: 576, height: 391, padBottom: 0 });
});
test('resizing a terminal reconnects with the new grid and ignores callbacks from the old socket', () => {
+1
View File
@@ -23,6 +23,7 @@ const { BdfFont } = load('app/graphics/bdffont.ts');
const font = BdfFont.parse(fs.readFileSync(path.join(__dirname, '../app/fonts/terminus/ter-u18n.bdf'), 'utf8'));
const fonts = { getDefaultSmallFont: () => font };
const layers = load('app/ui/layers.ts', {
'./viewport': require('../.test-build/app/ui/viewport.js'),
'../graphics/image': graphics, '../graphics/plane': plane, './gestures': gestures,
'../native/frame-timings': { spanCurrent: (_name, paint) => paint() },
'../graphics/screen-size': { screenWidth: () => 640, screenHeight: () => 480 },
+1 -1
View File
@@ -9,7 +9,7 @@ test('iOS game worker forwards an immutable byte payload through its host and ig
const load = loader({ global: { isIOS: true, postMessage: data => worker.onmessage({ data }) } }, {
'../../graphics/image': {}, './chrome-layer': { windowIcon() {} },
'../../assistant/tool-registry': { toolRegistry: { removeAppTools() {} } },
'./geometry': { appViewportSize: () => ({ width: 576, height: 260 }) },
'./geometry': { appViewport: () => ({ width: 576, height: 260 }) },
'../../native/frame-timings': {}, './worker-state': {},
'./shell': { shell: { registerWindow() {} } },
});
+33 -15
View File
@@ -4,6 +4,7 @@ const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ts = require('typescript');
const { bordered, unbordered, edged } = require('./helpers/viewport.cjs');
function load(file, modules = {}, globals = {}) {
const source = fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
@@ -23,7 +24,7 @@ const font = (size) => BdfFont.parse(fs.readFileSync(path.join(__dirname, `../ap
const small = font(18), large = font(32);
const diagnostics = { magneticAccuracy: 3, magneticAnomalies: 2, orientationSource: 3, flags: 0x8c, sampleTimeMs: 1234 };
function compass(width = 576, height = 260, glasses = 'g2') {
function compass(width = 576, height = 260, glasses = 'g2', viewport = bordered(width, height)) {
let listener, window;
class RecordingImage extends graphics.GrayImage {
texts = [];
@@ -60,7 +61,7 @@ function compass(width = 576, height = 260, glasses = 'g2') {
'./calibration-layer': {}, './declination': { onDeclinationChanged: () => () => {} },
'./heading': { getNorthReference: () => 'magnetic', resolveHeading: (v) => ({ displayDegrees: v }) },
}, { setInterval: () => 1, clearInterval() {} });
const ctx = { stack: { getBaseSize: () => ({ width, height }), pop() {} } };
const ctx = { stack: { getBaseSize: () => viewport, pop() {} } };
app.createCompassAppWindow({ onClosed() {} });
return { menu: () => window.menuItems(),
paint: () => window.baseLayer.paint(ctx),
@@ -96,23 +97,40 @@ test('calibration dots track firmware magnetic accuracy and never go stale', ()
});
test('calibration readout fits the viewport without overlapping the heading or status', () => {
for (const [width, height] of [[240, 260], [320, 260], [576, 260], [640, 260], [576, 288], [576, 140]]) {
const app = compass(width, height); app.heading({ ...diagnostics, magneticAccuracy: 2 });
const image = app.paint();
const label = calibrationText(image);
assert.ok(label.x >= 0 && label.y >= 0, `${width}x${height}`);
assert.ok(label.x + label.width <= width && label.y + label.height <= image.height, `${width}x${height}`);
for (const other of image.texts.filter((t) => t !== label)) {
assert.ok(!overlaps(label, other), `${width}x${height}: overlaps "${other.text}"`);
}
if (process.env.COMPASS_PREVIEW && width === 576 && height === 260) {
fs.writeFileSync(process.env.COMPASS_PREVIEW, Buffer.concat([
Buffer.from(`P5\n${image.width} ${image.height}\n255\n`), Buffer.from(image.withDrawsBaked().pixels),
]));
for (const [width, height] of [[240, 260], [320, 260], [576, 260], [640, 260], [576, 288], [576, 140], [476, 155]]) {
for (const viewport of [bordered(width, height), unbordered(width, height), edged(width, height, 'top', 'left'), edged(width, height, 'bottom')]) {
const where = `${width}x${height} ${JSON.stringify(viewport.padding)}`;
const app = compass(width, height, 'g2', viewport); app.heading({ ...diagnostics, magneticAccuracy: 2 });
const image = app.paint();
const label = calibrationText(image);
const { padding } = viewport;
// Every line of text keeps inside the padding of the window's edges.
for (const text of image.texts) {
assert.ok(text.x >= padding.left && text.y >= padding.top, `${where}: "${text.text}"`);
assert.ok(text.x + text.width <= width - padding.right && text.y + text.height <= height - padding.bottom, `${where}: "${text.text}"`);
}
for (const other of image.texts.filter((t) => t !== label)) {
assert.ok(!overlaps(label, other), `${where}: overlaps "${other.text}"`);
}
if (process.env.COMPASS_PREVIEW && width === 576 && height === 260 && viewport.padding.top && viewport.padding.right) {
fs.writeFileSync(process.env.COMPASS_PREVIEW, Buffer.concat([
Buffer.from(`P5\n${image.width} ${image.height}\n255\n`), Buffer.from(image.withDrawsBaked().pixels),
]));
}
}
}
});
test('the calibration readout sits in the top-right corner, at the padding of those edges', () => {
const corner = (viewport) => {
const label = calibrationText(compass(576, 260, 'g2', viewport).paint());
return [label.x + label.width, label.y];
};
assert.deepEqual(corner(bordered(576, 260)), [568, 8]);
assert.deepEqual(corner(unbordered(576, 260)), [576, 0]);
assert.deepEqual(corner(edged(576, 260, 'top')), [576, 8]);
});
test('glasses without a magnetometer say so and offer no calibration', () => {
const app = compass(576, 260, 'g1');
const image = app.paint();
+8 -2
View File
@@ -4,6 +4,7 @@ const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ts = require('typescript');
const { bordered, unbordered } = require('./helpers/viewport.cjs');
function load(file, modules = {}, extra = '', globals = {}) {
const source = fs.readFileSync(path.join(__dirname, '..', file), 'utf8') + extra;
@@ -124,7 +125,8 @@ test('heading updates reuse the texture; brightness, layout and clipping changes
const layer = new compass.CompassLayer(() => {});
layer.enabled = true;
let height = 260;
const ctx = { stack: { getBaseSize: () => ({ width: viewportWidth, height }) } };
let viewport = bordered;
const ctx = { stack: { getBaseSize: () => viewport(viewportWidth, height) } };
const texture = () => layer.paint(ctx).draws.find((draw) => draw.kind === 'image').source;
const waiting = texture();
layer.rawHeading = 0;
@@ -143,7 +145,11 @@ test('heading updates reuse the texture; brightness, layout and clipping changes
const wide = texture();
assert.notEqual(wide, tall);
layer.firmwareStatus = 'Calibration status '.repeat(12);
assert.notEqual(texture(), wide);
const wrapped = texture();
assert.notEqual(wrapped, wide);
// Losing the borders moves the rose toward the edges, at the same size.
viewport = unbordered;
assert.notEqual(texture(), wrapped);
viewportWidth = 576;
});
+1
View File
@@ -22,6 +22,7 @@ const { BdfFont } = load('app/graphics/bdffont.ts');
const font = (name) => BdfFont.parse(fs.readFileSync(path.join(__dirname, `../app/fonts/terminus/${name}.bdf`), 'utf8'));
const fonts = { getDefaultSmallFont: () => font('ter-u12n'), getDefaultMediumFont: () => font('ter-u16n') };
const layers = load('app/ui/layers.ts', {
'./viewport': require('../.test-build/app/ui/viewport.js'),
'../graphics/image': graphics, '../graphics/plane': plane, './gestures': gestures,
'../native/frame-timings': { spanCurrent: (_name, paint) => paint() },
});
+19
View File
@@ -36,6 +36,25 @@ test('the display mode starts as the middle band, or carries over the old mode a
assert.equal(api.displayLayoutSetting.get(), 'band-bottom');
});
test('the border starts all around, or as the status line a popup switcher\'s old Window border toggle left', () => {
const border = (entries) => settingsFixture(new Map(entries)).windowBorderSetting.get();
assert.equal(border([]), 'all');
assert.equal(border([['display.appSwitcherPosition', 'popup']]), 'all');
assert.equal(border([['display.appSwitcherPosition', 'popup'], ['display.windowBorder', true]]), 'all');
assert.equal(border([['display.appSwitcherPosition', 'popup'], ['display.windowBorder', false]]), 'status');
// A bottom row's windows had the border whatever the toggle said.
assert.equal(border([['display.windowBorder', false]]), 'all');
// Once set, the setting is its own, for either switcher.
const store = new Map([['display.appSwitcherPosition', 'popup'], ['display.windowBorder', false]]);
const api = settingsFixture(store);
assert.equal(api.windowBorderSetting.displayValue(), 'Status line');
api.windowBorderSetting.set('none');
assert.equal(store.get('display.border'), 'none');
api.appSwitcherPositionSetting.set('bottom');
assert.equal(api.windowBorderSetting.get(), 'none');
assert.deepEqual(Array.from(api.windowBorderSetting.values, (value) => api.windowBorderSetting.displayValue(value)), ['All around', 'Status line', 'None']);
});
test('the glasses model name follows the paired glasses type', () => {
const model = (entries) => settingsFixture(new Map(entries)).glassesModelName();
assert.equal(model([]), 'G2');
+3 -2
View File
@@ -5,6 +5,7 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
const { bordered } = require('./helpers/viewport.cjs');
const gestures = loader({}, {})('app/ui/gestures.ts');
const font = { lineHeight: 10, measureText: (text) => text.length * 6 };
@@ -74,7 +75,7 @@ const loadStore = () => {
const stackCalls = { push: 0, clearToBase: 0 };
const ctx = {
stack: {
getBaseSize: () => ({ width: 476, height: 180 }),
getBaseSize: () => bordered(476, 180),
isFocused: () => true,
clearToBase() { stackCalls.clearToBase++; },
push() { stackCalls.push++; },
@@ -159,7 +160,7 @@ const loadWarning = () => {
// The real stack calls onRemoved as it pops.
const ctx = {
stack: {
getBaseSize: () => ({ width: 476, height: 180 }),
getBaseSize: () => bordered(476, 180),
isFocused: () => true,
pop() { outcome.popped++; dialog.onRemoved(); },
},
+2 -1
View File
@@ -9,6 +9,7 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
const { bordered } = require('./helpers/viewport.cjs');
const setting = (initial = '') => {
let value = initial;
@@ -74,7 +75,7 @@ const makeCtx = () => {
const stack = {
cleared: 0,
pushed: [],
getBaseSize: () => ({ width: 576, height: 136 }),
getBaseSize: () => bordered(576, 136),
isFocused: () => true,
clearToBase() { stack.cleared++; stack.pushed.length = 0; },
push(layer) { stack.pushed.push(layer); },
+51 -6
View File
@@ -6,13 +6,14 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
const { bordered, unbordered, edged } = require('./helpers/viewport.cjs');
const gestures = loader({}, {})('app/ui/gestures.ts');
const font = { lineHeight: 10, measureText: (text) => text.length * 6 };
/** Records drawn text; every other drawing call is a no-op. */
/** Records drawn text (and where, in `drawn.positions`); every other drawing call is a no-op. */
const makeImageClass = (drawn) => class {
drawText(_font, _x, _y, text) { drawn.push(text); }
drawText(_font, x, y, text) { drawn.push(text); (drawn.positions ??= new Map()).set(text, { x, y }); }
fillRect() {}
fillRoundedRect() {}
drawRoundedRect() {}
@@ -20,6 +21,8 @@ const makeImageClass = (drawn) => class {
/** Stand-in for ui/menu-core's Menu: draws every row in order, scrolls the selection by one. */
class FakeMenu {
/** The box and scrollbar track of the latest paint, whichever tab's menu it was. */
static painted = { box: null, scrollbar: null };
constructor(options) {
this.options = options;
this.items = options.items;
@@ -37,9 +40,10 @@ class FakeMenu {
if (event.type === 'scroll-up') this.selectedIndex = Math.max(0, this.selectedIndex - 1);
}
paint(image, box) {
FakeMenu.painted.box = box;
this.items.forEach((item, index) => this.options.draw({ image, item, index, x: box.x, y: box.y, width: box.width }));
}
drawScrollbar() {}
drawScrollbar(_image, x, y, height) { FakeMenu.painted.scrollbar = { x, y, height }; }
}
const storeApp = (packageId, name, version) => ({
@@ -93,9 +97,9 @@ const loadStore = ({ updates = [] } = {}) => {
return { layer, drawn, installs };
};
const makeCtx = () => ({
const makeCtx = (viewport = bordered(576, 288)) => ({
stack: {
getBaseSize: () => ({ width: 576, height: 288 }),
getBaseSize: () => viewport,
isFocused: () => true,
clearToBase() {},
push() {},
@@ -191,6 +195,47 @@ test('the Updates tab has no Update All row when nothing can be installed', asyn
assert.ok(!painted.includes('Update All'));
});
test('the list scrolls to the window\'s bottom edge under the fixed header, inside the side padding', async () => {
const updates = [{ installed: { packageId: 'c', name: 'Gamma', version: '1' } }];
const layout = async (viewport) => {
const { layer, drawn } = loadStore({ updates });
const ctx = makeCtx(viewport);
await openUpdatesTab(layer, ctx);
repaint(layer, drawn, ctx);
return { ...FakeMenu.painted, title: drawn.positions.get('EvenHub'), row: drawn.positions.get('Gamma') };
};
// Framed: rows start at the left padding and stop short of the scrollbar,
// which hugs the right padding. The header keeps the top padding; the list
// box runs to the bottom edge with that edge's padding inside it.
const framed = await layout(bordered(576, 288));
assert.equal(framed.box.x, 8);
assert.equal(framed.box.x + framed.box.width, 576 - 8 - 6);
assert.equal(framed.box.y + framed.box.height, 288, 'the box reaches the bottom edge');
assert.equal(framed.box.padTop, 0, 'no padding under the fixed header');
assert.equal(framed.box.padBottom, 8);
assert.deepEqual(framed.title, { x: 14, y: 11 }, 'a focused tab\'s highlight, 3px above the title line, sits at the padding');
assert.equal(framed.row.x, framed.title.x, 'the title lines up with the row text');
assert.deepEqual(framed.scrollbar, { x: 576 - 8 - 3, y: framed.box.y, height: 288 - 8 - framed.box.y });
// Nothing bordering the window: content runs to every edge.
const bare = await layout(unbordered(576, 288));
assert.equal(bare.box.x, 0);
assert.equal(bare.box.padBottom, 0);
assert.equal(bare.box.y + bare.box.height, 288);
assert.deepEqual(bare.title, { x: 6, y: 3 });
assert.equal(bare.box.y, framed.box.y - 8, 'the header moves up by the top padding');
assert.equal(bare.scrollbar.x, 576 - 3, 'the scrollbar stays clear of the rows');
assert.ok(bare.box.x + bare.box.width <= bare.scrollbar.x);
// Each edge follows its own padding.
const mixed = await layout(edged(576, 288, 'top', 'left'));
assert.equal(mixed.box.x, 8);
assert.equal(mixed.box.x + mixed.box.width, 576 - 6);
assert.equal(mixed.box.y, framed.box.y);
assert.equal(mixed.box.padBottom, 0);
});
// ---- permission dialog ---------------------------------------------------
const loadDialog = (detailLines) => {
@@ -216,7 +261,7 @@ const loadDialog = (detailLines) => {
() => { outcome.confirmed = true; },
() => { outcome.confirmed = false; },
);
const ctx = { stack: { getBaseSize: () => ({ width: 576, height: 136 }), isFocused: () => true, pop() {} } };
const ctx = { stack: { getBaseSize: () => bordered(576, 136), isFocused: () => true, pop() {} } };
const paint = () => {
drawn.length = 0;
dialog.paint(ctx, () => new ImageClass());
+6 -1
View File
@@ -1,5 +1,6 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { bordered, unbordered, edged } = require('./helpers/viewport.cjs');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
@@ -56,7 +57,9 @@ const glyphRuns = (image, f) => image.draws.filter((d) => d.kind === 'glyph' &&
test('the font picker previews under its rows where they fit, else beside them, on the window either way', () => {
// At 192 rows either fits, by the font's metrics: only the bounds are checked.
for (const [size, beside] of [[{ width: 576, height: 260 }, false], [{ width: 476, height: 192 }, null], [{ width: 476, height: 155 }, true]]) {
// Framed windows, and ones nothing borders (so no padding: the rows reach the edges).
for (const [size, beside] of [[bordered(576, 260), false], [bordered(476, 192), null], [bordered(476, 155), true],
[unbordered(576, 260), false], [unbordered(476, 155), true], [edged(576, 260, 'top', 'left'), false]]) {
const { layers, ctx } = stackOf(size);
picker.uiFontPickerMenuItem().onSelect(ctx);
const image = layers[0].paint(ctx);
@@ -72,6 +75,8 @@ test('the font picker previews under its rows where they fit, else beside them,
const rowsRight = Math.max(...rows.map((d) => d.x)), rowsBottom = Math.max(...rows.map((d) => d.y));
if (beside === true) assert.ok(Math.min(...sample.map((d) => d.x)) > rowsRight, 'the sample right of the rows');
if (beside === false) assert.ok(Math.min(...sample.map((d) => d.y)) > rowsBottom, 'the sample under the rows');
// The rows' text keeps the same inset from wherever the padding puts their boxes.
assert.equal(Math.min(...rows.map((d) => d.x)), size.padding.left + 10);
}
});
+17
View File
@@ -0,0 +1,17 @@
// Viewports for layout tests: what ctx.stack.getBaseSize() (or a worker's
// open-window message) hands a layout. Needs `tsc -p tests/tsconfig.json`.
const viewport = require('../../.test-build/app/ui/viewport.js');
/** A window with a border line along every edge (a framed window): 8px of padding all round. */
const bordered = (width, height) => viewport.viewportWith({ width, height }, viewport.uniformEdges('border'));
/** A window nothing borders (Border: None, or immersive): no padding. */
const unbordered = (width, height) => viewport.viewportWith({ width, height }, viewport.uniformEdges('offscreen'));
/** A window with border lines along just the named edges, e.g. edged(576, 260, 'top', 'left'). */
const edged = (width, height, ...borders) => viewport.viewportWith({ width, height }, {
top: 'offscreen', right: 'offscreen', bottom: 'offscreen', left: 'offscreen',
...Object.fromEntries(borders.map((edge) => [edge, 'border'])),
});
module.exports = { ...viewport, bordered, unbordered, edged };
+44 -8
View File
@@ -124,18 +124,53 @@ function shown(image, at) {
return withClock(at, () => Array.from(image.withDrawsBaked().pixels, (v) => Math.min(15, (v + 8) >> 4)));
}
test('a box topped at the band inset less the highlight inset pads the first row band evenly', () => {
// The launcher's root grid (launcher-app.ts ROOT_GRID_TOP) relies on this.
const { grid } = makeGrid();
const { ICON_GRID_BAND_INSET_X: insetX, ICON_GRID_HIGHLIGHT_INSET_Y: insetY } = loadIconGrid();
const image = paint(grid, 1000, { x: 0, y: insetX - insetY, width: 500, height: 190 });
/** Bounds of the selection highlight's stroke in a painted image: [top, left, right margin]. */
function bandBounds(image) {
const stroke = build('ui/menu-core').MENU_HIGHLIGHT_STROKE;
let left = 500, right = -1, top = 200;
image.pixels.forEach((v, i) => {
if (v !== stroke) return;
left = Math.min(left, i % 500); right = Math.max(right, i % 500); top = Math.min(top, (i / 500) | 0);
});
assert.deepEqual([top, left, 500 - 1 - right], [insetX, insetX, insetX]);
return [top, left, 500 - 1 - right];
}
test('a box inset at the sides, with as much padTop, pads the first row band evenly', () => {
// The launcher's grid (launcher-app.ts) relies on this: its box runs to the
// window's top edge, with the edge's suggested padding as padTop.
const pad = 8;
const image = paint(makeGrid().grid, 1000, { x: pad, y: 0, width: 500 - 2 * pad, height: 190, padTop: pad });
assert.deepEqual(bandBounds(image), [pad, pad, pad]);
// Beside blank space there is no padding: the band spans the box, its own
// 2px inside its row.
assert.deepEqual(bandBounds(paint(makeGrid().grid, 1000, { x: 0, y: 0, width: 500, height: 190 })), [2, 0, 0]);
});
test('padTop scrolls away with the first row, and the scroll still animates to the static paint', async () => {
const box = { x: 0, y: 0, width: 500, height: 180, padTop: 8, padBottom: 8 };
const { grid } = makeGrid({ items: Array.from({ length: 20 }, (_, i) => `item${i}`) });
const iconYs = (image) => [...new Set(image.draws.filter((d) => d.kind === 'image' && !d.presentation).map((d) => d.y))];
// The first row starts below the padding (less the band's own 2px inset).
assert.deepEqual(iconYs(paint(grid, 500, box)), [6 + 4, 6 + 4 + ROW_H]);
await grid.handleInput(ring('scroll-down'), null);
paint(grid, 1000, box);
// Once the band's slide onto the second row is over.
const settledBefore = paint(grid, 2000, box);
await grid.handleInput(ring('scroll-down'), null);
const moving = paint(grid, 3000, box);
assert.ok(animation(moving), 'the scroll is retained as a display list');
assert.deepEqual(shown(moving, 3000), shown(settledBefore, 2000));
const end = 3000 + MENU_HIGHLIGHT_DURATION_MS;
const settled = paint(grid, end, box);
// Scrolled, the rows run from the box's top edge.
assert.deepEqual(iconYs(settled), [4, 4 + ROW_H]);
assert.deepEqual(shown(moving, end), shown(settled, end));
// A touch lands on the row under it either way.
const { grid: touched, log } = makeGrid();
paint(touched, 1000, box);
assert.equal(await touched.hitTest(50, 3, null), false, 'the padding is no row');
assert.equal(await touched.hitTest(50, 6 + ROW_H + 10, null), true);
assert.deepEqual(log.activated.map((a) => a.index), [5]);
});
test('rows keep their content height instead of stretching, and the next row peeks clipped', () => {
@@ -203,8 +238,9 @@ test('item selection slides the highlight between cells without redrawing past t
assert.equal(list.calls[0].clip.width, 495, 'the scrollbar gutter is left to the static paint');
const rect = list.calls[1];
const { evaluate } = build('graphics/draw-expression');
assert.equal(evaluate(rect.x, 0).value, 200 + 6, 'starts on the middle cell');
assert.equal(evaluate(rect.x, MENU_HIGHLIGHT_DURATION_MS).value, 300 + 6, 'rests on the next cell');
// The rows keep clear of the gutter: five 99px columns in the 495 left of it.
assert.equal(evaluate(rect.x, 0).value, 198 + 6, 'starts on the middle cell');
assert.equal(evaluate(rect.x, MENU_HIGHLIGHT_DURATION_MS).value, 297 + 6, 'rests on the next cell');
assert.deepEqual(shown(moving, 2000), shown(before, 1000));
const end = 2000 + MENU_HIGHLIGHT_DURATION_MS;
assert.deepEqual(shown(moving, end), shown(paint(grid, end), end));
+23 -5
View File
@@ -4,6 +4,7 @@ const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ts = require('typescript');
const { bordered, unbordered } = require('./helpers/viewport.cjs');
const read = (file) => fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
const js = (source) => ts.transpileModule(source, {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
@@ -103,8 +104,16 @@ test('Input events captures while visible, pauses for history, and unsubscribes
});
let visible = true, renders = 0, removed = 0, pops = 0;
const layer = new InputEventsLayer(() => renders++, () => visible, () => removed++);
const ctx = { stack: { getBaseSize: () => ({ width: 576, height: 260 }),
let viewport = bordered(576, 260);
const ctx = { stack: { getBaseSize: () => viewport,
pop: () => pops++, popThrough: (page) => { assert.equal(page, layer); page.onRemoved(); } } };
const inBounds = (image) => {
for (const text of image.texts) {
assert.ok(text.x >= 0 && text.x + text.width <= image.width, text.text);
assert.ok(text.y >= 0 && text.y + text.height <= image.height, text.text);
}
};
const at = (image, start) => image.texts.find(t => t.text.startsWith(start));
try {
for (const type of ['ring-press','click','ring-press','ring-press','double-click','long-press','long-press-release','short-then-long-press']) {
const e = { ...event(type, 1000 + renders * 75), ringInput: { tick: 4294967200 + renders, type: 1, aux:0, speed:0 } };
@@ -117,10 +126,19 @@ test('Input events captures while visible, pauses for history, and unsubscribes
assert.ok(image.texts.some(t => t.text.startsWith("*")));
layer.menuItems()[2].onSelect(ctx);
assert.ok(layer.paint(ctx).texts.some(t => t.text.startsWith("Phone receive time")));
for (const text of image.texts) {
assert.ok(text.x >= 0 && text.x + text.width <= image.width, text.text);
assert.ok(text.y >= 0 && text.y + text.height <= image.height, text.text);
}
inBounds(image);
// Framed: the title and the hint line sit at the padding; the log is between them.
assert.deepEqual([at(image, 'Input events').x, at(image, 'Input events').y], [8, 8]);
assert.equal(at(image, 'Unfiltered').y + font.lineHeight, 260 - 8);
assert.ok(Math.max(...image.texts.map(t => t.x + t.width)) <= 576 - 8, 'nothing runs into the right padding');
// Nothing bordering the window: the same lines run to its edges.
viewport = unbordered(576, 260);
const bare = layer.paint(ctx);
inBounds(bare);
assert.deepEqual([at(bare, 'Input events').x, at(bare, 'Input events').y], [0, 0]);
assert.equal(at(bare, 'Unfiltered').y + font.lineHeight, 260);
assert.ok(bare.texts.length >= image.texts.length, 'the log has no less room');
viewport = bordered(576, 260);
if (process.env.INPUT_EVENTS_PREVIEW) fs.writeFileSync(process.env.INPUT_EVENTS_PREVIEW, Buffer.concat([
Buffer.from(`P5\n${image.width} ${image.height}\n255\n`), Buffer.from(image.withDrawsBaked().pixels),
]));
+11 -5
View File
@@ -214,15 +214,12 @@ test('iOS bandwidth footer toggles live, polls only in foreground and resets its
'./phone-gestures': { PhoneGestureRecognizer: class { cancel() {} } },
'./ble-bandwidth-meter': require('../.test-build/app/phone-ui/ble-bandwidth-meter.js'),
'../native/ble-traffic': { sampleBleTraffic: () => totals },
'../ui/dashboard-settings': { brightnessSetting: { get: () => 'auto' }, displayLayoutSetting: { displayValue: () => 'Tall' }, showBleBandwidthSetting: { get: () => enabled }, glassesModelName: () => 'G2',
'../ui/dashboard-settings': { phoneInputStyleSetting: { get: () => 'watch' }, showBleBandwidthSetting: { get: () => enabled },
onAnySettingChanged: fn => { settingListeners.add(fn); return () => settingListeners.delete(fn); } },
'../g2/device-addresses': { loadDeviceAddresses: () => ({}) },
'../g2/ios-peripheral-identity': { deviceAddressError: () => 'no test devices' },
'./onboarding-state': { isPreviewOnlyMode: () => false },
'../g2/reconnect-policy': { isAutoReconnectSuppressed: () => false },
'../g2/glasses-display-state': require('../.test-build/app/g2/glasses-display-state.js'),
'../ui/shell/shell': { shell: { onBatteryLevelsChanged: () => () => {}, getBatteryLevels: () => ({
headset: null, headsetCharging: null, case: null, caseCharging: null, ring: null, ringCharging: null }) } },
};
modules['./keyboard-input-view-model'] = load('app/phone-ui/keyboard-input-view-model.ts', { require: id => modules[id] });
modules['./remote-controls-view-model'] = load('app/phone-ui/remote-controls-view-model.ts', { require: id => modules[id] });
@@ -370,6 +367,7 @@ test('iOS preview voice uses the phone microphone, while connected capture stays
test('iOS continuous capture is shared by windows and restarts after a disconnect, a lock or backgrounding', async () => {
const calls = [], claims = [], providers = [];
let saveRecording = false;
// Models the bridge's continuous state: listening on a source, or draining after a stop.
const bridge = { source: null, draining: false, recording: '', rawSession: undefined,
supportsContinuous: voice => voice.provider !== 'onboard',
@@ -387,7 +385,7 @@ test('iOS continuous capture is shared by windows and restarts after a disconnec
setRawSession: session => { bridge.rawSession = session; } };
const settings = { ...voiceSettings, voiceProviderSetting: { get: () => 'whisper-server' },
whisperServerUrlSetting: { get: () => 'http://whisper.local:8000' }, getVoiceTranscriptionLanguage: () => 'en',
saveTranscribeAudioSetting: { get: () => true } };
saveRecordingSetting: { get: () => saveRecording } };
const { IosPreviewController } = load('app/g2/ios-preview-controller.ts', {
require: id => id === '../native/ios-voice-input' ? { iosVoiceInput: bridge } : id === '../ui/dashboard-settings' ? settings
: id === '../ui/shell/voice-activity' ? { voiceActivity: { setActive: (active, holder) => claims.push([active, holder]) } }
@@ -406,7 +404,15 @@ test('iOS continuous capture is shared by windows and restarts after a disconnec
host.startContinuousVoiceCapture('transcribe', { recordAs: 'transcribe-1' }); await settle();
host.startContinuousVoiceCapture('calculator'); await settle();
assert.deepEqual(calls, [['glasses', true]], 'the second window shares the capture');
// Save Recording (in the window's menu) starts and stops the recording while it is open.
assert.equal(bridge.recording, '');
saveRecording = true; host.syncContinuousRecording();
assert.equal(bridge.recording, 'transcribe-1');
saveRecording = false; host.syncContinuousRecording();
assert.equal(bridge.recording, '');
saveRecording = true; host.syncContinuousRecording();
assert.equal(bridge.recording, 'transcribe-1');
assert.deepEqual(calls, [['glasses', true]], 'without touching the capture');
assert.deepEqual(claims.at(-1), [true, 'continuous-capture']);
host.stopContinuousVoiceCapture('calculator');
assert.deepEqual(calls, [['glasses', true]], 'closing one window keeps the other listening');
+16 -4
View File
@@ -4,6 +4,7 @@ const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ts = require('typescript');
const { bordered, unbordered } = require('./helpers/viewport.cjs');
function load(file, modules = {}, globals = {}) {
const sandbox = { exports: {}, require: id => {
@@ -150,9 +151,9 @@ function screenFixture() {
const f = provider(), timers = new Map(); let nextTimer = 0;
const font = { lineHeight: 12, measureText: text => text.length * 6 };
class Image {
constructor(width = 300, height = 288) { this.width = width; this.height = height; this.text = []; }
drawText(_font, _x, _y, text) { this.text.push(text); }
fillRoundedRect() {} drawRoundedRect() {}
constructor(width = 300, height = 288) { this.width = width; this.height = height; this.text = []; this.at = {}; this.boxes = []; }
drawText(_font, x, y, text) { this.text.push(text); this.at[text] = [x, y]; }
fillRoundedRect(x, y, width, height) { this.boxes.push([x, y, width, height]); } drawRoundedRect() {}
}
const common = {
'graphics/image': { GrayImage: Image }, 'graphics/ui-fonts': { getDefaultSmallFont: () => font, getDefaultMediumFont: () => font },
@@ -173,7 +174,8 @@ function screenFixture() {
test('Calendar and Glanceboard show permission, loading, error and event states with widget cleanup', () => {
const f = screenFixture(); let renders = 0, requests = 0;
const widget = new f.CalendarWidget(), layer = new f.CalendarLayer(() => requests++);
const ctx = { stack: { getBaseSize: () => ({ width: 300, height: 288 }) } };
let viewport = bordered(300, 288);
const ctx = { stack: { getBaseSize: () => viewport } };
const paintWidget = () => { const image = new f.Image(); widget.paint(image); return image.text.join(' '); };
widget.start(() => renders++); widget.start(() => renders++); assert.equal(f.timers.size, 1);
f.permission(false); assert.match(layer.paint(ctx).text.join(' '), /Grant calendar permission/);
@@ -187,6 +189,16 @@ test('Calendar and Glanceboard show permission, loading, error and event states
f.reads[1].done(JSON.stringify([f.event('event')]), null);
assert.match(layer.paint(ctx).text.join(' '), /Meeting/);
assert.match(paintWidget(), /Meeting/);
// Beside border lines the selection box keeps the suggested padding and the
// title lines up with row text; with nothing past the edges they run to them.
const framed = layer.paint(ctx);
assert.deepEqual(framed.at.Calendar, [18, 10]);
assert.deepEqual(framed.boxes[0], [8, 54, 284, 32]);
assert.equal(framed.at.Office[0], 18);
viewport = unbordered(300, 288);
const bare = layer.paint(ctx);
assert.deepEqual(bare.at.Calendar, [10, 2]);
assert.deepEqual(bare.boxes[0], [0, 46, 300, 32]);
widget.stop(); const before = renders; f.bridge.changeHandler();
assert.equal(renders, before); assert.equal(f.timers.size, 0);
});
+4 -1
View File
@@ -191,7 +191,10 @@ function fixture() {
: ({ 0: 'click', 1: 'scroll-up', 2: 'scroll-down', 3: 'double-click', 9: 'long-press',
10: 'long-press-release', 11: 'short-then-long-press' })[event.eventType] ?? 'unknown', source: 'ring',
}) },
'../ui/shell/geometry': { appViewportRect: () => ({ x: 0, y: 0, width: 640, height: 480 }) },
'../ui/shell/geometry': {
appViewportRect: () => ({ x: 0, y: 0, width: 640, height: 480 }),
windowEdges: () => ({ top: 'offscreen', right: 'offscreen', bottom: 'offscreen', left: 'offscreen' }),
},
};
const { IosPreviewController } = load('app/g2/ios-preview-controller.ts', modules, {
...clock, console: { log() {}, warn() {}, error: text => errors.push(text) },
+34 -1
View File
@@ -31,8 +31,13 @@ function harness() {
},
};
const recordings = [];
let failRecordings = false, recordingAttempts = 0;
class FakeRecorder {
static open(name) { const r = new FakeRecorder(); r.name = name; r.path = `/Downloads/${name}.wav`; r.pcm = []; r.closed = false; recordings.push(r); return r; }
static open(name) {
recordingAttempts++;
if (failRecordings) return null;
const r = new FakeRecorder(); r.name = name; r.path = `/Downloads/${name}.wav`; r.pcm = []; r.closed = false; recordings.push(r); return r;
}
append(bytes) { this.pcm.push(...bytes); }
close() { this.closed = true; }
}
@@ -56,6 +61,7 @@ function harness() {
} };
const onboard = { provider: 'onboard', elevenLabsApiKey: '', openAiApiKey: '', sonioxApiKey: '' };
return { bridge, native, session, audio, commands, text, timers, clouds, analyzers, recordings, release: () => release(),
failRecordings: value => { failRecordings = value; }, recordingAttempts: () => recordingAttempts,
analyzerSupported: value => { analyzerSupported = value; },
onboard, cloud: { ...onboard, provider: 'soniox', sonioxApiKey: 'key' },
microphoneAuthorization: value => { microphoneAuthorization = value; }, microphoneRequests: () => microphoneRequests,
@@ -307,7 +313,10 @@ test('push-to-talk after Transcribe closed starts its own capture instead of joi
test('continuous captures record to the requested WAV, created by their first audio and kept across restarts', async () => {
const h = harness();
let changes = 0; h.bridge.onRecordingChange(() => changes++);
assert.equal(h.bridge.recording, false);
h.bridge.recordTo('transcribe-2026-10-17-120000');
assert.deepEqual([h.bridge.recording, h.bridge.recordingFailed, changes], [true, false, 1]);
// A start that fails before any audio leaves no file behind.
h.native.error = 'No phone microphone is available.';
await h.bridge.startPhoneCapture(h.cloud, () => {}, false, true);
@@ -334,6 +343,30 @@ test('continuous captures record to the requested WAV, created by their first au
assert.deepEqual(h.recordings[0].pcm, [1, 2, 3, 4, 5, 6, 7]);
h.bridge.recordTo('');
assert.equal(h.recordings[0].closed, true);
assert.deepEqual([h.bridge.recording, changes], [false, 2]);
});
test('a recording whose file cannot be created is reported, and not retried per packet', async () => {
const h = harness();
let changes = 0; h.bridge.onRecordingChange(() => changes++);
h.failRecordings(true);
h.bridge.recordTo('transcribe-1');
const start = h.bridge.startGlassesCapture(h.session, h.cloud, () => {}, false, true); h.release(); await start;
h.native.pcmHandler(new Uint8Array([1, 2]));
h.native.pcmHandler(new Uint8Array([3, 4]));
assert.deepEqual([h.bridge.recording, h.bridge.recordingFailed, changes, h.recordingAttempts()], [false, true, 2, 1]);
// Asking for the same recording again changes nothing; another one (Save Recording
// switched off and on) is a fresh attempt.
h.bridge.recordTo('transcribe-1');
h.native.pcmHandler(new Uint8Array([5]));
assert.equal(h.recordingAttempts(), 1);
h.failRecordings(false);
h.bridge.recordTo('');
assert.deepEqual([h.bridge.recording, h.bridge.recordingFailed, changes], [false, false, 3]);
h.bridge.recordTo('transcribe-1');
h.native.pcmHandler(new Uint8Array([6]));
assert.deepEqual([h.bridge.recording, h.bridge.recordingFailed, changes], [true, false, 4]);
assert.deepEqual(h.recordings[0].pcm, [6]);
});
test('a glasses session ending drains continuous capture instead of discarding what it heard', async () => {
@@ -21,4 +21,31 @@ class WavRecorderRepairTest {
file.delete()
}
}
@Test
fun keepsTheHeaderCurrentWhileRecording() {
val file = File.createTempFile("recording", ".wav")
try {
val recorder = FaceclawWavRecorder(file.path, 16000, 1)
// Under a second of audio: still the empty header from the start.
recorder.append(ByteArray(16000))
assertEquals(BinaryEncoding.wavHeader(0, 16000, 1).toList(), file.readBytes().copyOf(44).toList())
// Past a second the header covers what is on disk, without waiting for finish(), and
// later audio still lands at the end.
recorder.append(ByteArray(16000) { 1 })
recorder.append(ByteArray(100) { 2 })
var bytes = file.readBytes()
assertEquals(44 + 32100, bytes.size)
assertEquals(BinaryEncoding.wavHeader(32000, 16000, 1).toList(), bytes.copyOf(44).toList())
assertEquals(0.toByte(), bytes[44])
assertEquals(1.toByte(), bytes[44 + 16000])
assertEquals(2.toByte(), bytes.last())
assertEquals(32100L, recorder.finish())
bytes = file.readBytes()
assertEquals(44 + 32100, bytes.size)
assertEquals(BinaryEncoding.wavHeader(32100, 16000, 1).toList(), bytes.copyOf(44).toList())
} finally {
file.delete()
}
}
}
@@ -63,7 +63,6 @@ class VoiceCaptureSessionTest {
override val dispatcher = CallbackDispatcher { it() }
var packetListener: FaceclawAudioPacketListener? = null
var g2Stops = 0
val recordings = mutableListOf<ByteArray>()
override fun onSessionStarting() {}
override fun isG2SessionReady(): Boolean = g2Ready
override fun isG2AudioCaptureActive(): Boolean = packetListener != null
@@ -96,7 +95,6 @@ class VoiceCaptureSessionTest {
override fun embed(pcm16le: ByteArray, sampleRate: Int): FloatArray? = embedding
override fun release() {}
}
override fun recordingSink(): RecordingSink = RecordingSink { bytes, _ -> recordings.add(bytes) }
}
private val logs = mutableListOf<String>()
@@ -196,7 +194,6 @@ class VoiceCaptureSessionTest {
val session = session(host, platform, "voice-test-onboard")
session.setListener(events)
session.setUsePhoneMic(true)
session.setSaveRecordings(true)
session.start("onboard", 1)
assertTrue(events.stoppedLatch.await(10000))
assertTrue(mic.closed)
@@ -211,8 +208,6 @@ class VoiceCaptureSessionTest {
// Every segment handed to the model is at most 8 s and was peak-normalized.
assertTrue(transcriber.calls.all { it in 1..VoiceCaptureSession.TRANSCRIPT_SEGMENT_MAX_SAMPLES })
assertTrue(logs.any { it.startsWith("I Moonshine decode final=true") }, logs.toString())
assertEquals(1, host.recordings.size)
assertEquals(170 * 800 * 2, host.recordings[0].size)
assertEquals(170, events.pcmChunks.size)
assertEquals("x x", VoiceCaptureSession.joinTranscript("x", "x"))
assertEquals("x, y", VoiceCaptureSession.joinTranscript("x", ", y"))
+55 -11
View File
@@ -7,7 +7,7 @@ const { pcmLevel } = loader()('app/util/audio-level.ts');
function harness() {
const levelListeners = new Set();
let tick = null;
const { MicLevelMeter, paintListeningHeader } = loader({
const { MicLevelMeter, paintListeningHeader, RECORDING_ICON, withRecordingIcon } = loader({
setInterval(fn) { tick = fn; return 1; },
clearInterval() { tick = null; },
}, {
@@ -16,14 +16,15 @@ function harness() {
} },
})('app/ui/listening-header.ts');
const level = value => { for (const listener of levelListeners) listener(value); };
return { MicLevelMeter, paintListeningHeader, level, tick: () => tick?.(), ticking: () => tick !== null, levelListeners };
return { MicLevelMeter, paintListeningHeader, RECORDING_ICON, withRecordingIcon, level, tick: () => tick?.(), ticking: () => tick !== null, levelListeners };
}
/** Records draws; text is 6px per character, like a fixed-width bitmap face. */
function fakeImage(width = 576) {
const texts = [], rects = [];
return { width, texts, rects,
const texts = [], rects = [], images = [];
return { width, texts, rects, images,
drawText(_font, x, y, text, gray) { texts.push({ x, y, text, gray }); },
drawImage(source, x, y) { images.push({ source, x, y }); },
fillRect(x, y, w, h, gray) { rects.push({ x, y, w, h, gray }); } };
}
const font = { ascent: 12, lineHeight: 16, measureText: text => text.length * 6 };
@@ -81,20 +82,63 @@ test('the header puts title and status on one line, truncated before the meter',
const h = harness();
const meter = new h.MicLevelMeter();
const image = fakeImage(300);
const bodyTop = h.paintListeningHeader(image, font, 'Translate', 'Listening (ElevenLabs)...', meter);
assert.equal(bodyTop, 20 + 18 + 2);
assert.deepEqual(image.texts.map(({ x, y, gray }) => [x, y, gray]), [[24, 20, 200], [24 + 54, 20, 110]]);
// Inside the padding suggested for the window's edges: here a border at
// the top and left, blank space at the right.
const padding = { top: 8, right: 0, bottom: 8, left: 8 };
const bodyTop = h.paintListeningHeader(image, font, 'Translate', 'Listening (ElevenLabs)...', meter, padding);
assert.equal(bodyTop, 8 + 18 + 2);
assert.deepEqual(image.texts.map(({ x, y, gray }) => [x, y, gray]), [[8, 8, 200], [8 + 54, 8, 110]]);
assert.equal(image.texts[0].text, 'Translate');
const status = image.texts[1].text;
assert.ok(status.startsWith(' · Listening') && status.endsWith('...'), status);
const meterX = Math.min(...image.rects.map(rect => rect.x));
assert.equal(meterX, 300 - 24 - meter.width);
assert.ok(24 + 54 + status.length * 6 <= meterX - 10, 'status stops short of the meter');
assert.equal(meterX, 300 - meter.width, 'the meter ends at the unpadded right edge');
assert.ok(8 + 54 + status.length * 6 <= meterX - 10, 'status stops short of the meter');
// Segments sit on the text baseline.
assert.ok(image.rects.every(rect => rect.y + rect.h === 20 + font.ascent));
assert.ok(image.rects.every(rect => rect.y + rect.h === 8 + font.ascent));
assert.equal(image.images.length, 0, 'no recording circle unless the audio is being saved');
const idle = fakeImage(300);
h.paintListeningHeader(idle, font, 'Transcribe', 'Starting microphone...', null);
h.paintListeningHeader(idle, font, 'Transcribe', 'Starting microphone...', null, padding);
assert.equal(idle.rects.length, 0);
assert.equal(idle.texts[1].text, ' · Starting microphone...');
});
test('while the audio is being saved, the recording circle sits beside the meter', () => {
const h = harness();
const meter = new h.MicLevelMeter();
const image = fakeImage(300);
const padding = { top: 8, right: 0, bottom: 8, left: 8 };
h.paintListeningHeader(image, font, 'Translate', 'Listening (ElevenLabs)...', meter, padding, true);
const meterX = Math.min(...image.rects.map(rect => rect.x));
assert.equal(meterX, 300 - meter.width, 'the meter stays where it was');
assert.equal(image.images.length, 1);
const [circle] = image.images;
assert.equal(circle.source, h.RECORDING_ICON);
assert.equal(circle.x + circle.source.width + 4, meterX);
// Centred on the meter, whose 7 rows sit on the text baseline.
const meterTop = Math.min(...image.rects.map(rect => rect.y));
assert.equal(circle.y + circle.source.height / 2, meterTop + 7 / 2);
const status = image.texts[1].text;
assert.ok(8 + 54 + status.length * 6 <= circle.x - 10, 'status stops short of the circle');
// The mic isn't live (starting, or waiting for the glasses): nothing is being saved to mark.
const idle = fakeImage(300);
h.paintListeningHeader(idle, font, 'Transcribe', 'Starting microphone...', null, padding, true);
assert.equal(idle.images.length, 0);
});
test('a tray icon gains the recording circle to its right, vertically centred', () => {
const h = harness();
const { GrayImage } = loader()('app/graphics/image.ts');
const mic = new GrayImage(14, 15, 0);
mic.setPixel(0, 0, 200); mic.setPixel(13, 14, 200);
const icon = h.withRecordingIcon(mic);
assert.deepEqual([icon.width, icon.height], [14 + 2 + 9, 15]);
assert.deepEqual([icon.getPixel(0, 0), icon.getPixel(13, 14)], [200, 200]);
assert.deepEqual([icon.getPixel(14, 7), icon.getPixel(15, 7)], [0, 0], 'a gap separates them');
// The circle's widest row is the icon's middle row; its corners are clear.
for (let x = 16; x < 25; x++) assert.equal(icon.getPixel(x, 7), 220);
assert.deepEqual([icon.getPixel(16, 3), icon.getPixel(20, 3), icon.getPixel(20, 2), icon.getPixel(20, 12)], [0, 220, 0, 0]);
});
+34
View File
@@ -75,6 +75,40 @@ test('scrolling keeps the selection and its neighbors visible and aligns the vie
assert.equal(menu.scrollTop, 0);
});
test('padTop and padBottom are blank rows inside the scrolled content, shown only at its ends', async () => {
// A box that runs to a window's edges: 8px of padding scrolls with the rows.
const box = { x: 10, y: 5, width: 80, height: 60, padTop: 8, padBottom: 8 };
const { menu, paint, image } = stringMenu();
const step = async (type) => { await menu.handleInput({ type }); paint(true, box); return menu.scrollTop; };
const rows = paint(true, box);
assert.equal(menu.scrollTop, 0);
assert.equal(rows[1].y, 5 + 8 + 20, 'rows start below the padding');
assert.equal(menu.indexAt(5 + 4), null, 'the padding is no row');
assert.equal(menu.indexAt(5 + 8), 0);
assert.equal(menu.overflows, true);
// Rows scrolled off are cut at the box's edge: the viewport rests on a row
// top, without the padding, until the first row comes back.
assert.equal(await step('scroll-down'), 0);
assert.equal(await step('scroll-down'), 28, 'b sits right at the top edge');
assert.equal(menu.indexAt(5), 1);
assert.equal(await step('scroll-down'), 28);
assert.equal(await step('scroll-down'), 68, 'the last row shows with the padding under it');
assert.equal(menu.selectedIndex, 4);
assert.equal(await step('scroll-up'), 68);
assert.equal(await step('scroll-up'), 28);
assert.equal(await step('scroll-up'), 28);
assert.equal(await step('scroll-up'), 0, 'back at the first row, its padding shows again');
// Content that fits just sits below the top padding.
const short = stringMenu({ items: ['a', 'b'] });
const drawn = short.paint(true, box);
assert.equal(short.menu.overflows, false);
assert.equal(drawn[1].y, 5 + 8 + 20);
// A scrollbar spans the padded content.
const before = image.pixels.slice();
menu.drawScrollbar(image, 95, 5, 60);
assert.ok(image.pixels.some((value, index) => value !== before[index]));
});
test('without wrap the ends call the exit callbacks and hold the selection', async () => {
const { menu, exits } = stringMenu();
await menu.handleInput({ type: 'scroll-up' });
+15 -3
View File
@@ -50,6 +50,7 @@ test('later opaque planes add an occlusion to a replayed selection',()=>{
});
const {LayerStack,noopLayerActions}=load('app/ui/layers.ts',{
'./viewport':require('../.test-build/app/ui/viewport.js'),
'../graphics/image':graphics,'../graphics/plane':planes,'../native/frame-timings':{spanCurrent:(_name,fn)=>fn()},'../graphics/screen-size':{screenWidth:()=>640,screenHeight:()=>480},'./gestures':{},
});
test('context menu surface and selected row both use +4 without changing the app screen',()=>{
@@ -121,7 +122,9 @@ test('unselected sidebar icons retain -2 depth through shell cropping, including
});
test('shell modal carries its inner menu highlight animation instead of baking its first frame',async()=>{
const {ShellModalLayer}=load('app/ui/shell/modal-layer.ts',{
'../viewport':require('../.test-build/app/ui/viewport.js'),
'../../graphics/image':graphics,'../../graphics/display-list':require('../.test-build/app/graphics/display-list.js'),'../../graphics/plane':planes,'../gestures':{},'../layers':load('app/ui/layers.ts',{
'./viewport':require('../.test-build/app/ui/viewport.js'),
'../graphics/image':graphics,'../graphics/plane':planes,'../native/frame-timings':{spanCurrent:(_name,fn)=>fn()},'../graphics/screen-size':{screenWidth:()=>640,screenHeight:()=>480},
'./gestures':{isDirectionalInput:()=>false},
}),
@@ -147,6 +150,7 @@ test('a stack without its own size follows the screen when the glasses type chan
// RayNeo iO must not leave its overlays painting on a 540x220 canvas.
const screen={width:540,height:220};
const {LayerStack}=load('app/ui/layers.ts',{
'./viewport':require('../.test-build/app/ui/viewport.js'),
'../graphics/image':graphics,'../graphics/plane':planes,'../native/frame-timings':{spanCurrent:(_name,fn)=>fn()},
'../graphics/screen-size':{screenWidth:()=>screen.width,screenHeight:()=>screen.height},'./gestures':{},
});
@@ -156,10 +160,18 @@ test('a stack without its own size follows the screen when the glasses type chan
const sizes=()=>JSON.parse(JSON.stringify(stack.paint().map(p=>[p.image.width,p.image.height])));
assert.deepEqual(sizes(),[[540,220],[540,220]]);
screen.width=640;screen.height=480;
assert.deepEqual({...stack.getBaseSize()},{width:640,height:480});
const plain=value=>JSON.parse(JSON.stringify(value));
const unbordered={edges:{top:'offscreen',right:'offscreen',bottom:'offscreen',left:'offscreen'},padding:{top:0,right:0,bottom:0,left:0}};
assert.deepEqual(plain(stack.getBaseSize()),{width:640,height:480,...unbordered});
assert.deepEqual(sizes(),[[640,480],[640,480]]);
// An explicit size (a window's viewport, the modal's interior) stays put.
// An explicit size (a window's viewport, the modal's interior) stays put;
// given bare, nothing borders it, so it suggests no padding.
const sized=new LayerStack({paint:()=>new graphics.GrayImage(100,90,0)},noopLayerActions,{width:100,height:90});
screen.width=540;screen.height=220;
assert.deepEqual({...sized.getBaseSize()},{width:100,height:90});
assert.deepEqual(plain(sized.getBaseSize()),{width:100,height:90,...unbordered});
// A host that says what its edges touch hands layers the padding for them.
const viewport=require('../.test-build/app/ui/viewport.js');
const edges={top:'border',right:'offscreen',bottom:'offscreen',left:'border'};
sized.setBaseSize(viewport.viewportWith({width:100,height:90},edges));
assert.deepEqual(plain(sized.getBaseSize()),{width:100,height:90,edges,padding:{top:8,right:0,bottom:0,left:8}});
});
+1 -1
View File
@@ -200,7 +200,7 @@ test('SettingsPanel labels animate only in the focused column', async () => {
});
const layer = new SettingsPanelLayer([{ label: 'very long section label beyond column width',
items: [{ label: 'very long option label beyond the right column width', onSelect() {} }] }]);
const ctx = { stack: { getBaseSize: () => ({ width: 360, height: 100 }), isFocused: () => true } };
const ctx = { stack: { getBaseSize: () => require('./helpers/viewport.cjs').bordered(360, 100), isFocused: () => true } };
const left = lists(layer.paint(ctx));
assert.equal(left.length, 1);
assert.ok(left[0].x < 150);
+2 -1
View File
@@ -1,5 +1,6 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { bordered } = require('./helpers/viewport.cjs');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
@@ -177,7 +178,7 @@ test('Music settings keeps toggles and selection when a new app arrives and supp
};
const { MusicSettingsLayer } = load('app/apps/music/music-settings.ts', (name) => uiDeps[name]);
const layer = new MusicSettingsLayer();
const ctx = { stack: { getBaseSize: () => ({ width: 540, height: 224 }), isFocused: () => true, pop: () => closes++ } };
const ctx = { stack: { getBaseSize: () => bordered(540, 224), isFocused: () => true, pop: () => closes++ } };
const paint = () => layer.paint(ctx, () => new RecordingImage(540, 224));
const input = (type) => layer.handleInput({ type }, ctx);
assert.equal(refreshes, 1);
+23 -8
View File
@@ -5,6 +5,7 @@ const vm = require('node:vm');
const ts = require('typescript');
const path = require('node:path');
const { loader } = require('./helpers/load-typescript.cjs');
const { bordered, unbordered, edged } = require('./helpers/viewport.cjs');
const flush = () => new Promise(resolve => setImmediate(resolve));
const route = { coordinates: [[-122.4, 37.7], [-122.4, 37.71]], distanceMeters: 1112, durationSec: 600,
@@ -13,7 +14,7 @@ const route = { coordinates: [[-122.4, 37.7], [-122.4, 37.71]], distanceMeters:
const fix = latitude => ({ latitude, longitude: -122.4, timestampMs: Date.now(), bearingDeg: 0, speedMps: 1.5, accuracyMeters: 5 });
function fixture() {
const messages = [], timers = new Set(), timeouts = new Set(), holds = [], maps = [], errors = [], requests = [];
let callbacks, compass, delayRoute = null, delayMap = null, routeError = null, distanceUnit = 'miles', timeFormat = '24h';
let callbacks, compass, delayRoute = null, delayMap = null, routeError = null, distanceUnit = 'miles', timeFormat = '24h', paints = 0;
const routeMath = loader()('app/apps/navigate/route-follower.ts');
const tracker = { running: false, isRunning() { return this.running; }, start() { this.running = true; }, stop() { this.running = false; } };
const sensor = { LocationTracker: function (value) { callbacks = value; return tracker; }, COMPASS_CHANGED: 15,
@@ -22,7 +23,8 @@ function fixture() {
handleNavigationSensorEvent: event => { if (event.kind === 'location') callbacks.onLocation(event.location); } };
const modules = {
'@nativescript/core/globals': {},
'../../graphics/bdffont': { getFont: () => ({}) }, '../../graphics/ui-fonts': { getDefaultSmallFont: () => ({}) },
// The footer hint's line height sets how much of the window the map-mode map gets.
'../../graphics/bdffont': { getFont: () => ({}) }, '../../graphics/ui-fonts': { getDefaultSmallFont: () => ({ lineHeight: 12 }) },
'../../native/settings-store': { onSettingsStoreChanged() {} },
'../../ui/dashboard-settings': { distanceUnitSetting: { get: () => distanceUnit } },
'../../ui/clock-format': loader({}, { './dashboard-settings': { timeFormatSetting: { get: () => timeFormat } } })('app/ui/clock-format.ts'),
@@ -34,7 +36,8 @@ function fixture() {
'../../native/frame-timings': { startFrame: () => 1, finishFrame() {}, logFrame() {}, span: (_id, _name, fn) => fn(), runWithFrame: (_id, fn) => fn() },
'../../native/active-display': { getActiveDisplay: () => null },
'../../ui/menu-core': require('../.test-build/app/ui/menu-core.js'),
'../../ui/window-menu': { WindowMenu: class { paint() { return []; } isOpen() { return false; } resize() {} } },
'../../ui/window-menu': { WindowMenu: class { paint() { paints++; return []; } isOpen() { return false; } resize() {} } },
'../../ui/viewport': require('../.test-build/app/ui/viewport.js'),
'../../graphics/plane': { planesFingerprint: () => 'frame' },
'../../native/mapbox': {
isMapboxConfigured: () => true,
@@ -54,9 +57,9 @@ function fixture() {
console: { log() {}, warn() {}, error: error => errors.push(error) }, require: id => modules[id] ?? {},
});
const send = data => global.onmessage({ data });
send({ type: 'open-window', windowId: 'navigate:main', surfaceId: 'window:navigate:main', title: 'Navigate', viewport: { width: 576, height: 480 } });
send({ type: 'open-window', windowId: 'navigate:main', surfaceId: 'window:navigate:main', title: 'Navigate', viewport: bordered(576, 480) });
send({ type: 'foreground', windowId: 'navigate:main', foreground: true, focused: true });
return { ...exports.probe, send, timers, holds, maps, errors, tracker, requests,
return { ...exports.probe, send, timers, holds, maps, errors, tracker, requests, paints: () => paints,
input: type => send({ type: 'input', windowId: 'navigate:main', focused: true, frameId: 1, event: { type } }),
tick: () => { for (const callback of timers) callback(); },
expireFix: () => { for (const callback of timeouts) callback(); timeouts.clear(); },
@@ -114,8 +117,9 @@ test('front page map entry follows location without routing, supports zoom and r
h.fix(37.7); await flush();
assert.equal(h.state().phase, 'map');
assert.deepEqual(h.requests, []);
// The map fills the window down to the footer hint, which rests on the bottom padding.
assert.equal(h.maps.at(-1).width, 576);
assert.equal(h.maps.at(-1).height, 450);
assert.equal(h.maps.at(-1).height, 452);
assert.equal(h.maps.at(-1).routePath, undefined);
assert.equal(h.maps.at(-1).camera.latitude, 37.7);
assert.equal(h.maps.at(-1).camera.bearingDeg, 0);
@@ -147,9 +151,20 @@ test('map suspends fetching and compass while hidden and resizes to the viewport
assert.equal(h.holds.at(-1), false);
h.send({ type: 'screen', on: true }); await flush();
assert.equal(h.maps.at(-1).camera.latitude, 37.71);
h.send({ type: 'resize-window', windowId: 'navigate:main', viewport: { width: 540, height: 260 } }); await flush();
const resize = async viewport => { h.send({ type: 'resize-window', windowId: 'navigate:main', viewport }); await flush(); };
await resize(bordered(540, 260));
assert.equal(h.maps.at(-1).width, 540);
assert.equal(h.maps.at(-1).height, 230);
assert.equal(h.maps.at(-1).height, 232);
// With no border below, the footer hint moves down to the edge and the map follows it.
await resize(edged(540, 260, 'top', 'left'));
assert.equal(h.maps.at(-1).height, 240);
// A change to the other edges lays the window out again, but keeps the map it has.
const fetched = h.maps.length, painted = h.paints();
await resize(unbordered(540, 260));
assert.equal(h.maps.length, fetched);
assert.equal(h.paints(), painted + 1);
await resize(unbordered(540, 260));
assert.equal(h.paints(), painted + 1);
h.send({ type: 'close-window' });
assert.equal(h.tracker.running, false);
assert.equal(h.timers.size, 0);
+42 -4
View File
@@ -4,6 +4,7 @@ const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ts = require('typescript');
const { bordered, unbordered, edged } = require('./helpers/viewport.cjs');
const alerts = require('../.test-build/app/apps/nightscout/nightscout-alerts.js');
const detector = require('../.test-build/app/apps/nightscout/missed-bolus-detector.js');
const now = 1_800_000_000_000;
@@ -53,6 +54,7 @@ class Image {
drawText(font, ...args) { this.draws.push(['text', ...args]); }
drawLine(...args) { this.draws.push(['line', ...args]); }
fillRect(...args) { this.draws.push(['rect', ...args]); }
drawRect(...args) { this.draws.push(['frame', ...args]); }
}
const font = { measureText: text => text.length * 6, lineHeight: 12, hasGlyph: () => true };
@@ -197,17 +199,22 @@ test('tray keeps every pixel row when a TTF font measures the reading fractional
}
});
test('main page highlights only the breached field and removes highlights on recovery', () => {
const f = fixture();
const page = load('app/apps/nightscout/nightscout.ts', {
/** nightscout.ts (the app window's page) over a fixture's bridge and settings. */
function loadMainPage(f) {
return load('app/apps/nightscout/nightscout.ts', {
...f.deps,
'../../graphics/textwrap': { truncateText: (font, text) => text },
'../../ui/gestures': {}, '../../ui/layers': {}, '../../ui/menu': {},
'../../ui/dashboard/settings-panel': {}, '../../ui/metrics': { lineStep: () => 16 },
'~/util/date-util': { formatAgeShortFromTimestamp: () => '1m', formatTimestamp: () => '12:00' },
}, { Date: { now: () => now } });
}
test('main page highlights only the breached field and removes highlights on recovery', () => {
const f = fixture();
const page = loadMainPage(f);
const layer = new page.NightscoutLayer();
const paint = () => layer.paint({ stack: { getBaseSize: () => ({ width: 576, height: 260 }) } });
const paint = () => layer.paint({ stack: { getBaseSize: () => bordered(576, 260) } });
for (const [field, value, label] of [['reservoirUnits', 10, '10U'], ['batteryVoltage', 1, '1.00V'], ['cageTimestampMs', now - 73 * 3_600_000, 'CAGE 1m'], ['loopTimestampMs', now - 16 * 60_000, 'Loop 1m']]) {
f.state[field] = value;
const image = paint();
@@ -219,6 +226,37 @@ test('main page highlights only the breached field and removes highlights on rec
}
});
test('main page puts its title, readout and graph at the padding suggested for each edge', () => {
const f = fixture();
Object.assign(f.state, { history: [{ timestampMs: now - 60_000, sgv: 120 }], basal: [], carbs: [], boluses: [] });
const layer = new (loadMainPage(f).NightscoutLayer)();
const paint = viewport => layer.paint({ stack: { getBaseSize: () => viewport } }).draws;
const texts = draws => draws.filter(d => d[0] === 'text');
const graph = draws => draws.find(d => d[0] === 'frame').slice(1, 5);
// A border on every edge: 8px in from each. The caption is the last line above the bottom padding.
const framed = paint(bordered(576, 260));
assert.deepEqual(texts(framed)[0].slice(1, 4), [8, 8, 'Nightscout']);
assert.deepEqual(texts(framed)[1].slice(1, 4), [8, 64, '100'], 'readout, centered between the title (to y=20) and the graph (from y=120)');
assert.deepEqual(graph(framed), [8, 120, 560, 114]);
assert.deepEqual(texts(framed).at(-1).slice(1, 3), [8, 240]);
// No borders: the page runs to the window's edges and the graph takes the room.
const bare = paint(unbordered(576, 260));
assert.deepEqual(texts(bare)[0].slice(1, 3), [0, 0]);
assert.deepEqual(graph(bare), [0, 112, 576, 130]);
assert.deepEqual(texts(bare).at(-1).slice(1, 3), [0, 248]);
// Each edge is padded on its own.
assert.deepEqual(graph(paint(edged(576, 260, 'top', 'left'))), [8, 120, 568, 122]);
assert.deepEqual(graph(paint(edged(576, 260, 'bottom', 'right'))), [0, 112, 568, 122]);
// A window too short for the graph and its caption gives the graph the caption's room, inside the image.
const short = paint(bordered(476, 155));
assert.deepEqual(graph(short), [8, 120, 460, 27]);
assert.ok(!texts(short).some(d => /glucose history/.test(d[3])));
});
test('bridge exposes numeric measurements and treats absent values as unknown', async () => {
let pump = { reservoir: '10.5', battery: { voltage: '1.15' } };
const module = load('app/native/nightscout-bridge.ts', {
+3 -1
View File
@@ -131,7 +131,9 @@ test('notification mask follows resize, band position and restore without coveri
assert.equal(frame.getPixel(rect.x + 10, rect.y + 10), 240);
assert.ok(!frame.pixels.includes(200), 'no app pixels survive');
assert.equal(layers[0].height, rect.height);
assert.deepEqual({ ...f.innerSize() }, { width: rect.width - 8, height: rect.height - 8 });
const inner = f.innerSize();
assert.deepEqual({ ...inner, edges: { ...inner.edges }, padding: { ...inner.padding } },
{ ...require('./helpers/viewport.cjs').bordered(rect.width - 8, rect.height - 8) });
}
});
+2 -1
View File
@@ -1,5 +1,6 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { bordered } = require('./helpers/viewport.cjs');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
@@ -135,7 +136,7 @@ function ui(fontSize = 12) {
dependencies['./menu'] = load('app/ui/menu.ts', requireModule);
const { SingleNotificationLayer } = load('app/ui/notifications.ts', requireModule);
const { NotificationFilterLayer } = load('app/ui/notification-filter.ts', requireModule);
const ctx = { stack: { getBaseSize: () => ({ width: 540, height: 224 }), isFocused: () => true, pop: () => closes++ } };
const ctx = { stack: { getBaseSize: () => bordered(540, 224), isFocused: () => true, pop: () => closes++ } };
const popup = new SingleNotificationLayer('key', { origin: 'new-notification-modal', onClose: () => closes++ });
const trayCloses = [];
const tray = new SingleNotificationLayer('key', { origin: 'notification-tray', onClose: (_ctx, gone) => trayCloses.push(gone) });
-40
View File
@@ -88,46 +88,6 @@ test('iOS registers the devices page, which it cannot resolve otherwise', () =>
assert.match(source, /registerModule\('phone-ui\/onboarding-devices-page\.xml', /);
});
test('choosing glasses selects exactly one, and the accessories are stored', () => {
const { state, loadPage } = fixture();
const { OnboardingDevicesViewModel } = loadPage('onboarding-devices-view-model');
const model = new OnboardingDevicesViewModel();
assert.equal(model.glassesOptions.map(option => option.choice).join(), 'preview,g1,g2');
// Nothing is chosen until you choose, even with a stored glasses type, and Next waits for it.
assert.equal(selected(model), '');
assert.equal(model.nextEnabled, false);
model.onNextTap();
assert.equal(state.navigations.length, 0);
tap(model, 'g1');
assert.equal(state.glasses, 'g1');
assert.equal(selected(model), 'g1');
assert.equal(model.nextEnabled, true);
assert.equal(model.hasRing, false);
model.hasRing = true;
model.hasWatch = true;
assert.equal(state.ring, true);
assert.equal(state.watch, true);
assert.equal(new OnboardingDevicesViewModel().hasRing, true);
});
test('the watch follows the platform, and unreleased RayNeo iO is hidden on both platforms', () => {
const android = fixture();
const onAndroid = new (android.loadPage('onboarding-devices-view-model').OnboardingDevicesViewModel)();
assert.equal(onAndroid.watchLabel, 'Wear OS watch');
assert.equal(rowFor(onAndroid, 'rayneo-io'), undefined);
const ios = fixture({ ios: true });
const onIos = new (ios.loadPage('onboarding-devices-view-model').OnboardingDevicesViewModel)();
assert.equal(onIos.watchLabel, 'Apple Watch');
assert.equal(rowFor(onIos, 'rayneo-io'), undefined);
assert.equal(ios.state.glasses, 'g2');
assert.equal(selected(onIos), '');
assert.equal(onIos.nextEnabled, false);
});
test('the disclaimer and firmware steps name only the chosen glasses', () => {
const copy = glasses => {
const { OnboardingViewModel } = fixture({ glasses }).loadPage('onboarding-view-model');
+38 -4
View File
@@ -1,6 +1,7 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
const { bordered, unbordered } = require('./helpers/viewport.cjs');
// Roboto's line heights at the onboarding sizes, and a fixed advance.
const FONTS = { title: 31, body: 24, detail: 19, hero: 52 };
@@ -53,7 +54,8 @@ test('the layout page fits four 40%-wide diagrams with captions on the immersive
const page = new LayoutPage();
assert.equal(page.immersive, true);
const image = recorder(640, 480);
page.paint(image, true);
// An immersive page's edges are the screen's: no padding.
page.paint(image, true, unbordered(640, 480).padding);
// Each diagram's outline spans the display's width at 40%.
const areas = image.calls.filter((call) => call.kind === 'outline' && call.w === 256);
assert.equal(areas.length, 4);
@@ -79,6 +81,16 @@ test('the layout page fits four 40%-wide diagrams with captions on the immersive
// Bottom, recommended, is the selected cell at first, filled while focused.
const box = image.calls.find((call) => call.kind === 'fill' && call.value === 15);
assert.ok(box.x <= areas[0].x && box.y <= areas[0].y && box.y + box.h >= bottom.y);
// With nothing bordering the page, its title sits 10px in (where list rows' text starts) and 2px down.
const title = text('Layout')[0];
assert.deepEqual([title.x, title.y], [10, 2]);
// Beside border lines the heading keeps their padding, and the grid stays centred.
const framed = recorder(640, 480);
page.paint(framed, true, bordered(640, 480).padding);
const framedTitle = framed.calls.find((call) => call.kind === 'text' && call.text === 'Layout');
assert.deepEqual([framedTitle.x, framedTitle.y], [18, 10]);
const framedAreas = framed.calls.filter((call) => call.kind === 'outline' && call.w === 256);
assert.deepEqual(framedAreas.map((area) => area.x), areas.map((area) => area.x));
});
test('the layout page starts on Bottom whatever is set, swipes in reading order, and a tap saves the choice', () => {
@@ -137,12 +149,24 @@ test('the text size page offers 12 to 18px, starts on the recommended 16px, and
assert.deepEqual(rows.filter((texts) => texts.length > 1).length, 1);
// The size column holds the note; the preview is paragraphs of text, no menu.
const image = recorder(640, 480);
page.paint(image, true);
page.paint(image, true, unbordered(640, 480).padding);
assert.ok(menu.box.width >= 10 + '16 px'.length * 8 + 8 + 'Recommended'.length * 8);
const preview = image.calls.filter((call) => call.kind === 'text' && call.x > menu.box.x + menu.box.width);
assert.equal(preview[0].text.startsWith('This is how text will look'), true);
assert.ok(preview.length > 3);
assert.equal(image.calls.some((call) => call.kind === 'text' && call.text === 'Timers'), false);
// Unpadded, the size list starts at the window's left edge and the preview's frame reaches its right and bottom edges.
const frame = image.calls.find((call) => call.kind === 'outline');
assert.equal(menu.box.x, 0);
assert.deepEqual([frame.x + frame.w, frame.y + frame.h], [640, 480]);
// The list scrolls, so it runs to the bottom edge whatever borders it, the edge's padding inside it.
assert.deepEqual([menu.box.y + menu.box.height, menu.box.padBottom], [480, 0]);
const framed = recorder(640, 480);
page.paint(framed, true, bordered(640, 480).padding);
const paddedFrame = framed.calls.find((call) => call.kind === 'outline');
assert.equal(menu.box.x, 8);
assert.deepEqual([paddedFrame.x + paddedFrame.w, paddedFrame.y + paddedFrame.h], [632, 472]);
assert.deepEqual([menu.box.y + menu.box.height, menu.box.padBottom], [480, 8]);
// A tap saves; coming back keeps the size chosen.
page.handleInput({ type: 'scroll-up' }, { next: () => {} });
page.handleInput({ type: 'click' }, { next: () => {} });
@@ -186,7 +210,7 @@ test('on a RayNeo iO the layout page recommends and starts on Left, and fits the
assert.equal(recommendedLayout(), 'left');
const page = new LayoutPage();
const image = recorder(540, 220);
page.paint(image, true);
page.paint(image, true, unbordered(540, 220).padding);
const captions = image.calls.filter((call) => call.kind === 'text').map((call) => call.text);
assert.ok(captions.includes('Left (Recommended)'));
assert.ok(captions.includes('Bottom'));
@@ -289,9 +313,19 @@ test('the display mode page offers Full Screen only where the layout allows it,
assert.equal(menu.selectedItem, 'fullscreen');
// The selected mode's description sits beside the list, within the window (a band's).
const image = recorder(576, 260);
page.paint(image, true);
page.paint(image, true, bordered(576, 260).padding);
const description = image.calls.filter((call) => call.kind === 'text' && call.x >= menu.box.x + menu.box.width);
assert.match(description.map((call) => call.text).join(' '), /Depth is turned off/);
// Beside border lines: the title at the UI-wide (18, 10), the list's rows from the padding, the list to the bottom edge.
const title = (calls) => calls.find((call) => call.kind === 'text' && call.text === 'Display mode');
assert.deepEqual([title(image.calls).x, title(image.calls).y], [18, 10]);
assert.deepEqual([menu.box.x, menu.box.y + menu.box.height, menu.box.padBottom], [8, 260, 8]);
assert.ok(description.every((call) => call.x + call.text.length * 8 <= 576 - 18 && call.y + FONTS.detail <= 260 - 8));
// With no border on the left or bottom, the page runs to those edges.
const open = recorder(576, 260);
page.paint(open, true, { top: 8, right: 8, bottom: 0, left: 0 });
assert.deepEqual([title(open.calls).x, title(open.calls).y], [10, 10]);
assert.deepEqual([menu.box.x, menu.box.y + menu.box.height, menu.box.padBottom], [0, 260, 0]);
let next = 0;
const nav = { next: () => next++ };
page.handleInput({ type: 'scroll-up' }, nav);
+170
View File
@@ -0,0 +1,170 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
const NO_LEVELS = { headset: null, headsetCharging: null, case: null, caseCharging: null, ring: null, ringCharging: null };
function fixture() {
let brightness = '40', mode = 'small', style = 'watch', picked, levels = { ...NO_LEVELS };
const changes = [], writes = [], back = [];
const settingListeners = new Set(), batteryListeners = new Set();
const subscribe = listeners => fn => { listeners.add(fn); return () => listeners.delete(fn); };
class Observable {
notifyPropertyChange(name, value) { changes.push([name, value]); }
}
const settings = {
brightnessSetting: { get: () => brightness, set: value => { brightness = value; writes.push(value); } },
displayLayoutSetting: { get: () => mode, set: value => { mode = value; }, values: ['small', 'large', 'huge'],
isDisabled: value => value === 'huge', displayValue(value = mode) { return value[0].toUpperCase() + value.slice(1); } },
phoneInputStyleSetting: { get: () => style, set: value => { style = value; } },
glassesModelName: () => 'G2',
onAnySettingChanged: subscribe(settingListeners),
};
// glasses-display-state and glasses-presence are pure, so the real ones load.
const load = loader({}, {
'@nativescript/core': { Observable, Dialogs: { action: async () => picked }, Frame: { topmost: () => ({ goBack: () => back.push(true) }) } },
'../ui/dashboard-settings': settings,
'../ui/shell/shell': { shell: { getBatteryLevels: () => levels, onBatteryLevelsChanged: subscribe(batteryListeners) } },
});
const { SettingsViewModel } = load('app/phone-ui/settings-view-model.ts');
const presence = load('app/g2/glasses-presence.ts');
return { model: new SettingsViewModel(), changes, writes, back, presence, settingListeners, batteryListeners,
brightness: () => brightness, mode: () => mode, style: () => style, pick: value => { picked = value; },
setLevels: next => { levels = { ...NO_LEVELS, ...next }; for (const fn of batteryListeners) fn(); },
changeElsewhere: fn => { fn({ setBrightness: value => { brightness = value; }, setStyle: value => { style = value; } });
for (const listener of settingListeners) listener(); } };
}
test('brightness controls snap manual levels and restore the manual value after Auto', () => {
const h = fixture();
h.model.onBrightnessChange({ value: 76 });
assert.equal(h.brightness(), '80');
h.model.onBrightnessAutoChange({ value: true });
assert.equal(h.brightness(), 'auto');
assert.equal(h.model.brightnessSliderEnabled, false);
h.model.onBrightnessChange({ value: 10 });
assert.equal(h.brightness(), 'auto');
h.model.onBrightnessAutoChange({ value: false });
assert.equal(h.brightness(), '80');
h.model.onBrightnessChange({ value: -10 });
assert.equal(h.brightness(), '2');
h.model.onBrightnessChange({ value: NaN });
assert.equal(h.brightness(), '2');
});
test('display-mode picker preserves cancellation and applies the selected mode', async () => {
const h = fixture();
h.pick('Cancel'); await h.model.onDisplayModeTap();
assert.equal(h.mode(), 'small');
// Unavailable modes (Full Screen beside a side strip) are not offered.
h.pick('Huge'); await h.model.onDisplayModeTap();
assert.equal(h.mode(), 'small');
h.pick('Large'); await h.model.onDisplayModeTap();
assert.equal(h.mode(), 'large');
assert.equal(h.model.displayModeLabel, 'Large ▾');
});
test('Phone input style picks the pad, marks the chosen button and explains it', () => {
const h = fixture();
assert.match(h.model.watchStyleClass, /segment-button-selected/);
assert.doesNotMatch(h.model.ringStyleClass, /selected/);
const watchHint = h.model.phoneInputStyleHint;
h.model.onWatchStyleTap();
assert.deepEqual(h.changes, [], 'picking the current style changes nothing');
h.model.onRingStyleTap();
assert.equal(h.style(), 'ring');
assert.match(h.model.ringStyleClass, /segment-button-selected/);
assert.doesNotMatch(h.model.watchStyleClass, /selected/);
assert.notEqual(h.model.phoneInputStyleHint, watchHint);
// Updated at once, without waiting for the store's own (next-tick) notification.
assert.deepEqual(h.changes.map(change => change[0]), ['watchStyleClass', 'ringStyleClass', 'phoneInputStyleHint']);
});
test('the page follows changes made on the glasses only while it is on screen', () => {
const h = fixture();
assert.equal(h.settingListeners.size, 0, 'nothing is subscribed before the page loads');
h.model.attach(); h.model.attach();
assert.equal(h.settingListeners.size, 1); assert.equal(h.batteryListeners.size, 1);
h.changes.length = 0;
h.changeElsewhere(remote => { remote.setBrightness('auto'); remote.setStyle('ring'); });
const changed = Object.fromEntries(h.changes);
assert.equal(changed.brightnessAuto, true);
assert.equal(changed.brightnessSliderEnabled, false);
assert.match(changed.ringStyleClass, /segment-button-selected/);
assert.ok('displayModeLabel' in changed);
h.model.detach();
assert.equal(h.settingListeners.size, 0); assert.equal(h.batteryListeners.size, 0);
// Coming back (an app resume, or returning to the page) catches up.
h.changeElsewhere(remote => remote.setBrightness('60'));
h.changes.length = 0; h.model.attach();
assert.equal(Object.fromEntries(h.changes).brightnessPercent, 60);
h.model.detach();
});
test('the battery row hides until a level is known and marks charging only over a live link', () => {
const h = fixture();
h.model.attach();
assert.equal(h.model.batteryLineVisibility, 'collapse');
h.setLevels({ headset: 90, headsetCharging: true, ring: 72 });
assert.equal(h.model.batteryLine, 'G2 90% · R1 72%');
assert.equal(h.model.batteryLineVisibility, 'visible');
h.changes.length = 0;
h.presence.updateGlassesPresence({ connected: true });
assert.equal(h.model.batteryLine, 'G2 90% ⚡ · R1 72%');
assert.deepEqual(h.changes.map(change => change[0]), ['batteryLine', 'batteryLineVisibility']);
h.model.detach();
h.presence.updateGlassesPresence({ connected: false });
assert.equal(h.model.batteryLine, 'G2 90% ⚡ · R1 72%', 'a detached page is not updated');
h.model.attach();
assert.equal(h.model.batteryLine, 'G2 90% · R1 72%');
h.model.detach();
});
test('the back arrow pops the settings page', () => {
const h = fixture();
h.model.onBackTap();
assert.deepEqual(h.back, [true]);
});
test('the settings page binds every row the view model serves and is registered for iOS', () => {
const fs = require('node:fs'), path = require('node:path');
const read = file => fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
const xml = read('app/phone-ui/settings-page.xml');
for (const binding of ['displayModeLabel', 'onDisplayModeTap', 'brightnessAuto', 'onBrightnessAutoChange', 'brightnessPercent',
'onBrightnessChange', 'brightnessSliderEnabled', 'watchStyleClass', 'ringStyleClass', 'onWatchStyleTap', 'onRingStyleTap',
'phoneInputStyleHint', 'batteryLine', 'batteryLineVisibility', 'onBackTap']) {
assert.ok(xml.includes(`{{ ${binding} }}`), `settings-page.xml binds ${binding}`);
}
// iOS skips webpack's automatic page discovery, and loads app.ios.css instead of app.css.
const register = read('app/phone-ui/onboarding-register.ios.ts');
assert.match(register, /registerModule\('phone-ui\/settings-page', /);
assert.match(register, /registerModule\('phone-ui\/settings-page\.xml', /);
for (const css of ['app/app.css', 'app/app.ios.css']) assert.match(read(css), /@import '\.\/phone-ui\/settings-page\.css';/);
});
test('Phone input style is a stored setting, Watch by default, also offered in the glasses Settings app', () => {
const fs = require('node:fs'), path = require('node:path'), vm = require('node:vm'), ts = require('typescript');
const read = file => fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
// The real setting object, over an in-memory settings store.
const store = new Map(), sandbox = { exports: {}, global: { isIOS: false }, setTimeout: fn => fn(),
require: id => id.includes('settings-store') ? { onSettingsStoreChanged() {},
getStringSetting: (key, fallback) => store.get(key) ?? fallback, setStringSetting: (key, value) => store.set(key, value),
getBooleanSetting: (key, fallback) => store.get(key) ?? fallback, setBooleanSetting: (key, value) => store.set(key, value) }
: { Layer: class {}, ASSISTANT_MODEL_CHOICES: [], TRANSCRIPTION_LANGUAGES: {} } };
vm.runInNewContext(ts.transpileModule(read('app/ui/dashboard-settings.ts'),
{ compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 } }).outputText, sandbox);
const setting = sandbox.exports.phoneInputStyleSetting;
assert.equal(setting.label, 'Phone input style');
assert.equal(setting.get(), 'watch');
assert.deepEqual([...setting.values].map(value => setting.displayValue(value)), ['Watch', 'Ring']);
setting.set('ring');
assert.equal(store.get('phone.inputStyle'), 'ring');
assert.equal(setting.get(), 'ring');
store.set('phone.inputStyle', 'settings');
assert.equal(setting.get(), 'watch', 'an unknown stored value reads as the default');
// The on-glasses Settings app lists it with the other phone-screen settings.
const menus = read('app/ui/dashboard/settings-menus.ts');
const section = menus.slice(menus.indexOf('label: "Phone display"'), menus.indexOf('label: "Watch"'));
assert.match(section, /enumSettingMenuItem\(phoneInputStyleSetting\)/);
});
+61 -45
View File
@@ -3,62 +3,78 @@ const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
function fixture() {
let brightness = '40', mode = 'small', picked;
const changes = [], writes = [];
let style = 'watch';
const changes = [], navigations = [];
class Observable {
notifyPropertyChange(name, value) { changes.push([name, value]); }
}
const settings = {
brightnessSetting: { get: () => brightness, set: value => { brightness = value; writes.push(value); } },
displayLayoutSetting: { get: () => mode, set: value => { mode = value; }, values: ['small', 'large', 'huge'],
isDisabled: value => value === 'huge', displayValue(value = mode) { return value[0].toUpperCase() + value.slice(1); } },
};
const { RemoteControlsViewModel } = loader({}, {
'@nativescript/core': { Observable, Dialogs: { action: async () => picked } },
'../ui/dashboard-settings': settings,
'@nativescript/core': { Observable, Frame: { topmost: () => ({ navigate: entry => navigations.push(entry) }) } },
'../ui/dashboard-settings': { phoneInputStyleSetting: { get: () => style } },
})('app/phone-ui/remote-controls-view-model.ts');
return { model: new RemoteControlsViewModel(), create: () => new RemoteControlsViewModel(), changes, writes,
brightness: () => brightness, mode: () => mode, pick: value => { picked = value; } };
return { model: new RemoteControlsViewModel(), create: () => new RemoteControlsViewModel(), changes, navigations,
setStyle: value => { style = value; } };
}
test('shared controls preserve the selected tab across page visits and update all tab bindings', () => {
test('the touchpad follows the Phone input style setting and only notifies when it changes', () => {
const h = fixture();
assert.equal(h.model.watchTabVisibility, 'visible');
h.model.onRingTabTap();
assert.equal(h.model.watchTabVisibility, 'collapse');
assert.equal(h.model.ringTabVisibility, 'visible');
assert.match(h.model.ringTabClass, /tab-button-selected/);
assert.equal(h.changes.length, 6);
assert.equal(h.create().ringTabVisibility, 'visible');
h.model.onSettingsTabTap();
assert.equal(h.model.settingsTabVisibility, 'visible');
assert.equal(h.model.watchPadVisibility, 'visible');
assert.equal(h.model.ringPadVisibility, 'collapse');
// Some other setting changed: nothing to redraw, no gesture to cancel.
h.model.refreshInputStyle();
assert.deepEqual(h.changes, []);
h.setStyle('ring'); h.model.refreshInputStyle();
assert.equal(h.model.watchPadVisibility, 'collapse');
assert.equal(h.model.ringPadVisibility, 'visible');
assert.deepEqual(h.changes, [['watchPadVisibility', 'collapse'], ['ringPadVisibility', 'visible']]);
// A page built later starts on the stored style.
assert.equal(h.create().ringPadVisibility, 'visible');
});
test('shared brightness controls snap manual levels and restore the manual value after Auto', () => {
const h = fixture();
h.model.onBrightnessChange({ value: 76 });
assert.equal(h.brightness(), '80');
h.model.onBrightnessAutoChange({ value: true });
assert.equal(h.brightness(), 'auto');
assert.equal(h.model.brightnessSliderEnabled, false);
h.model.onBrightnessChange({ value: 10 });
assert.equal(h.brightness(), 'auto');
h.model.onBrightnessAutoChange({ value: false });
assert.equal(h.brightness(), '80');
h.model.onBrightnessChange({ value: -10 });
assert.equal(h.brightness(), '2');
h.model.onBrightnessChange({ value: NaN });
assert.equal(h.brightness(), '2');
test('the EvenHub phone-UI button shows only with an icon and opens that app through the host', () => {
const h = fixture(), opened = [], icon = { id: 'icon' };
h.model.showEvenHubPhoneUi = windowId => opened.push(windowId);
assert.equal(h.model.evenHubPhoneUiVisibility, 'collapse');
h.model.onEvenHubPhoneUiTap();
h.model.evenHubPhoneUi = { windowId: 'w1', title: 'Chess', icon: null };
assert.equal(h.model.evenHubPhoneUiVisibility, 'collapse');
h.model.onEvenHubPhoneUiTap();
assert.deepEqual(opened, [], 'a hidden button opens nothing');
h.changes.length = 0;
h.model.evenHubPhoneUi = { windowId: 'w1', title: 'Chess', icon };
assert.equal(h.model.evenHubPhoneUiVisibility, 'visible');
assert.equal(h.model.evenHubPhoneUiIcon, icon);
assert.equal(h.model.evenHubPhoneUiLabel, 'Open Chess on phone');
assert.deepEqual(h.changes.map(change => change[0]), ['evenHubPhoneUiIcon', 'evenHubPhoneUiVisibility', 'evenHubPhoneUiLabel']);
h.model.onEvenHubPhoneUiTap();
assert.deepEqual(opened, ['w1']);
// The host pushes a fresh object on every snapshot; an equal one is not a change.
h.changes.length = 0;
h.model.evenHubPhoneUi = { windowId: 'w1', title: 'Chess', icon };
assert.deepEqual(h.changes, []);
h.model.evenHubPhoneUi = null;
assert.equal(h.model.evenHubPhoneUiVisibility, 'collapse');
assert.equal(h.model.evenHubPhoneUiLabel, '');
});
test('shared display-mode picker preserves cancellation and applies the selected mode', async () => {
test('the gear button opens the settings page', () => {
const h = fixture();
h.pick('Cancel'); await h.model.onDisplayModeTap();
assert.equal(h.mode(), 'small');
// Unavailable modes (Full Screen beside a side strip) are not offered.
h.pick('Huge'); await h.model.onDisplayModeTap();
assert.equal(h.mode(), 'small');
h.pick('Large'); await h.model.onDisplayModeTap();
assert.equal(h.mode(), 'large');
assert.equal(h.model.displayModeLabel, 'Large ▾');
h.model.onSettingsTap();
// The entry is built in the module's own realm, so compare its field.
assert.deepEqual(h.navigations.map(entry => entry.moduleName), ['phone-ui/settings-page']);
});
test('the control bar keeps the EvenHub button leftmost and the pads bound to the input style', () => {
const xml = require('node:fs').readFileSync(require('node:path').join(__dirname, '../app/phone-ui/remote-controls.xml'), 'utf8');
const bar = xml.slice(xml.indexOf('class="control-bar"'), xml.indexOf('onControlsContentLayoutChanged'));
const order = ['onEvenHubPhoneUiTap', 'onSyntheticMicTap', 'onKeyboardTap', 'onSettingsTap'].map(name => bar.indexOf(name));
assert.ok(order.every(index => index >= 0), 'all four buttons are in the bar');
assert.deepEqual(order, [...order].sort((a, b) => a - b));
// A leading star column takes the slack, so the app button's coming and going moves no other button.
assert.match(xml, /columns="\*,auto,auto,auto,auto"[^>]*class="control-bar"/);
assert.match(xml, /visibility="\{\{ watchPadVisibility \}\}"/);
assert.match(xml, /visibility="\{\{ ringPadVisibility \}\}"/);
assert.doesNotMatch(xml, /TabVisibility|TabClass|TabTap/);
});
+29 -5
View File
@@ -15,6 +15,7 @@ function load(file, modules) {
}
const graphics = require('../.test-build/app/graphics/image.js');
const { bordered, unbordered } = require('./helpers/viewport.cjs');
const metrics = require('../.test-build/app/ui/metrics.js');
const menuCore = require('../.test-build/app/ui/menu-core.js');
const { BdfFont } = load('app/graphics/bdffont.ts', { '@nativescript/core': {} });
@@ -34,8 +35,8 @@ const { SettingsPanelLayer } = load('app/ui/dashboard/settings-panel.ts', {
'../shell/shell': { shell: { yieldFocusToSidebar: () => yields++ } },
});
/** A panel over three sections; records which item callbacks fire. */
function panel() {
/** A panel over three sections, in a framed window unless given another; records which item callbacks fire. */
function panel(viewport = bordered(576, 260)) {
const selected = [];
const item = (label, extra = {}) => ({ label, onSelect: () => selected.push(label), ...extra });
const layer = new SettingsPanelLayer([
@@ -43,7 +44,7 @@ function panel() {
{ label: 'Voice', items: Array.from({ length: 20 }, (_, i) => item(`Voice ${i}`, { description: 'Help text for this option.' })) },
{ label: 'About', items: [], renderDetail: () => {} },
]);
const ctx = { stack: { getBaseSize: () => ({ width: 576, height: 260 }), isFocused: () => true } };
const ctx = { stack: { getBaseSize: () => viewport, isFocused: () => true } };
const input = (type) => layer.handleInput({ type, timestampMs: 0 }, ctx);
return { layer, input, paint: () => layer.paint(ctx), selected };
}
@@ -104,7 +105,7 @@ test('the selected row stays clear of its description band', async () => {
await p.input('scroll-up');
const row = selections(p.paint())[1];
const overlay = new graphics.GrayImage(576, 260);
p.layer.paintDescriptionOverlay(overlay, { stack: { getBaseSize: () => ({ width: 576, height: 260 }) } });
p.layer.paintDescriptionOverlay(overlay, { stack: { getBaseSize: () => bordered(576, 260) } });
let bandTop = -1;
for (let y = 0; y < 260 && bandTop < 0; y++) if (overlay.getPixel(300, y) !== 0) bandTop = y;
assert.ok(bandTop > 0, 'the band is drawn');
@@ -118,7 +119,7 @@ test('a section\'s detail gives its rows the pane while focus is in them, where
// About's blurb under its 72px logo: about 145px.
const about = { label: 'About', items: docs.map((label) => ({ label, onSelect() {} })),
renderDetail: ({ image, x, y }) => { detailDraws.push(image); image.fillRect(x, y, 72, 72, 90); return 145; } };
for (const [size, keeps] of [[{ width: 576, height: 260 }, true], [{ width: 476, height: 192 }, false], [{ width: 476, height: 155 }, false]]) {
for (const [size, keeps] of [[bordered(576, 260), true], [bordered(476, 192), false], [bordered(476, 155), false]]) {
const layer = new SettingsPanelLayer([about]);
const ctx = { stack: { getBaseSize: () => size, isFocused: () => true } };
const paint = () => { detailDraws.length = 0; const image = layer.paint(ctx); return { image, drawn: detailDraws.includes(image) }; };
@@ -133,3 +134,26 @@ test('a section\'s detail gives its rows the pane while focus is in them, where
assert.ok(row.y + row.source.height <= size.height - 8);
}
});
test('the columns keep the padding suggested for each window edge, and scroll right up to the top and bottom', async () => {
// Where the left column's first-row highlight (a retained selection) starts.
const first = (viewport) => { const row = selections(panel(viewport).paint())[0]; return [row.x, row.y]; };
assert.deepEqual(first(bordered(576, 260)), [8, 8], 'beside border lines, 8px in');
assert.deepEqual(first(unbordered(576, 260)), [0, 0], 'beside blank space, right at the edges');
// The right column ends at the right edge's padding.
for (const [viewport, right] of [[bordered(576, 260), 568], [unbordered(576, 260), 576]]) {
const p = panel(viewport);
await p.input('click');
const row = selections(p.paint())[1];
assert.equal(row.x + row.source.width, right);
}
// A long list scrolled to its middle is cut off at the window's own top
// and bottom edges, not at the padding: a row starts at y 0.
const p = panel(bordered(576, 260));
await p.input('scroll-down');
await p.input('click');
for (let i = 0; i < 10; i++) await p.input('scroll-down');
const image = p.paint().withDrawsBaked();
const lit = (y) => { for (let x = 180; x < 560; x++) if (image.getPixel(x, y) > 40) return true; return false; };
assert.ok([0, 1, 2, 3, 4, 5, 6, 7].some(lit), 'rows show in the top padding once scrolled');
});
+1 -1
View File
@@ -149,7 +149,7 @@ test('host applies activity only to its own open windows and cleans up on close'
'../../graphics/image': { GrayImage: Image },
'./chrome-layer': { windowIcon: (icon, letter, glyph, phase) => phase },
'../../assistant/tool-registry': { toolRegistry: { removeAppTools() {} } },
'./geometry': { appViewportSize: () => ({ width: 576, height: 260 }) },
'./geometry': { appViewport: () => ({ width: 576, height: 260 }) },
'../../native/frame-timings': {},
'./worker-state': {},
'./shell': { shell: { registerWindow: w => shellWindows.set(w.windowId, w) } },
+30 -10
View File
@@ -1,30 +1,50 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { HUB_TITLE_X, layoutHubHeader } = require('../.test-build/app/apps/terminal/hub-header.js');
const { HUB_TITLE_INSET_X, layoutHubHeader } = require('../.test-build/app/apps/terminal/hub-header.js');
const { bordered, unbordered, edged } = require('./helpers/viewport.cjs');
const font = size => ({ measureText: text => [...text].length * size, getGlyph: () => ({ dwidthX: size }) });
// Framed all round: the title 8px in plus its inset, and 2px below the top padding.
const TITLE_X = 8 + HUB_TITLE_INSET_X;
test('terminal short status stays inline; exact-fit status does not move the list', () => {
const f = font(7), title = 'Terminal', status = 'Connected.';
const width = HUB_TITLE_X + f.measureText(title) + 16 + f.measureText(status) + 12;
const header = layoutHubHeader(f, title, status, width, 18);
const width = TITLE_X + f.measureText(title) + 16 + f.measureText(status) + 8;
const header = layoutHubHeader(f, title, status, bordered(width, 260), 18);
assert.deepEqual([header.titleX, header.titleY], [TITLE_X, 10]);
assert.equal(header.y, 10); assert.equal(header.listTop, 34); assert.deepEqual(header.lines, [status]);
assert.equal(layoutHubHeader(f, title, status, width - 1, 18).y, 28);
assert.equal(layoutHubHeader(f, title, status, bordered(width - 1, 260), 18).y, 28);
});
test('terminal long error wraps in full-width block and moves menu below all lines at each font size', () => {
const status = 'Connection failed. The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.';
for (const size of [5, 7, 12, 20]) for (const width of [320, 576, 640]) {
const f = font(size), step = size * 2;
const header = layoutHubHeader(f, 'Terminal - Connections', status, width, step);
assert.equal(header.x, HUB_TITLE_X); assert.equal(header.y, 10 + step);
const header = layoutHubHeader(f, 'Terminal - Connections', status, bordered(width, 260), step);
assert.equal(header.x, TITLE_X); assert.equal(header.y, 10 + step);
assert.equal(header.lines.join(' '), status);
assert.ok(header.lines.every(line => f.measureText(line) <= width - HUB_TITLE_X - 12));
assert.ok(header.lines.every(line => f.measureText(line) <= width - TITLE_X - 8));
assert.ok(header.listTop >= header.y + header.lines.length * step);
assert.equal(header.listTop, 16 + step * (1 + header.lines.length));
}
});
test('terminal explicit newlines and long unbroken messages remain complete', () => {
const h = layoutHubHeader(font(7), 'Terminal', 'First\nSecond', 640, 18);
assert.equal(h.x, HUB_TITLE_X); assert.deepEqual(h.lines, ['First', 'Second']);
const h = layoutHubHeader(font(7), 'Terminal', 'First\nSecond', bordered(640, 260), 18);
assert.equal(h.x, TITLE_X); assert.deepEqual(h.lines, ['First', 'Second']);
const word = 'x'.repeat(200);
const wrapped = layoutHubHeader(font(7), 'Terminal', word, 320, 18);
const wrapped = layoutHubHeader(font(7), 'Terminal', word, bordered(320, 260), 18);
assert.equal(wrapped.lines.join(''), word);
});
test('terminal header keeps the padding of just the edges a border runs along', () => {
const f = font(7), title = 'Terminal', status = 'Connected.';
// Nothing bordered: the title starts its inset from the left edge, at the top edge's offset.
const open = layoutHubHeader(f, title, status, unbordered(576, 260), 18);
assert.deepEqual([open.titleX, open.titleY, open.y, open.listTop], [HUB_TITLE_INSET_X, 2, 2, 26]);
// An inline status may run right up to an unbordered right edge, but stops 8px short of a bordered one.
const fit = HUB_TITLE_INSET_X + f.measureText(title) + 16 + f.measureText(status);
assert.equal(layoutHubHeader(f, title, status, unbordered(fit, 260), 18).lines.length, 1);
assert.equal(layoutHubHeader(f, title, status, unbordered(fit, 260), 18).y, 2);
assert.equal(layoutHubHeader(f, title, status, edged(fit, 260, 'right'), 18).y, 2 + 18);
// Each edge on its own.
const topLeft = layoutHubHeader(f, title, 'First\nSecond', edged(576, 260, 'top', 'left'), 18);
assert.deepEqual([topLeft.titleX, topLeft.titleY, topLeft.x, topLeft.y], [TITLE_X, 10, TITLE_X, 28]);
const bottom = layoutHubHeader(f, title, 'First\nSecond', edged(576, 260, 'bottom'), 18);
assert.deepEqual([bottom.titleX, bottom.titleY, bottom.listTop], [HUB_TITLE_INSET_X, 2, 8 + 18 * 3]);
});
+49 -9
View File
@@ -1,10 +1,12 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
const { bordered, unbordered } = require('./helpers/viewport.cjs');
const HUB = 'terminal:hub';
const MIN = { width: 552, height: 260 };
const MAX = { width: 552, height: 452 };
// Framed windows: the shell's messages carry what each edge touches and its padding.
const MIN = bordered(552, 260);
const MAX = bordered(552, 452);
const font = { lineHeight: 12, measureText: (text) => text.length * 6, getGlyph: () => null };
const tick = () => new Promise((resolve) => setTimeout(resolve, 0));
@@ -16,9 +18,10 @@ function fakeImageModule() {
this.height = height;
this.texts = [];
this.draws = [];
this.positions = [];
return new Proxy(this, { get: (target, key) => (key in target ? target[key] : () => {}) });
}
drawText(_font, _x, _y, text) { this.texts.push(text); }
drawText(_font, x, y, text) { this.texts.push(text); this.positions.push([text, x, y]); }
drawMenuSelection(row) { this.texts.push(...row.texts.map((text) => `[${text}]`)); }
}
return { GrayImage };
@@ -95,8 +98,8 @@ function terminal({ sessions = ['vim', 'top'], presets = '', bellWake = true } =
'../../graphics/image': image,
'../graphics/image': image,
'../../graphics/plane': {
planesFingerprint: (planes) => JSON.stringify([planes[0].width, planes[0].height, planes[0].texts]),
flattenPlanesWithDraws: (planes) => ({ image: { ...planes[0], width: planes[0].width, height: planes[0].height, texts: planes[0].texts, to8bppBuffer: () => ({ buffer: planes[0].texts }) }, draws: [] }),
planesFingerprint: (planes) => JSON.stringify([planes[0].width, planes[0].height, planes[0].texts, planes[0].positions]),
flattenPlanesWithDraws: (planes) => ({ image: { ...planes[0], width: planes[0].width, height: planes[0].height, texts: planes[0].texts, to8bppBuffer: () => ({ buffer: planes[0] }) }, draws: [] }),
},
'../../graphics/glyph-wire': { prepareFrameDraws: () => null },
'../../graphics/ui-fonts': {
@@ -110,7 +113,7 @@ function terminal({ sessions = ['vim', 'top'], presets = '', bellWake = true } =
},
'../../native/active-display': {
getActiveDisplay: () => ({
submitSurfaceFrame: (texts, surfaceId, _x, _y, width, height) => frames.push({ surfaceId, width, height, texts }),
submitSurfaceFrame: ({ texts, positions }, surfaceId, _x, _y, width, height) => frames.push({ surfaceId, width, height, texts, positions }),
}),
},
'../../ui/gestures': { GESTURE_DOUBLE_CLICK: 'double-tap' },
@@ -149,6 +152,8 @@ function terminal({ sessions = ['vim', 'top'], presets = '', bellWake = true } =
return {
clients, frames, replies, menus, send, input, openWindow, repliesOf,
lastFrame: () => frames[frames.length - 1],
// Where the last frame drew a line of text, as [x, y].
textAt: (text) => frames[frames.length - 1].positions.find((entry) => entry[0] === text).slice(1),
clearReplies: () => { replies.length = 0; },
openMenu: (windowId = HUB) => input('short-then-long-press', windowId),
menuLabels: () => Array.from(menus.find((menu) => menu.isOpen()).opened, (item) => item.label),
@@ -400,14 +405,49 @@ test('closing the window while it shows a session stops that session', () => {
test('a later resize of a session in place reconnects at the new grid, and the list then gets its own size', () => {
const t = hubShowingSession();
t.answerHeight({ width: 552, height: 400 });
t.answerHeight(bordered(552, 400));
assert.equal(t.clients[1].stopped, false);
assert.deepEqual(t.clients[1].viewport, [92, 33]);
t.input('double-click');
t.answerHeight({ width: 552, height: 240 });
t.answerHeight(bordered(552, 240));
assert.equal(t.lastFrame().height, 240);
});
test('the list lays out inside the padding of its window\'s bordered edges, and follows a change in them', async () => {
const t = terminal();
t.openWindow(HUB, MIN);
// The title lines up with the rows' text: 6px inside their boxes, which start at the left padding.
assert.deepEqual(t.textAt('Terminal'), [8 + 6, 8 + 2]);
assert.deepEqual(t.textAt('Connected.'), [8 + 6 + 'Terminal'.length * 6 + 16, 8 + 2]);
// The window menu's stack gets the whole viewport, for the pages it shows.
const plain = (value) => JSON.parse(JSON.stringify(value));
assert.deepEqual(plain(t.menus[0].options.size), plain(MIN));
// Same size, nothing bordering it any more (Border: None): a repaint with no padding.
const painted = t.frames.length;
t.send({ type: 'resize-window', windowId: HUB, viewport: unbordered(552, 260) });
await new Promise((resolve) => setTimeout(resolve, 80));
assert.equal(t.frames.length, painted + 1);
assert.deepEqual(t.textAt('Terminal'), [6, 2]);
assert.deepEqual(plain(t.menus[0].options.size), plain(unbordered(552, 260)));
});
test('a session keeps its connection and grid when only its window\'s edges change', async () => {
const t = hubShowingSession();
const painted = t.frames.length;
t.send({ type: 'resize-window', windowId: HUB, viewport: unbordered(552, 452) });
await new Promise((resolve) => setTimeout(resolve, 80));
assert.equal(t.clients[1].stopped, false);
assert.equal(t.clients[1].viewport, undefined, 'no new grid negotiated');
assert.equal(t.clients.length, 2);
assert.equal(t.frames.length, painted);
// Back in the list, the hub takes the padding the shell answers with.
t.input('double-click');
t.answerHeight(unbordered(552, 260));
assert.deepEqual(t.textAt('Terminal'), [6, 2]);
});
test('the shell host resizes the surface before answering with the new viewport', async () => {
const worker = { posted: [], postMessage(message) { this.posted.push(message); } };
const surfaces = [];
@@ -418,7 +458,7 @@ test('the shell host resizes the surface before answering with the new viewport'
'../../graphics/image': {},
'./chrome-layer': { windowIcon() {} },
'../../assistant/tool-registry': { toolRegistry: { removeAppTools() {} } },
'./geometry': { appViewportSize: (mode) => (mode === 'max' ? MAX : MIN) },
'./geometry': { appViewport: (mode) => (mode === 'max' ? MAX : MIN) },
'../../native/frame-timings': {},
'./worker-state': {},
'./shell': { shell: {
+37 -1
View File
@@ -2,9 +2,12 @@ const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
const load = loader();
const { TranscriptModel, TranscriptScroll, wrapTranscribeText } = load('app/apps/transcribe/transcript-model.ts');
const { TranscriptModel, TranscriptScroll, transcriptLayout, wrapTranscribeText } = load('app/apps/transcribe/transcript-model.ts');
const { SpeechPauseDetector } = load('app/native/speech-pause.ts');
const { TimedTranscript } = load('app/native/transcript-format.ts');
const { bordered, unbordered, edged } = require('./helpers/viewport.cjs');
const plain = value => JSON.parse(JSON.stringify(value));
function pcm(amplitude, ms = 50) {
const bytes = new Uint8Array(ms * 16 * 2);
@@ -82,6 +85,39 @@ test('short transcripts become scrollable without disabling automatic following'
assert.equal(s.layout(12, 10), 2);
});
test('the transcript lines up with the header inside the side padding and scrolls to the bottom edge', () => {
// 16px lines stepping 20, under a header that ends at y=38.
const framed = transcriptLayout(bordered(576, 260), 38, 16, 20);
assert.deepEqual(plain(framed), {
// In line with the header's title at the left padding; the right keeps the scrollbar's gutter.
textX: 8, textWidth: 576 - 8 - 8 - 8, pageLines: 10, drawnLines: 11,
scrollbar: { x: 576 - 8 - 2, y: 38, width: 2, height: 260 - 8 - 38 },
});
// Following the tail, the last line rests above the bottom padding; scrolled
// back, one more line fits above the window's edge itself.
const lineBottom = (firstLine, total) => 38 + (Math.min(total, firstLine + framed.drawnLines) - 1 - firstLine) * 20 + 16;
const s = new TranscriptScroll();
assert.equal(s.layout(40, framed.pageLines), 30);
assert.equal(lineBottom(30, 40), 234);
s.scroll(-3);
assert.equal(s.layout(40, framed.pageLines), 27);
assert.equal(lineBottom(27, 40), 254);
assert.ok(lineBottom(27, 40) > 260 - 8 && lineBottom(27, 40) <= 260);
// With nothing bordering the window, the column and the page gain the padding's room.
assert.deepEqual(plain(transcriptLayout(unbordered(576, 260), 38, 16, 20)), {
textX: 0, textWidth: 576 - 8, pageLines: 11, drawnLines: 11,
scrollbar: { x: 574, y: 38, width: 2, height: 222 },
});
const leftOnly = transcriptLayout(edged(576, 260, 'left'), 38, 16, 20);
assert.deepEqual([leftOnly.textX, leftOnly.textWidth, leftOnly.scrollbar.x], [8, 576 - 8 - 8, 574]);
// The scrollbar never stands over the text column.
for (const layout of [framed, leftOnly, transcriptLayout(bordered(476, 155), 38, 16, 20)]) {
assert.ok(layout.textX + layout.textWidth < layout.scrollbar.x);
assert.ok(layout.pageLines >= 1 && layout.drawnLines >= layout.pageLines);
}
});
test('pause detector uses 1.5 seconds of PCM, fires once per pause, and ignores leading silence', () => {
const d = new SpeechPauseDetector();
for (let i = 0; i < 60; i++) assert.equal(d.accept(pcm(0)), false);
+1
View File
@@ -26,6 +26,7 @@
"../app/graphics/plane.ts",
"../app/graphics/shell-scene.ts",
"../app/ui/metrics.ts",
"../app/ui/viewport.ts",
"../app/ui/menu-core.ts",
"../app/phone-ui/phone-gestures.ts",
"../app/native/java-direct-buffer.ts",
+58 -2
View File
@@ -158,11 +158,11 @@ test('cloud fallback and a synchronous final still send exactly once', () => {
});
/** The Android voice bridge over a fake native controller (on-device recognition only). */
function androidBridge() {
function androidBridge(modules = {}) {
const controller = {
starts: 0,
setListener(listener) { this.listener = listener; },
setCommunicator() {}, setUsePhoneMic() {}, setSaveRecordings() {}, setEndpointing() {},
setCommunicator() {}, setUsePhoneMic() {}, setEndpointing() {},
setNoiseSuppression() {}, setBeamFilter() {}, clearSpeakerVerification() {},
setFrenchWhisper(enabled) { this.frenchWhisper = enabled; },
setOnboardModelKind(kind) { this.modelKind = kind; }, setOnboardLanguage(language) { this.language = language; },
@@ -175,6 +175,7 @@ function androidBridge() {
'./speech-pause': { SpeechPauseDetector: class { reset() {} } },
'./cloud-stt-provider': { createCloudSttClient: () => null,
transcriptionKey: options => `${options.provider}:${options.provider === 'onboard-whisper-fr' ? 'fr' : options.language ?? (options.provider === 'onboard-whisper' ? 'en' : '')}` },
...modules,
}, { global: { isAndroid: true }, com: { faceclaw: { app: {
FaceclawVoiceController: function () { return controller; },
FaceclawVoiceControllerListener: function (listener) { return listener; },
@@ -251,3 +252,58 @@ test('dedicated French Whisper selects its own files and switches back without r
assert.equal(controller.starts, 2);
bridge.stop();
});
test('Android continuous captures record to the requested WAV, and report one that cannot be created', () => {
const recordings = [];
let fail = false, attempts = 0;
class FakeRecorder {
static open(name) {
attempts++;
if (fail) return null;
const r = new FakeRecorder(); r.name = name; r.path = `/Download/${name}.wav`; r.pcm = []; r.closed = false; recordings.push(r); return r;
}
append(pcm) { this.pcm.push(...pcm); }
close() { this.closed = true; }
}
const { bridge, controller } = androidBridge({
'./wav-recorder': { WavRecorder: FakeRecorder },
'./speech-pause': { SpeechPauseDetector: class { reset() {} accept() { return false; } } },
'../util/array-util': { toUint8Array: pcm => Uint8Array.from(pcm) },
'../util/audio-level': { pcmLevel: () => 0 },
});
const options = { provider: 'onboard' };
let changes = 0; bridge.onRecordingChange(() => changes++);
bridge.recordTo('transcribe-1');
assert.deepEqual([bridge.recording, bridge.recordingFailed, changes], [true, false, 1]);
// Push-to-talk on a capture of its own is not recorded, and the file waits for audio to save.
bridge.startPushToTalk(options);
controller.listener.onPcm([9, 9]);
assert.equal(attempts, 0);
bridge.startContinuousCapture(options);
controller.listener.onPcm([1, 2]);
controller.listener.onPcm([3, 4]);
assert.deepEqual(recordings.map(r => [r.name, r.pcm, r.closed]), [['transcribe-1', [1, 2, 3, 4], false]]);
// The file outlives a capture: one restarted after the glasses reconnect keeps appending to it.
bridge.handleSessionEnded();
bridge.resumeCapture(options);
controller.listener.onPcm([5]);
assert.deepEqual(recordings.map(r => [r.pcm, r.closed]), [[[1, 2, 3, 4, 5], false]]);
bridge.recordTo('');
assert.deepEqual([recordings[0].closed, bridge.recording, changes], [true, false, 2]);
controller.listener.onPcm([6]);
assert.equal(recordings[0].pcm.length, 5);
// One attempt per recording, not one per packet; another recording is a fresh attempt.
fail = true; attempts = 0;
bridge.recordTo('transcribe-2');
controller.listener.onPcm([7]); controller.listener.onPcm([8]);
assert.deepEqual([bridge.recording, bridge.recordingFailed, changes, attempts], [false, true, 4, 1]);
bridge.recordTo('transcribe-2');
controller.listener.onPcm([9]);
assert.equal(attempts, 1);
fail = false;
bridge.recordTo('');
bridge.recordTo('transcribe-2');
controller.listener.onPcm([10]);
assert.deepEqual([bridge.recording, bridge.recordingFailed, recordings.at(-1).pcm], [true, false, [10]]);
});
+1 -1
View File
@@ -11,7 +11,7 @@ function fixture() {
const load = loader({ global: {}, setTimeout: (fn, ms) => { timers.set(fn, ms); return fn; }, clearTimeout: fn => timers.delete(fn) }, {
'../../graphics/image': {}, './chrome-layer': { windowIcon() {} },
'../../assistant/tool-registry': { toolRegistry: { removeAppTools() {} } },
'./geometry': { appViewportSize: () => ({ width: 576, height: 288 }) },
'./geometry': { appViewport: () => ({ width: 576, height: 288 }) },
'../../native/frame-timings': {}, './worker-state': { publishWorkerState: (...args) => published.push(args) },
'./shell': { shell: { registerWindow: w => shellWindows.set(w.windowId, w), setTrayIcon() {},
focusWindow: id => focused.push(id), isWindowFocused: () => false } },