forked from Blendman974/faceclaw
Unify vertical position and display mode settings; add to onboarding
This commit is contained in:
1 parent
6b1e64c5ac
commit
5a9ca08921
36 files changed
+810
-574
No files matched your search
@@ -271,7 +271,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 }), setAppFullscreen: () => false },
|
||||
'./chrome-layer': { windowIcon: () => () => null }, './geometry': { appViewportSize: () => ({ width: 576, height: 260 }), setAppImmersive: () => false },
|
||||
'./shell': { shell },
|
||||
});
|
||||
const input = [], menus = [];
|
||||
|
||||
+111
-79
@@ -11,9 +11,7 @@ const js = (source) => ts.transpileModule(source, {
|
||||
|
||||
function geometry() {
|
||||
const settings = Object.fromEntries(Object.entries({
|
||||
displayModeSetting: '576x288', verticalPositionSetting: 'middle',
|
||||
navigateDisplayModeSetting: 'global', navigateVerticalPositionSetting: 'global',
|
||||
terminalDisplayModeSetting: 'default', terminalVerticalPositionSetting: 'global',
|
||||
displayLayoutSetting: 'band-middle', navigateDisplayLayoutSetting: 'global', terminalDisplayLayoutSetting: 'default',
|
||||
appSwitcherPositionSetting: 'left', uiDepthSetting: '0', statusBarPositionSetting: 'top',
|
||||
statusBarVisibilitySetting: 'always', windowBorderSetting: true,
|
||||
}).map(([name, value]) => [name, { value, get() { return this.value; } }]));
|
||||
@@ -27,46 +25,79 @@ function geometry() {
|
||||
return { ...context.exports, settings, rect };
|
||||
}
|
||||
|
||||
const LAYOUTS = ['band-top', 'band-high', 'band-middle', 'band-low', 'band-bottom', 'tall', 'fullscreen'];
|
||||
|
||||
test('defaults preserve normal windows, EvenHub height and tall terminal sessions', () => {
|
||||
const g = geometry();
|
||||
assert.deepEqual(g.rect('min', 'navigate'), { x: 64, y: 124, width: 576, height: 260 });
|
||||
assert.deepEqual(g.rect('min', 'terminal'), g.rect('min'));
|
||||
assert.deepEqual(g.rect('max', 'terminal'), { x: 64, y: 28, width: 576, height: 452 });
|
||||
assert.equal(g.windowBandHeight('medium', 'evenhub'), 316);
|
||||
g.settings.displayModeSetting.value = '640x480';
|
||||
assert.deepEqual(g.rect('max', 'terminal'), { x: 0, y: 28, width: 640, height: 452 });
|
||||
// Tall: every window the whole height, beside the strip.
|
||||
g.settings.displayLayoutSetting.value = 'tall';
|
||||
assert.deepEqual(g.rect('min'), { x: 64, y: 28, width: 576, height: 452 });
|
||||
});
|
||||
|
||||
test('Navigate can use a small bottom band while other apps fill the panel', () => {
|
||||
test('Navigate can use a small bottom band while other apps are tall', () => {
|
||||
const g = geometry();
|
||||
g.settings.displayModeSetting.value = '640x480';
|
||||
g.settings.navigateDisplayModeSetting.value = '576x288';
|
||||
g.settings.navigateVerticalPositionSetting.value = 'bottom';
|
||||
g.settings.displayLayoutSetting.value = 'tall';
|
||||
g.settings.navigateDisplayLayoutSetting.value = 'band-bottom';
|
||||
assert.deepEqual(g.rect('min', 'navigate'), { x: 64, y: 220, width: 576, height: 260 });
|
||||
assert.equal(g.minWindowTop('navigate'), 192);
|
||||
assert.equal(g.sidebarStripVisible('window', 'navigate'), true);
|
||||
assert.equal(g.sidebarStripVisible('window', 'other'), false);
|
||||
assert.deepEqual(g.rect('min', 'other'), { x: 0, y: 28, width: 640, height: 452 });
|
||||
assert.deepEqual(g.rect('min', 'other'), { x: 64, y: 28, width: 576, height: 452 });
|
||||
});
|
||||
|
||||
test('Terminal can disable its tall default, inherit position or override both dimensions', () => {
|
||||
test('Terminal can disable its tall default, follow the global band or choose a mode of its own', () => {
|
||||
const g = geometry();
|
||||
g.settings.terminalDisplayModeSetting.value = 'global';
|
||||
g.settings.terminalDisplayLayoutSetting.value = 'global';
|
||||
assert.deepEqual(g.rect('max', 'terminal'), g.rect('min'));
|
||||
g.settings.verticalPositionSetting.value = 'top';
|
||||
g.settings.displayLayoutSetting.value = 'band-top';
|
||||
assert.equal(g.windowTop('max', 'terminal'), 0);
|
||||
g.settings.terminalVerticalPositionSetting.value = 'lower';
|
||||
g.settings.terminalDisplayLayoutSetting.value = 'band-low';
|
||||
assert.equal(g.windowTop('max', 'terminal'), 144);
|
||||
g.settings.terminalDisplayModeSetting.value = '640x480';
|
||||
assert.deepEqual(g.rect('max', 'terminal'), { x: 0, y: 28, width: 640, height: 452 });
|
||||
assert.equal(g.sidebarStripVisible('window', 'terminal'), false);
|
||||
assert.equal(g.sidebarStripVisible('sidebar', 'terminal'), true);
|
||||
g.settings.terminalDisplayModeSetting.value = '576x480';
|
||||
g.settings.terminalDisplayLayoutSetting.value = 'tall';
|
||||
assert.deepEqual(g.rect('min', 'terminal'), { x: 64, y: 28, width: 576, height: 452 });
|
||||
// The default keeps sessions tall and the sessions list in the global band.
|
||||
g.settings.terminalDisplayLayoutSetting.value = 'default';
|
||||
assert.deepEqual(g.rect('max', 'terminal'), { x: 64, y: 28, width: 576, height: 452 });
|
||||
assert.equal(g.windowTop('min', 'terminal'), 0);
|
||||
});
|
||||
|
||||
test('all explicit size/position combinations stay within the display and align content below the bar', () => {
|
||||
test('Full Screen widens Tall windows to the panel and drops depth, beside a bottom row or popup only', () => {
|
||||
const g = geometry();
|
||||
g.settings.displayLayoutSetting.value = 'fullscreen';
|
||||
g.settings.uiDepthSetting.value = '48';
|
||||
// A side strip leaves no width to spare: there it is Tall.
|
||||
assert.equal(g.displayLayout(), 'tall');
|
||||
assert.deepEqual(g.rect('min'), { x: 64, y: 28, width: 576, height: 452 });
|
||||
g.settings.appSwitcherPositionSetting.value = 'bottom';
|
||||
assert.equal(g.displayLayout(), 'fullscreen');
|
||||
// Tall's height and the panel's width, the row still reserved under it,
|
||||
// always shown; no room for a frame, nor for depth.
|
||||
assert.deepEqual(g.rect('min'), { x: 0, y: 28, width: 640, height: 416 });
|
||||
assert.deepEqual({ ...g.switcherRect('min') }, { x: 0, y: 444, width: 640, height: 36 });
|
||||
assert.equal(g.sidebarStripVisible('window'), true);
|
||||
assert.equal(g.windowFramed(), false);
|
||||
assert.equal(g.uiDepth(), 0);
|
||||
// With the status bar in the row, there's no frame top for a header either.
|
||||
g.settings.statusBarPositionSetting.value = 'bottom';
|
||||
assert.equal(g.statusInSwitcherRow(), true);
|
||||
assert.deepEqual(g.rect('min'), { x: 0, y: 0, width: 640, height: 444 });
|
||||
// A popup's status bar keeps its edge.
|
||||
g.settings.appSwitcherPositionSetting.value = 'popup';
|
||||
assert.deepEqual(g.rect('max'), { x: 0, y: 0, width: 640, height: 452 });
|
||||
assert.equal(g.statusBarTop('max'), 452);
|
||||
assert.equal(g.windowFramed(), false);
|
||||
// Per app: depth follows the foreground app's mode.
|
||||
g.settings.displayLayoutSetting.value = 'band-middle';
|
||||
g.settings.navigateDisplayLayoutSetting.value = 'fullscreen';
|
||||
assert.deepEqual([g.uiDepth('navigate'), g.uiDepth('launcher'), g.uiDepth()], [0, 48, 48]);
|
||||
assert.deepEqual([g.rect('min', 'navigate').width, g.rect('min', 'launcher').width], [640, 576]);
|
||||
});
|
||||
|
||||
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']];
|
||||
for (const statusBar of ['top', 'bottom']) {
|
||||
for (const visibility of ['always', 'switcher']) {
|
||||
@@ -78,42 +109,43 @@ test('all explicit size/position combinations stay within the display and align
|
||||
g.settings.statusBarPositionSetting.value = statusBar;
|
||||
g.settings.statusBarVisibilitySetting.value = visibility;
|
||||
g.settings.windowBorderSetting.value = border;
|
||||
for (const globalMode of ['576x288', '576x480', '640x480']) {
|
||||
g.settings.displayModeSetting.value = globalMode;
|
||||
const side = switcher === 'left' || switcher === 'right';
|
||||
for (const globalMode of LAYOUTS) {
|
||||
g.settings.displayLayoutSetting.value = globalMode;
|
||||
for (const appId of ['navigate', 'terminal']) {
|
||||
for (const mode of ['global', '576x288', '576x480', '640x480']) {
|
||||
g.settings[`${appId}DisplayModeSetting`].value = mode;
|
||||
for (const position of ['global', 'top', 'upper', 'middle', 'lower', 'bottom']) {
|
||||
g.settings[`${appId}VerticalPositionSetting`].value = position;
|
||||
for (const heightMode of ['min', 'medium', 'max']) {
|
||||
const rect = g.rect(heightMode, appId);
|
||||
const fullPanel = g.displayMode(appId) === '640x480';
|
||||
assert.equal(rect.x + rect.width, fullPanel ? 640 : { left: 640, right: 576, bottom: 608, popup: 608 }[switcher]);
|
||||
const header = g.windowHeaderHeight(appId), footer = g.windowFooterHeight(appId);
|
||||
assert.equal(g.statusInSwitcherRow(appId), statusBar === 'bottom' && g.switcherRowHeight(appId) > 0);
|
||||
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 && !fullPanel);
|
||||
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.deepEqual([header, footer], [g.statusInSwitcherRow(appId) ? 1 : g.TOP_BAR_HEIGHT, 0]);
|
||||
}
|
||||
assert.equal(rect.y, g.windowTop(heightMode, appId) + header);
|
||||
assert.equal(rect.height + header + footer, g.windowBandHeight(heightMode, appId));
|
||||
assert.ok(rect.y >= header && rect.y + rect.height + footer <= 480 - g.switcherRowHeight(appId));
|
||||
const row = g.switcherRect(heightMode, appId);
|
||||
assert.ok(row.y + row.height <= 480);
|
||||
// A reserved bottom row hangs right under the window, as wide as it.
|
||||
if (g.switcherRowHeight(appId)) assert.deepEqual([row.x, row.y, row.width], [rect.x, rect.y + rect.height, rect.width]);
|
||||
// The frame's sides, just outside the window, survive the
|
||||
// deepest shift (±62 moves each lens 31px).
|
||||
if (g.windowFramed(appId)) assert.ok(rect.x - 1 - 31 >= 0 && rect.x + rect.width + 31 < 640);
|
||||
for (const mode of ['default', 'global', ...LAYOUTS]) {
|
||||
g.settings[`${appId}DisplayLayoutSetting`].value = mode;
|
||||
const wide = g.displayLayout(appId) === 'fullscreen';
|
||||
if (wide) assert.equal(side, false, 'Full Screen only beside a bottom row or popup');
|
||||
assert.equal(g.uiDepth(appId), side || wide ? 0 : 48);
|
||||
for (const heightMode of ['min', 'medium', 'max']) {
|
||||
const rect = g.rect(heightMode, appId);
|
||||
assert.equal(rect.x + rect.width, wide ? 640 : { left: 640, right: 576, bottom: 608, popup: 608 }[switcher]);
|
||||
const header = g.windowHeaderHeight(appId), footer = g.windowFooterHeight(appId);
|
||||
assert.equal(g.statusInSwitcherRow(appId), statusBar === 'bottom' && g.switcherRowHeight(appId) > 0);
|
||||
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);
|
||||
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.deepEqual([header, footer], [!g.statusInSwitcherRow(appId) ? g.TOP_BAR_HEIGHT : g.windowFramed(appId) ? 1 : 0, 0]);
|
||||
}
|
||||
assert.equal(rect.y, g.windowTop(heightMode, appId) + header);
|
||||
assert.equal(rect.height + header + footer, g.windowBandHeight(heightMode, appId));
|
||||
assert.ok(rect.y >= header && rect.y + rect.height + footer <= 480 - g.switcherRowHeight(appId));
|
||||
const row = g.switcherRect(heightMode, appId);
|
||||
assert.ok(row.y + row.height <= 480);
|
||||
// A reserved bottom row hangs right under the window, as wide as it.
|
||||
if (g.switcherRowHeight(appId)) assert.deepEqual([row.x, row.y, row.width], [rect.x, rect.y + rect.height, rect.width]);
|
||||
// The frame's sides, just outside the window, survive the
|
||||
// deepest shift (±62 moves each lens 31px).
|
||||
if (g.windowFramed(appId)) assert.ok(rect.x - 1 - 31 >= 0 && rect.x + rect.width + 31 < 640);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,8 +165,9 @@ test('the app switcher can sit on the right edge', () => {
|
||||
// Depth needs the bottom row's side margins.
|
||||
g.settings.uiDepthSetting.value = '32';
|
||||
assert.equal(g.uiDepth(), 0);
|
||||
g.settings.displayModeSetting.value = '640x480';
|
||||
assert.deepEqual(g.rect('max'), { x: 0, y: 28, width: 640, height: 452 });
|
||||
// Full Screen needs the width a strip takes: beside one it is Tall.
|
||||
g.settings.displayLayoutSetting.value = 'fullscreen';
|
||||
assert.deepEqual(g.rect('min'), { x: 0, y: 28, width: 576, height: 452 });
|
||||
});
|
||||
|
||||
test('a popup app switcher centres 576-wide windows, whose edges the status bar and frame decide', () => {
|
||||
@@ -167,10 +200,10 @@ test('a popup app switcher centres 576-wide windows, whose edges the status bar
|
||||
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 panel: the status bar keeps its edge, but there's no room for a frame.
|
||||
// Full Screen: the status bar keeps its edge, but there's no room for a frame.
|
||||
g.settings.windowBorderSetting.value = true;
|
||||
g.settings.statusBarVisibilitySetting.value = 'always';
|
||||
g.settings.displayModeSetting.value = '640x480';
|
||||
g.settings.displayLayoutSetting.value = 'fullscreen';
|
||||
assert.equal(g.windowFramed(), false);
|
||||
assert.deepEqual(g.rect('max'), { x: 0, y: 0, width: 640, height: 452 });
|
||||
assert.equal(g.statusBarTop('max'), 452);
|
||||
@@ -187,7 +220,7 @@ test('a bottom app switcher centres 576-wide windows and hangs one tall tab unde
|
||||
assert.deepEqual({ ...g.switcherRect('min') }, { x: 32, y: 366, width: 576, height: 36 });
|
||||
assert.equal(g.isOnSwitcherEdge(10, 370, 'min'), true);
|
||||
assert.equal(g.isOnSwitcherEdge(10, 360, 'min'), false);
|
||||
g.settings.verticalPositionSetting.value = 'bottom';
|
||||
g.settings.displayLayoutSetting.value = 'band-bottom';
|
||||
assert.equal(g.switcherRect('min').y, 444);
|
||||
// The true centre is the viewport's own with the window centred.
|
||||
assert.equal(g.screenCenterInViewportX(), 288);
|
||||
@@ -195,28 +228,27 @@ test('a bottom app switcher centres 576-wide windows and hangs one tall tab unde
|
||||
g.settings.uiDepthSetting.value = '-48';
|
||||
assert.equal(g.uiDepth(), -48);
|
||||
assert.equal(g.windowFramed(), true);
|
||||
// Full panel: windows fill the panel and the row overlays the bottom edge while focused.
|
||||
g.settings.displayModeSetting.value = '640x480';
|
||||
assert.deepEqual(g.rect('max'), { x: 0, y: 28, width: 640, height: 452 });
|
||||
// Full Screen: windows take the panel's width over the row, which stays.
|
||||
g.settings.displayLayoutSetting.value = 'fullscreen';
|
||||
assert.deepEqual(g.rect('max'), { x: 0, y: 28, width: 640, height: 416 });
|
||||
assert.deepEqual({ ...g.switcherRect('max') }, { x: 0, y: 444, width: 640, height: 36 });
|
||||
assert.equal(g.sidebarStripVisible('window'), false);
|
||||
assert.equal(g.sidebarStripVisible('sidebar'), true);
|
||||
assert.equal(g.sidebarStripVisible('window'), true);
|
||||
assert.equal(g.windowFramed(), false);
|
||||
});
|
||||
|
||||
test('a fullscreen app fills the panel without chrome rows, frame or depth, in any layout', () => {
|
||||
test('an immersive app fills the panel without chrome rows, frame or depth, in any layout', () => {
|
||||
const panel = { x: 0, y: 0, width: 640, height: 480 };
|
||||
for (const position of ['left', 'right', 'bottom', 'popup']) {
|
||||
const g = geometry();
|
||||
g.settings.appSwitcherPositionSetting.value = position;
|
||||
g.settings.statusBarPositionSetting.value = 'bottom';
|
||||
g.settings.uiDepthSetting.value = '48';
|
||||
assert.equal(g.setAppFullscreen('onboarding', true), true);
|
||||
assert.equal(g.setAppFullscreen('onboarding', true), false);
|
||||
assert.equal(g.setAppImmersive('onboarding', true), true);
|
||||
assert.equal(g.setAppImmersive('onboarding', true), false);
|
||||
for (const mode of ['min', 'medium', 'max']) assert.deepEqual(g.rect(mode, 'onboarding'), panel, position);
|
||||
assert.equal(g.windowFramed('onboarding'), false);
|
||||
assert.equal(g.statusInSwitcherRow('onboarding'), false);
|
||||
// The switcher overlays it while focused, as in the full-panel mode.
|
||||
// The switcher overlays it while focused.
|
||||
assert.equal(g.sidebarStripVisible('window', 'onboarding'), false);
|
||||
assert.equal(g.sidebarStripVisible('sidebar', 'onboarding'), true);
|
||||
assert.equal(g.uiDepth('onboarding'), 0);
|
||||
@@ -225,7 +257,7 @@ test('a fullscreen app fills the panel without chrome rows, frame or depth, in a
|
||||
assert.equal(g.uiDepth('launcher'), depth);
|
||||
assert.equal(g.uiDepth(), depth);
|
||||
assert.notDeepEqual(g.rect('min', 'launcher'), panel);
|
||||
assert.equal(g.setAppFullscreen('onboarding', false), true);
|
||||
assert.equal(g.setAppImmersive('onboarding', false), true);
|
||||
assert.deepEqual(g.rect('min', 'onboarding'), g.rect('min', 'launcher'));
|
||||
assert.equal(g.uiDepth('onboarding'), depth);
|
||||
}
|
||||
@@ -318,17 +350,17 @@ test('a bottom app switcher frames the foreground window\'s content in a rounded
|
||||
// The flat paint carries the same frame.
|
||||
const image = chrome.paint();
|
||||
assert.deepEqual(frames(image).map((d) => [d.x, d.y]), [[31, 105]]);
|
||||
// No frame in the full-panel mode.
|
||||
g.settings.displayModeSetting.value = '640x480';
|
||||
// No frame in the Full Screen mode.
|
||||
g.settings.displayLayoutSetting.value = 'fullscreen';
|
||||
assert.equal(chrome.paintParts().flatMap((p) => frames(p.image)).length, 0);
|
||||
});
|
||||
|
||||
test('over a fullscreen window the chrome draws only the switcher, and only while it has focus', () => {
|
||||
test('over an immersive window the chrome draws only the switcher, and only while it has focus', () => {
|
||||
for (const position of ['bottom', 'popup', 'left']) {
|
||||
const g = geometry();
|
||||
g.settings.appSwitcherPositionSetting.value = position;
|
||||
g.settings.statusBarPositionSetting.value = position === 'left' ? 'top' : 'bottom';
|
||||
g.setAppFullscreen('onboarding', true);
|
||||
g.setAppImmersive('onboarding', true);
|
||||
const { chrome, state } = chromeLayer(g, { windows: 2, notifications: 1 });
|
||||
state.foregroundAppId = 'onboarding';
|
||||
assert.equal(chrome.paintParts().length, 0, position);
|
||||
@@ -396,10 +428,10 @@ test('the status bar can join a bottom app switcher, and windows grow into the t
|
||||
assert.deepEqual(g.rect('medium'), { x: 32, y: 79, width: 576, height: 288 });
|
||||
assert.deepEqual(g.rect('max', 'terminal'), { x: 32, y: 1, width: 576, height: 443 });
|
||||
assert.deepEqual({ ...g.switcherRect('min') }, { x: 32, y: 366, width: 576, height: 36 });
|
||||
// The full-panel mode keeps the top bar: its row shows only while focused.
|
||||
g.settings.displayModeSetting.value = '640x480';
|
||||
assert.equal(g.statusInSwitcherRow(), false);
|
||||
assert.deepEqual(g.rect('max'), { x: 0, y: 28, width: 640, height: 452 });
|
||||
// Full Screen keeps the row, and the status bar in it, but has no frame.
|
||||
g.settings.displayLayoutSetting.value = 'fullscreen';
|
||||
assert.equal(g.statusInSwitcherRow(), true);
|
||||
assert.deepEqual(g.rect('max'), { x: 0, y: 0, width: 640, height: 444 });
|
||||
});
|
||||
|
||||
test('the switcher row lays out windows, free space, notifications, widgets, batteries and the clock', () => {
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
const { test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs'), vm = require('node:vm'), ts = require('typescript');
|
||||
|
||||
// dashboard-settings.ts over an in-memory settings store (as in brightness-curve.test.cjs).
|
||||
function settingsFixture(store = new Map()) {
|
||||
const context = { exports: {}, global: { isIOS: false }, require: id => {
|
||||
if (id.includes('settings-store')) return {
|
||||
onSettingsStoreChanged() {}, getStringSetting: (k, d) => store.get(k) ?? d,
|
||||
setStringSetting: (k, v) => store.set(k, v),
|
||||
getBooleanSetting: (k, d) => store.get(k) ?? d, setBooleanSetting: (k, v) => store.set(k, v),
|
||||
};
|
||||
if (id.includes('brightness-curve')) return require('../.test-build/app/g2/brightness-curve.js');
|
||||
if (id.includes('animation-speed')) return require('../.test-build/app/ui/animation-speed.js');
|
||||
return { Layer: class {}, ASSISTANT_MODEL_CHOICES: [] };
|
||||
}};
|
||||
vm.runInNewContext(ts.transpileModule(fs.readFileSync('app/ui/dashboard-settings.ts', 'utf8'), {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
|
||||
}).outputText, context);
|
||||
return context.exports;
|
||||
}
|
||||
|
||||
test('the display mode starts as the middle band, or carries over the old mode and vertical position', () => {
|
||||
const layout = (entries) => settingsFixture(new Map(entries)).displayLayoutSetting.get();
|
||||
assert.equal(layout([]), 'band-middle');
|
||||
assert.equal(layout([['display.verticalPosition', 'upper']]), 'band-high');
|
||||
assert.equal(layout([['display.mode', '576x288'], ['display.verticalPosition', 'lower']]), 'band-low');
|
||||
assert.equal(layout([['display.mode', '576x480'], ['display.verticalPosition', 'top']]), 'tall');
|
||||
assert.equal(layout([['display.mode', '640x480']]), 'fullscreen');
|
||||
// Once set, the merged setting is its own.
|
||||
const store = new Map([['display.mode', '576x480']]);
|
||||
const api = settingsFixture(store);
|
||||
api.displayLayoutSetting.set('band-bottom');
|
||||
assert.equal(store.get('display.layout'), 'band-bottom');
|
||||
assert.equal(api.displayLayoutSetting.get(), 'band-bottom');
|
||||
});
|
||||
|
||||
test('per-app display modes carry over their old mode and position where the merged values can say it', () => {
|
||||
const app = (appId, entries) => settingsFixture(new Map(entries))[`${appId}DisplayLayoutSetting`].get();
|
||||
assert.equal(app('navigate', []), 'global');
|
||||
assert.equal(app('terminal', []), 'default');
|
||||
assert.equal(app('navigate', [['navigate.displayMode', '576x288'], ['navigate.verticalPosition', 'bottom']]), 'band-bottom');
|
||||
// A band at the global position takes the global band.
|
||||
assert.equal(app('navigate', [['navigate.displayMode', '576x288'], ['display.verticalPosition', 'top']]), 'band-top');
|
||||
assert.equal(app('navigate', [['navigate.displayMode', '576x288'], ['display.layout', 'band-low']]), 'band-low');
|
||||
// Following the global band at a position of its own.
|
||||
assert.equal(app('navigate', [['navigate.verticalPosition', 'top']]), 'band-top');
|
||||
assert.equal(app('navigate', [['navigate.verticalPosition', 'top'], ['display.mode', '576x480']]), 'global');
|
||||
assert.equal(app('terminal', [['terminal.displayMode', '640x480']]), 'fullscreen');
|
||||
assert.equal(app('terminal', [['terminal.displayMode', 'global']]), 'global');
|
||||
assert.equal(app('terminal', [['terminal.verticalPosition', 'lower']]), 'default');
|
||||
});
|
||||
|
||||
test('Full Screen is offered only with a bottom or popup app switcher', () => {
|
||||
const store = new Map();
|
||||
const api = settingsFixture(store);
|
||||
for (const [position, available] of [['left', false], ['right', false], ['bottom', true], ['popup', true]]) {
|
||||
api.appSwitcherPositionSetting.set(position);
|
||||
assert.equal(api.fullScreenAvailable(), available, position);
|
||||
assert.equal(api.displayLayoutSetting.isDisabled('fullscreen'), !available, position);
|
||||
assert.equal(api.navigateDisplayLayoutSetting.isDisabled('fullscreen'), !available, position);
|
||||
assert.equal(api.displayLayoutSetting.isDisabled('tall'), false);
|
||||
}
|
||||
assert.deepEqual(Array.from(api.DISPLAY_LAYOUT_VALUES, (value) => api.displayLayoutLabel(value)),
|
||||
['Band · Top', 'Band · High', 'Band · Middle', 'Band · Low', 'Band · Bottom', 'Tall', 'Full Screen']);
|
||||
});
|
||||
@@ -182,7 +182,7 @@ 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' }, displayModeSetting: { get: () => 'full' }, displayModeLabel: () => 'Full', showBleBandwidthSetting: { get: () => enabled },
|
||||
'../ui/dashboard-settings': { brightnessSetting: { get: () => 'auto' }, displayLayoutSetting: { displayValue: () => 'Tall' }, showBleBandwidthSetting: { get: () => enabled },
|
||||
onAnySettingChanged: fn => { settingListeners.add(fn); return () => settingListeners.delete(fn); } },
|
||||
'../g2/device-addresses': { loadDeviceAddresses: () => ({}) },
|
||||
'../g2/ios-peripheral-identity': { deviceAddressError: () => 'no test devices' },
|
||||
|
||||
@@ -44,11 +44,11 @@ function recorder(width, height) {
|
||||
};
|
||||
}
|
||||
|
||||
test('the layout page fits four 40%-wide diagrams with captions on the fullscreen panel', () => {
|
||||
test('the layout page fits four 40%-wide diagrams with captions on the immersive panel', () => {
|
||||
const { load } = harness();
|
||||
const { LayoutPage } = load('app/apps/onboarding/layout-page.ts');
|
||||
const page = new LayoutPage();
|
||||
assert.equal(page.fullscreen, true);
|
||||
assert.equal(page.immersive, true);
|
||||
const image = recorder(640, 480);
|
||||
page.paint(image, true);
|
||||
// Each diagram's outline spans the display's width at 40%.
|
||||
@@ -162,7 +162,7 @@ test('the depth page follows layouts that have depth, sits in the layout, and ap
|
||||
});
|
||||
const { DepthPage } = mocks('app/apps/onboarding/depth-page.ts');
|
||||
const page = new DepthPage();
|
||||
assert.equal(page.fullscreen, undefined);
|
||||
assert.equal(page.immersive, undefined);
|
||||
for (const [position, applies] of [['left', false], ['right', false], ['bottom', true], ['popup', true]]) {
|
||||
settings.appSwitcherPositionSetting.value = position;
|
||||
assert.equal(page.applies(), applies, position);
|
||||
@@ -178,12 +178,12 @@ test('the depth page follows layouts that have depth, sits in the layout, and ap
|
||||
assert.equal(next, 1);
|
||||
});
|
||||
|
||||
test('the flow switches fullscreen per page and skips pages that do not apply, both ways', async () => {
|
||||
test('the flow switches immersive mode per page and skips pages that do not apply, both ways', async () => {
|
||||
const shell = { yields: 0, yieldFocusToSidebar() { this.yields++; } };
|
||||
const load = loader({}, {
|
||||
'../../graphics/image': { GrayImage: class {} },
|
||||
'../../ui/shell/in-process-window': {}, '../../ui/shell/shell': { shell }, '../../ui/sound-effects': {},
|
||||
'./data-collection-page': {}, './depth-page': {}, './ios-privacy-page': {}, './layout-page': {},
|
||||
'./data-collection-page': {}, './depth-page': {}, './display-mode-page': {}, './ios-privacy-page': {}, './layout-page': {},
|
||||
'./onboarding-progress': {}, './text-size-page': {}, './welcome-page': {},
|
||||
});
|
||||
const { OnboardingLayer } = load('app/apps/onboarding/onboarding-app.ts');
|
||||
@@ -191,27 +191,73 @@ test('the flow switches fullscreen per page and skips pages that do not apply, b
|
||||
const entered = [];
|
||||
const page = (name, extra) => ({ ...extra, enter: () => entered.push(name),
|
||||
handleInput: (event, nav) => { if (event.type === 'click') nav.next(); } });
|
||||
const fullscreen = [];
|
||||
const immersive = [];
|
||||
let finished = 0;
|
||||
const layer = new OnboardingLayer([
|
||||
page('welcome', { fullscreen: true }), page('layout', { fullscreen: true }),
|
||||
page('welcome', { immersive: true }), page('layout', { immersive: true }),
|
||||
page('depth', { applies: () => depthApplies }), page('voice', {}),
|
||||
], (value) => fullscreen.push(value), () => finished++);
|
||||
], (value) => immersive.push(value), () => finished++);
|
||||
const input = (type) => layer.handleInput({ type });
|
||||
await input('click');
|
||||
await input('click');
|
||||
assert.deepEqual(entered, ['welcome', 'layout', 'voice'], 'depth skipped going forward');
|
||||
assert.deepEqual(fullscreen, [true, false]);
|
||||
assert.deepEqual(immersive, [true, false]);
|
||||
await input('double-click');
|
||||
assert.deepEqual(entered.at(-1), 'layout', 'and going back');
|
||||
depthApplies = true;
|
||||
await input('click');
|
||||
await input('click');
|
||||
assert.deepEqual(entered.slice(-2), ['depth', 'voice']);
|
||||
assert.deepEqual(fullscreen, [true, false, true, false, false]);
|
||||
assert.deepEqual(immersive, [true, false, true, false, false]);
|
||||
await input('click');
|
||||
assert.equal(finished, 1);
|
||||
for (let i = 0; i < 4; i++) await input('double-click');
|
||||
assert.equal(entered.at(-1), 'welcome');
|
||||
assert.equal(shell.yields, 1, 'double-click on the first page leaves the app');
|
||||
});
|
||||
|
||||
test('the display mode page offers Full Screen only where the layout allows it, and applies the mode as it scrolls', () => {
|
||||
const values = ['band-top', 'band-high', 'band-middle', 'band-low', 'band-bottom', 'tall', 'fullscreen'];
|
||||
const settings = {
|
||||
appSwitcherPositionSetting: setting('bottom', ['left', 'right', 'bottom', 'popup']),
|
||||
displayLayoutSetting: { ...setting('fullscreen', values), displayValue: (v) => v,
|
||||
isDisabled: (v) => v === 'fullscreen' && ['left', 'right'].includes(settings.appSwitcherPositionSetting.value) },
|
||||
};
|
||||
const menu = { selected: null, items: [], setItems(items, index) { this.items = items; this.selected = index; },
|
||||
get selectedItem() { return this.items[this.selected] ?? null; }, paint(image, box) { this.box = box; },
|
||||
async handleInput(event) { this.selected = Math.max(0, Math.min(this.items.length - 1, this.selected + (event.type === 'scroll-down' ? 1 : -1))); } };
|
||||
const load = loader({}, {
|
||||
'./onboarding-fonts': { onboardingFont: font },
|
||||
'../../ui/dashboard-settings': settings,
|
||||
'../../ui/menu-core': { Menu: class { constructor() { return menu; } } },
|
||||
'../../ui/metrics': { LIST_ROW_TEXT_INSET: 4, listRowHeight: (f) => f.lineHeight + 8 },
|
||||
});
|
||||
const { DisplayModePage } = load('app/apps/onboarding/display-mode-page.ts');
|
||||
const page = new DisplayModePage();
|
||||
// An ordinary window, which the mode being applied resizes.
|
||||
assert.equal(page.immersive, undefined);
|
||||
page.enter();
|
||||
assert.deepEqual(Array.from(menu.items), values);
|
||||
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);
|
||||
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/);
|
||||
let next = 0;
|
||||
const nav = { next: () => next++ };
|
||||
page.handleInput({ type: 'scroll-up' }, nav);
|
||||
page.handleInput({ type: 'scroll-up' }, nav);
|
||||
assert.deepEqual(settings.displayLayoutSetting.writes, ['tall', 'band-bottom'], 'applied as it scrolls');
|
||||
page.handleInput({ type: 'click' }, nav);
|
||||
assert.equal(next, 1);
|
||||
assert.deepEqual(settings.displayLayoutSetting.writes, ['tall', 'band-bottom']);
|
||||
// Beside a side strip, a saved Full Screen shows as Tall, and is saved as such on a tap.
|
||||
settings.displayLayoutSetting.value = 'fullscreen';
|
||||
settings.appSwitcherPositionSetting.value = 'left';
|
||||
page.enter();
|
||||
assert.deepEqual(Array.from(menu.items), values.slice(0, 6));
|
||||
assert.equal(menu.selectedItem, 'tall');
|
||||
page.handleInput({ type: 'click' }, nav);
|
||||
assert.equal(settings.displayLayoutSetting.value, 'tall');
|
||||
});
|
||||
@@ -10,8 +10,8 @@ function fixture() {
|
||||
}
|
||||
const settings = {
|
||||
brightnessSetting: { get: () => brightness, set: value => { brightness = value; writes.push(value); } },
|
||||
displayModeSetting: { get: () => mode, set: value => { mode = value; } },
|
||||
DISPLAY_MODE_VALUES: ['small', 'large'], displayModeLabel: value => value === 'small' ? 'Small' : 'Large',
|
||||
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 } },
|
||||
@@ -51,10 +51,13 @@ test('shared brightness controls snap manual levels and restore the manual value
|
||||
assert.equal(h.brightness(), '2');
|
||||
});
|
||||
|
||||
test('shared screen-size picker preserves cancellation and applies the selected mode', async () => {
|
||||
test('shared 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 ▾');
|
||||
|
||||
Reference in new issue
Block a user