mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-27 07:59:33 +01:00
feat(desktop): the whole-display full screen is on by default, has a switch in App Settings, and the tabs go around the camera
Three things the owner asked for after seeing the first build on a MacBook
Pro with a camera housing, and one bug that run found.
On by default. `wholeScreen` in desktop.json now reads as on when it is
absent. The View menu item shows only while a display with a housing is
connected, since the option's own value no longer says anything about the Mac.
A switch in App Settings (Appearance > Mac App). The setting stays the app's:
the app tells each page what the switch shows
(`CodemanHostCutout.option({ available, enabled })`, on every page load and
whenever it changes), the group shows only inside the app on a Mac with such a
display, and saving sends a changed switch back through
`CodemanHost.setWholeScreen` (IPC `wholeScreen`, trusted frames only). The
menu item and every open page follow. It is never a key of the settings the
page stores or the server keeps.
Tabs on both sides of the camera. The toolbar's box used to start left of the
housing, so the first row of tabs ended there and the room up to the toolbar
stayed empty: three of ten tabs in the first row on that display. Now
`fitTabs()` reads the tabs' rectangles, finds the one that would overlap the
housing and gives the room to the tab before it as its right margin, so the
row carries on right of the housing (five of ten there, same header height).
Nothing is added to the strip and no tab is reordered. The tab strip calls it
once its row mode is decided and before it measures one row; a resize observer
follows a tab that grows or is added with no render behind it. The toolbar
keeps its own box, a user-chosen width included, and takes the covering box
(`html.host-cutout-toolbar`) only when it would reach the housing, and in a
solo window.
The bug: a window that comes out of a macOS Space is its own first responder
and takes no keys. Ticking the option while in macOS's full screen left the
terminal with a hollow cursor until a click. The web view now gets the keys
when nothing else had them.
Seen on the MacBook with the first build: launch into the mode, typing, the
menu bar sliding in over the header, leaving and entering, both change-overs,
relaunch, command+W, Dock and menu bar never stuck. Not yet seen there: this
commit's default, switch and focus fix (the Mac went to sleep before the
second round).
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
d5ddf2e250
commit
150f01e9b4
18 files changed
+899
-118
No files matched your search
@@ -1,12 +1,14 @@
|
||||
/**
|
||||
* @fileoverview Real-Chromium coverage for the header beside a camera housing (host-cutout.js and the
|
||||
* `html.host-cutout` rules in styles.css).
|
||||
* `html.host-cutout-toolbar` rules in styles.css).
|
||||
*
|
||||
* Codeman Desktop can draw the page behind the notch of a MacBook display, and whatever the header puts there
|
||||
* cannot be seen or clicked. What only a real layout engine answers: that no tab, button or reading ends up
|
||||
* behind the housing, in a single row, in a wrapped (L-shaped) strip and with a toolbar too wide for the room
|
||||
* beside it, and that taking the housing away puts the header back exactly. The real `<header>` from
|
||||
* index.html, the shipping styles.css, constants.js, app.js and host-cutout.js are loaded into a page.
|
||||
* beside it; that the tabs carry on right of the housing where there is room; that a tab changing size with
|
||||
* no render behind it is followed; and that taking the housing away puts the header back exactly. The real
|
||||
* `<header>` from index.html, the shipping styles.css, constants.js, app.js and host-cutout.js are loaded
|
||||
* into a page.
|
||||
*
|
||||
* Port: none (page.route on a fake origin, no server).
|
||||
*/
|
||||
@@ -27,12 +29,15 @@ type Cutout = { left: number; width: number; height: number };
|
||||
|
||||
/** MacBook displays in whole-screen mode: viewport and housing, in points. */
|
||||
const DISPLAYS: Array<{ name: string; width: number; height: number; cutout: Cutout }> = [
|
||||
// Measured on a MacBook Pro (Mac17,13, macOS 27.2): a narrow housing in a taller strip.
|
||||
{ name: 'narrow housing, default', width: 1512, height: 993, cutout: { left: 726.5, width: 59, height: 40 } },
|
||||
{ name: '14-inch, default', width: 1512, height: 982, cutout: { left: 663.5, width: 185, height: 32 } },
|
||||
{ name: '16-inch, default', width: 1728, height: 1117, cutout: { left: 771.5, width: 185, height: 32 } },
|
||||
{ name: '14-inch, more space', width: 1800, height: 1169, cutout: { left: 790, width: 220, height: 38 } },
|
||||
{ name: '14-inch, larger text', width: 1147, height: 745, cutout: { left: 503.5, width: 140, height: 24 } },
|
||||
];
|
||||
const MBP14 = DISPLAYS[0];
|
||||
const NARROW = DISPLAYS[0];
|
||||
const MBP14 = DISPLAYS[1];
|
||||
|
||||
describe('header beside a camera housing (real Chromium)', () => {
|
||||
let browser: Browser;
|
||||
@@ -109,6 +114,12 @@ describe('header beside a camera housing (real Chromium)', () => {
|
||||
const toolbar = () =>
|
||||
p.evaluate(() => document.getElementById('headerRight')!.getBoundingClientRect().toJSON()) as Promise<Rect>;
|
||||
const cornered = () => p.evaluate(() => document.getElementById('sessionTabs')!.classList.contains('tabs-corner'));
|
||||
/** Whether the toolbar has the box that covers the housing. */
|
||||
const boxed = () => p.evaluate(() => document.documentElement.classList.contains('host-cutout-toolbar'));
|
||||
/** Tabs that carry a margin of the module's. */
|
||||
const moved = () =>
|
||||
p.evaluate(() => document.querySelectorAll('#sessionTabs > .session-tab[style*="margin"]').length);
|
||||
const tabRects = async () => (await painted()).filter((r) => r.what.startsWith('tab '));
|
||||
|
||||
/** Everything the header row paints: tabs, the brand, the toolbar's controls. */
|
||||
const painted = () =>
|
||||
@@ -153,50 +164,96 @@ describe('header beside a camera housing (real Chromium)', () => {
|
||||
);
|
||||
|
||||
for (const display of DISPLAYS) {
|
||||
it(`keeps one row of tabs and the toolbar clear of the housing (${display.name})`, async () => {
|
||||
const right = display.cutout.left + display.cutout.width;
|
||||
|
||||
it(`leaves a short row of tabs and the toolbar as they are (${display.name})`, async () => {
|
||||
await open({ tabs: 3, width: display.width, height: display.height });
|
||||
const before = { toolbar: await toolbar(), painted: await painted() };
|
||||
await apply(display.cutout);
|
||||
// Three tabs end long before the housing and the toolbar begins long after it: nothing has to move.
|
||||
expect(await behind(display.cutout)).toEqual([]);
|
||||
const box = await toolbar();
|
||||
// The toolbar's box starts just left of the housing, so the tab strip ends there...
|
||||
expect(box.left).toBeLessThanOrEqual(display.cutout.left);
|
||||
expect(box.left).toBeGreaterThan(display.cutout.left - 16);
|
||||
// ...and still ends where the header's padding begins.
|
||||
expect(Math.round(display.width - box.right)).toBe(12);
|
||||
expect(await boxed()).toBe(false);
|
||||
expect(await moved()).toBe(0);
|
||||
expect(await toolbar()).toEqual(before.toolbar);
|
||||
expect(await painted()).toEqual(before.painted);
|
||||
await p.close();
|
||||
});
|
||||
|
||||
it(`keeps a wrapped strip clear of the housing, and its later rows full width (${display.name})`, async () => {
|
||||
it(`carries the first row of a wrapped strip on past the housing (${display.name})`, async () => {
|
||||
await open({ tabs: 34, width: display.width, height: display.height });
|
||||
const natural = await toolbar();
|
||||
await apply(display.cutout);
|
||||
expect(await cornered()).toBe(true);
|
||||
expect(await behind(display.cutout)).toEqual([]);
|
||||
const box = await toolbar();
|
||||
const tabs = (await painted()).filter((r) => r.what.startsWith('tab '));
|
||||
const beside = tabs.filter((t) => t.top < box.bottom);
|
||||
const below = tabs.filter((t) => t.top >= box.bottom);
|
||||
// The rows beside the toolbar's box stop at the housing; the rows below it run on past the housing.
|
||||
expect(beside.length).toBeGreaterThan(0);
|
||||
expect(Math.max(...beside.map((t) => t.right))).toBeLessThan(display.cutout.left);
|
||||
expect(Math.max(...below.map((t) => t.right))).toBeGreaterThan(display.cutout.left + display.cutout.width);
|
||||
// The toolbar keeps its own box, and the tabs fill the row up to it on both sides of the housing.
|
||||
expect(await boxed()).toBe(false);
|
||||
expect(await toolbar()).toEqual(natural);
|
||||
const tabs = await tabRects();
|
||||
const first = tabs.filter((t) => t.top < display.cutout.height);
|
||||
expect(first.some((t) => t.right <= display.cutout.left)).toBe(true);
|
||||
expect(first.some((t) => t.left >= right)).toBe(true);
|
||||
// The first tab right of the housing starts where its 8 px of air end, not somewhere further on.
|
||||
const next = Math.min(...first.filter((t) => t.left >= right).map((t) => t.left));
|
||||
expect(next).toBeGreaterThanOrEqual(right + 8);
|
||||
expect(next).toBeLessThan(right + 10);
|
||||
// Rows below the housing are not touched: some tab there lies in the housing's column.
|
||||
const below = tabs.filter((t) => t.top >= display.cutout.height);
|
||||
expect(below.some((t) => t.left < right && t.right > display.cutout.left)).toBe(true);
|
||||
// One tab per row beside the housing gave up its margin for the gap, and no tab was added to the strip.
|
||||
const rows = new Set(first.map((t) => Math.round(t.top))).size;
|
||||
expect(await moved()).toBe(rows);
|
||||
expect(await p.evaluate(() => document.getElementById('sessionTabs')!.children.length)).toBe(34);
|
||||
await p.close();
|
||||
});
|
||||
}
|
||||
|
||||
it('keeps a strip that is too tall for the corner left of the housing altogether', async () => {
|
||||
// Past its max-height the strip scrolls and keeps the plain wrap (_syncTabStripCorner): every row then
|
||||
// ends where the toolbar's box begins, which is the housing's left edge.
|
||||
const display = DISPLAYS[3];
|
||||
await open({ tabs: 40, width: display.width, height: display.height });
|
||||
it('keeps a strip that is too tall for the corner clear of the housing too', async () => {
|
||||
// Past its max-height the strip scrolls and keeps the plain wrap (_syncTabStripCorner).
|
||||
const display = DISPLAYS[4];
|
||||
await open({ tabs: 140, width: display.width, height: display.height });
|
||||
await apply(display.cutout);
|
||||
expect(await cornered()).toBe(false);
|
||||
expect(await behind(display.cutout)).toEqual([]);
|
||||
const tabs = (await painted()).filter((r) => r.what.startsWith('tab '));
|
||||
expect(Math.max(...tabs.map((t) => t.right))).toBeLessThan(display.cutout.left);
|
||||
// Scrolled, the rows that come up beside the housing are cleared as well.
|
||||
await p.evaluate(() => (document.getElementById('sessionTabs')!.scrollTop = 40));
|
||||
await settled();
|
||||
expect(await behind(display.cutout)).toEqual([]);
|
||||
await p.close();
|
||||
});
|
||||
|
||||
it('wraps a toolbar that is wider than the room beside the housing, below the housing', async () => {
|
||||
it('follows a tab that grows with no render behind it (a selection shows its gear and close)', async () => {
|
||||
await open({ tabs: 34, width: NARROW.width, height: NARROW.height });
|
||||
await apply(NARROW.cutout);
|
||||
// The last tab left of the housing gets wider, as a selected one does, and nothing calls the strip.
|
||||
await p.evaluate((left) => {
|
||||
const tabs = [...document.querySelectorAll<HTMLElement>('#sessionTabs > .session-tab')];
|
||||
const row = tabs.filter((t) => t.getBoundingClientRect().top < 40 && t.getBoundingClientRect().right <= left);
|
||||
row[row.length - 1].style.paddingRight = '90px';
|
||||
}, NARROW.cutout.left);
|
||||
await settled();
|
||||
await settled();
|
||||
expect(await behind(NARROW.cutout)).toEqual([]);
|
||||
await p.close();
|
||||
});
|
||||
|
||||
it('follows a tab that is added with no render behind it', async () => {
|
||||
await open({ tabs: 34, width: NARROW.width, height: NARROW.height });
|
||||
await apply(NARROW.cutout);
|
||||
await p.evaluate(() => {
|
||||
document
|
||||
.getElementById('sessionTabs')!
|
||||
.insertAdjacentHTML(
|
||||
'afterbegin',
|
||||
'<div class="session-tab" data-id="new" role="tab"><span class="tab-name">a-new-session</span></div>'
|
||||
);
|
||||
});
|
||||
await settled();
|
||||
await settled();
|
||||
expect(await behind(NARROW.cutout)).toEqual([]);
|
||||
await p.close();
|
||||
});
|
||||
|
||||
it('gives a toolbar that would reach the housing the box that covers it, wrapped below the housing', async () => {
|
||||
await open({ tabs: 3, width: MBP14.width, height: MBP14.height });
|
||||
// A toolbar full of readings: wider than the 660 px right of the housing.
|
||||
await p.evaluate(() => {
|
||||
@@ -211,11 +268,22 @@ describe('header beside a camera housing (real Chromium)', () => {
|
||||
await relayout();
|
||||
const before = await toolbar();
|
||||
await apply(MBP14.cutout);
|
||||
expect(await boxed()).toBe(true);
|
||||
const after = await toolbar();
|
||||
// Its box starts just left of the housing and still ends where the header's padding begins.
|
||||
expect(after.left).toBeLessThanOrEqual(MBP14.cutout.left);
|
||||
expect(after.left).toBeGreaterThan(MBP14.cutout.left - 16);
|
||||
expect(Math.round(MBP14.width - after.right)).toBe(12);
|
||||
expect(after.bottom - after.top).toBeGreaterThan(before.bottom - before.top + 16);
|
||||
expect(await behind(MBP14.cutout)).toEqual([]);
|
||||
// Nothing is cut off either: every control is inside the viewport.
|
||||
for (const r of await painted()) expect(r.left, r.what).toBeGreaterThanOrEqual(0);
|
||||
// Readings that go away give the toolbar its own box back.
|
||||
await p.evaluate(() => document.querySelectorAll('.test-reading').forEach((el) => el.remove()));
|
||||
await settled();
|
||||
await settled();
|
||||
expect(await boxed()).toBe(false);
|
||||
expect(await behind(MBP14.cutout)).toEqual([]);
|
||||
await p.close();
|
||||
});
|
||||
|
||||
@@ -223,15 +291,17 @@ describe('header beside a camera housing (real Chromium)', () => {
|
||||
await open({ tabs: 40, width: MBP14.width, height: MBP14.height });
|
||||
const before = { toolbar: await toolbar(), painted: await painted() };
|
||||
await apply(MBP14.cutout);
|
||||
expect(await toolbar()).not.toEqual(before.toolbar);
|
||||
expect(await painted()).not.toEqual(before.painted);
|
||||
await apply(null);
|
||||
expect(await toolbar()).toEqual(before.toolbar);
|
||||
expect(await painted()).toEqual(before.painted);
|
||||
expect(await moved()).toBe(0);
|
||||
expect(await p.evaluate(() => document.documentElement.getAttribute('style') || '')).not.toContain('host-cutout');
|
||||
expect(await p.evaluate(() => document.documentElement.className)).not.toContain('host-cutout');
|
||||
await p.close();
|
||||
});
|
||||
|
||||
it('sets aside a toolbar width the user chose while the housing is there', async () => {
|
||||
it('keeps a toolbar width the user chose while it ends right of the housing', async () => {
|
||||
await open({
|
||||
tabs: 3,
|
||||
width: MBP14.width,
|
||||
@@ -241,7 +311,24 @@ describe('header beside a camera housing (real Chromium)', () => {
|
||||
const chosen = await toolbar();
|
||||
expect(Math.round(chosen.right - chosen.left)).toBe(300);
|
||||
await apply(MBP14.cutout);
|
||||
// 300 px would end the toolbar right of the housing and let the tabs run behind it.
|
||||
expect(await boxed()).toBe(false);
|
||||
expect(await toolbar()).toEqual(chosen);
|
||||
expect(await behind(MBP14.cutout)).toEqual([]);
|
||||
await p.close();
|
||||
});
|
||||
|
||||
it('sets a chosen toolbar width aside while it would reach the housing', async () => {
|
||||
await open({
|
||||
tabs: 3,
|
||||
width: MBP14.width,
|
||||
height: MBP14.height,
|
||||
attrs: 'data-header-right-width="set" style="--header-right-width: 800px"',
|
||||
});
|
||||
const chosen = await toolbar();
|
||||
expect(Math.round(chosen.right - chosen.left)).toBe(800);
|
||||
await apply(MBP14.cutout);
|
||||
// 800 px begins the toolbar's box at 700, under the housing: it takes the box that covers the housing.
|
||||
expect(await boxed()).toBe(true);
|
||||
expect((await toolbar()).left).toBeLessThanOrEqual(MBP14.cutout.left);
|
||||
expect(await behind(MBP14.cutout)).toEqual([]);
|
||||
await apply(null);
|
||||
@@ -249,11 +336,13 @@ describe('header beside a camera housing (real Chromium)', () => {
|
||||
await p.close();
|
||||
});
|
||||
|
||||
it('keeps the toolbar right of the housing where the header has no tabs (sidebar, rail, solo window)', async () => {
|
||||
it('leaves the toolbar alone where the header has no tabs (sidebar, rail)', async () => {
|
||||
await open({ tabs: 0, width: MBP14.width, height: MBP14.height });
|
||||
const natural = await toolbar();
|
||||
await apply(MBP14.cutout);
|
||||
expect(await behind(MBP14.cutout)).toEqual([]);
|
||||
expect((await toolbar()).left).toBeLessThanOrEqual(MBP14.cutout.left);
|
||||
expect(await boxed()).toBe(false);
|
||||
expect(await toolbar()).toEqual(natural);
|
||||
await p.close();
|
||||
});
|
||||
});
|
||||
+321
-12
@@ -1,7 +1,9 @@
|
||||
/**
|
||||
* @fileoverview The camera housing module (host-cutout.js): what counts as a housing, when the page tells a
|
||||
* native wrapper that it may be drawn behind one, what `apply` writes, and that the page, the build and the
|
||||
* stylesheet carry it. The layout itself is measured in real Chromium (host-cutout.browser.test.ts).
|
||||
* native wrapper that it may be drawn behind one, what `apply` writes, how the tabs are moved around the
|
||||
* housing and when the toolbar takes the box that covers it, the option's switch, and that the page, the
|
||||
* build and the stylesheet carry it. The tabs here are a row model (widths, margins, a wrap width); the
|
||||
* layout itself is measured in real Chromium (host-cutout.browser.test.ts).
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { readFileSync } from 'node:fs';
|
||||
@@ -18,18 +20,42 @@ type Api = {
|
||||
apply: (cutout: unknown) => boolean;
|
||||
normalize: (cutout: unknown) => Cutout | null;
|
||||
fits: () => boolean;
|
||||
fitTabs: () => boolean;
|
||||
option: (state: unknown) => boolean;
|
||||
wholeScreen: () => { available: boolean; enabled: boolean } | null;
|
||||
setWholeScreen: (on: unknown) => boolean;
|
||||
current: () => Cutout | null;
|
||||
};
|
||||
|
||||
/** The MacBook Pro the layout was first seen on (Mac17,13): a housing 59 px wide in a strip 40 px high. */
|
||||
const NARROW: Cutout = { left: 726.5, width: 59, height: 40 };
|
||||
|
||||
type Rect = { left: number; right: number; top: number; bottom: number; width: number; height: number };
|
||||
|
||||
/** A 14-inch MacBook Pro at its default scaling. */
|
||||
const MBP14: Cutout = { left: 663.5, width: 185, height: 32 };
|
||||
|
||||
/**
|
||||
* Run the module in a page that has `dataset` on <html> and, with `host`, the bridge Codeman Desktop injects.
|
||||
* `tabs` are widths: they are laid out the way the strip lays them out, left to right from `stripLeft`, 2 px
|
||||
* apart, wrapping to a new row (36 px lower) before `rowRight`, and a margin the module sets moves them like a
|
||||
* real one. `toolbarLeft` is where the toolbar's own box begins (null: the header is not parsed yet).
|
||||
* Returns the module, what it told the bridge, the root's style and classes, and how to change the layout.
|
||||
*/
|
||||
function load(options: { dataset?: Record<string, string>; host?: boolean; pathname?: string; solo?: string } = {}) {
|
||||
function load(
|
||||
options: {
|
||||
dataset?: Record<string, string>;
|
||||
host?: boolean;
|
||||
pathname?: string;
|
||||
solo?: string;
|
||||
tabs?: number[];
|
||||
stripLeft?: number;
|
||||
rowRight?: number;
|
||||
toolbarLeft?: number | null;
|
||||
} = {}
|
||||
) {
|
||||
const calls: unknown[] = [];
|
||||
const switched: unknown[] = [];
|
||||
const relayouts: string[] = [];
|
||||
const props = new Map<string, string>();
|
||||
const classes = new Set<string>();
|
||||
@@ -40,6 +66,7 @@ function load(options: { dataset?: Record<string, string>; host?: boolean; pathn
|
||||
...options.dataset,
|
||||
};
|
||||
let observer: (() => void) | null = null;
|
||||
let ready: (() => void) | null = null;
|
||||
const documentElement = {
|
||||
dataset,
|
||||
style: {
|
||||
@@ -49,20 +76,102 @@ function load(options: { dataset?: Record<string, string>; host?: boolean; pathn
|
||||
classList: {
|
||||
add: (name: string) => classes.add(name),
|
||||
remove: (name: string) => classes.delete(name),
|
||||
contains: (name: string) => classes.has(name),
|
||||
toggle: (name: string, on: boolean) => (on ? classes.add(name) : classes.delete(name)),
|
||||
},
|
||||
};
|
||||
|
||||
const stripLeft = options.stripLeft ?? 100;
|
||||
const rowRight = options.rowRight ?? 1123;
|
||||
const px = (value: string | undefined, fallback: number) => (value === undefined ? fallback : parseFloat(value));
|
||||
const tabs = (options.tabs ?? []).map((width, index) => ({
|
||||
index,
|
||||
width,
|
||||
margins: new Map<string, string>(),
|
||||
rect: null as Rect | null,
|
||||
}));
|
||||
const layout = () => {
|
||||
let x = stripLeft;
|
||||
let top = 8;
|
||||
for (const tab of tabs) {
|
||||
const before = px(tab.margins.get('margin-left'), 0);
|
||||
const after = px(tab.margins.get('margin-right'), 2);
|
||||
if (x > stripLeft && x + before + tab.width + after > rowRight) {
|
||||
x = stripLeft;
|
||||
top += 36;
|
||||
}
|
||||
tab.rect = {
|
||||
left: x + before,
|
||||
right: x + before + tab.width,
|
||||
top,
|
||||
bottom: top + 30,
|
||||
width: tab.width,
|
||||
height: 30,
|
||||
};
|
||||
x += before + tab.width + after;
|
||||
}
|
||||
};
|
||||
const tabElements = tabs.map((tab) => ({
|
||||
model: tab,
|
||||
style: {
|
||||
setProperty: (name: string, value: string) => tab.margins.set(name, value),
|
||||
removeProperty: (name: string) => tab.margins.delete(name),
|
||||
},
|
||||
getBoundingClientRect: () => {
|
||||
layout();
|
||||
return tab.rect;
|
||||
},
|
||||
}));
|
||||
const strip = {
|
||||
dataset: {} as Record<string, string>,
|
||||
querySelectorAll: () => tabElements,
|
||||
addEventListener: () => {},
|
||||
};
|
||||
let toolbarLeft = options.toolbarLeft === undefined ? 1131 : options.toolbarLeft;
|
||||
const toolbar = {
|
||||
children: [{ offsetWidth: 200 }, { offsetWidth: 120 }],
|
||||
getBoundingClientRect: () => ({ left: toolbarLeft ?? 0, width: 1500 - (toolbarLeft ?? 0) }),
|
||||
};
|
||||
let headerParsed = toolbarLeft !== null;
|
||||
|
||||
const window: Record<string, unknown> = {
|
||||
innerWidth: 1512,
|
||||
app: {
|
||||
updateTabOverflowMode: () => relayouts.push('tabs'),
|
||||
// The real one ends by having the module place the tabs (app.js, updateTabOverflowMode).
|
||||
updateTabOverflowMode: () => {
|
||||
relayouts.push('tabs');
|
||||
(window.CodemanHostCutout as Api).fitTabs();
|
||||
},
|
||||
updateConnectionLines: () => relayouts.push('lines'),
|
||||
},
|
||||
};
|
||||
if (options.solo !== undefined) window.__CODEMAN_SOLO__ = options.solo;
|
||||
if (options.host !== false) window.CodemanHost = { cutoutReady: (ready: unknown) => calls.push(ready) };
|
||||
if (options.host !== false) {
|
||||
window.CodemanHost = {
|
||||
cutoutReady: (yes: unknown) => calls.push(yes),
|
||||
setWholeScreen: (on: unknown) => {
|
||||
switched.push(on);
|
||||
return true;
|
||||
},
|
||||
};
|
||||
}
|
||||
const context = vm.createContext({
|
||||
window,
|
||||
document: { documentElement },
|
||||
document: {
|
||||
documentElement,
|
||||
getElementById: (id: string) => {
|
||||
if (id === 'sessionTabs') return headerParsed ? strip : null;
|
||||
if (id === 'headerRight') return headerParsed ? toolbar : null;
|
||||
return null;
|
||||
},
|
||||
addEventListener: (type: string, callback: () => void) => {
|
||||
if (type === 'DOMContentLoaded') ready = callback;
|
||||
},
|
||||
},
|
||||
location: { pathname: options.pathname ?? '/' },
|
||||
getComputedStyle: (element: (typeof tabElements)[number]) => ({
|
||||
getPropertyValue: (name: string) => element.model.margins.get(name) ?? (name === 'margin-right' ? '2px' : '0px'),
|
||||
}),
|
||||
MutationObserver: class {
|
||||
constructor(callback: () => void) {
|
||||
observer = callback;
|
||||
@@ -76,15 +185,34 @@ function load(options: { dataset?: Record<string, string>; host?: boolean; pathn
|
||||
vm.runInContext(read('host-cutout.js'), context, { filename: 'host-cutout.js' });
|
||||
return {
|
||||
api: window.CodemanHostCutout as Api,
|
||||
window,
|
||||
calls,
|
||||
switched,
|
||||
relayouts,
|
||||
props,
|
||||
classes,
|
||||
/** Where each tab is now: `[left, right, top]`. */
|
||||
places() {
|
||||
layout();
|
||||
return tabs.map((tab) => [tab.rect!.left, tab.rect!.right, tab.rect!.top]);
|
||||
},
|
||||
/** The margins the module set, by tab index. */
|
||||
margins() {
|
||||
return Object.fromEntries(
|
||||
tabs.filter((tab) => tab.margins.size).map((tab) => [tab.index, Object.fromEntries(tab.margins)])
|
||||
);
|
||||
},
|
||||
/** Change the layout the way the settings do, and let the observer see it. */
|
||||
setLayout(change: Record<string, string>) {
|
||||
Object.assign(dataset, change);
|
||||
observer?.();
|
||||
},
|
||||
/** The header arrives, as when the parser reaches <body>, with its toolbar beginning at `left`. */
|
||||
parseHeader(left: number) {
|
||||
toolbarLeft = left;
|
||||
headerParsed = true;
|
||||
ready?.();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -176,8 +304,10 @@ describe('camera housing: laying the header out around it', () => {
|
||||
documentElement: {
|
||||
dataset: {},
|
||||
style: { setProperty: (n: string, v: string) => props.set(n, v), removeProperty: () => {} },
|
||||
classList: { add: () => {}, remove: () => {} },
|
||||
classList: { add: () => {}, remove: () => {}, contains: () => false, toggle: () => {} },
|
||||
},
|
||||
getElementById: () => null,
|
||||
addEventListener: () => {},
|
||||
},
|
||||
location: { pathname: '/' },
|
||||
});
|
||||
@@ -251,6 +381,154 @@ describe('camera housing: telling the app whether the page may be drawn behind i
|
||||
});
|
||||
});
|
||||
|
||||
describe('camera housing: the tabs go around it', () => {
|
||||
// Five tabs of 150 px from x = 100, 2 px apart: 100-250, 252-402, 404-554, 556-706, 708-858.
|
||||
// The housing with its 8 px of air on each side is 718.5 to 793.5.
|
||||
const FIVE = [150, 150, 150, 150, 150];
|
||||
|
||||
it('starts the tab that would sit under the housing just right of it', () => {
|
||||
const page = load({ tabs: FIVE });
|
||||
page.api.apply(NARROW);
|
||||
// The room is the right margin of the tab before it: 2 px of its own plus 793.5 - 708, rounded up.
|
||||
expect(page.margins()).toEqual({ 3: { 'margin-right': '88px' } });
|
||||
expect(page.places()).toEqual([
|
||||
[100, 250, 8],
|
||||
[252, 402, 8],
|
||||
[404, 554, 8],
|
||||
[556, 706, 8],
|
||||
[794, 944, 8],
|
||||
]);
|
||||
});
|
||||
|
||||
it('leaves a row alone that the housing does not reach', () => {
|
||||
const page = load({ tabs: [150, 150, 150, 150] });
|
||||
page.api.apply(NARROW);
|
||||
expect(page.margins()).toEqual({});
|
||||
});
|
||||
|
||||
it('wraps a tab that no longer fits right of the housing, flush left', () => {
|
||||
// The row ends at 900: 794 + 150 does not fit before it.
|
||||
const page = load({ tabs: FIVE, rowRight: 900 });
|
||||
page.api.apply(NARROW);
|
||||
expect(page.places()[4]).toEqual([100, 250, 44]);
|
||||
// The margin is the fourth tab's, so the wrapped one carries no indent.
|
||||
expect(page.margins()).toEqual({ 3: { 'margin-right': '88px' } });
|
||||
});
|
||||
|
||||
it('moves the first tab of a row by its own margin, having no tab before it', () => {
|
||||
const page = load({ tabs: [150, 150], stripLeft: 700 });
|
||||
page.api.apply(NARROW);
|
||||
expect(page.margins()).toEqual({ 0: { 'margin-left': '94px' } });
|
||||
expect(page.places()[0]).toEqual([794, 944, 8]);
|
||||
});
|
||||
|
||||
it('clears every row beside a tall housing, and none below it', () => {
|
||||
// Rows at 8 and 44 are beside a housing 60 px high, the one at 80 is not.
|
||||
const tabs = Array.from({ length: 18 }, () => 150);
|
||||
const page = load({ tabs });
|
||||
page.api.apply({ ...NARROW, height: 60 });
|
||||
const under = page.places().filter(([left, right, top]) => top < 60 && right > 718.5 && left < 793.5);
|
||||
expect(under).toEqual([]);
|
||||
const third = page.places().filter(([, , top]) => top === 80);
|
||||
expect(third.some(([left, right]) => right > 718.5 && left < 793.5)).toBe(true);
|
||||
});
|
||||
|
||||
it('says whether a pass moved anything, so the lineage lines are only redrawn when one did', () => {
|
||||
const page = load({ tabs: FIVE });
|
||||
page.api.apply(NARROW);
|
||||
expect(page.api.fitTabs()).toBe(false);
|
||||
expect(page.margins()).toEqual({ 3: { 'margin-right': '88px' } });
|
||||
});
|
||||
|
||||
it('follows the tabs: a wider fourth tab reaches the housing itself and is the one that moves', () => {
|
||||
// A selected tab is wider (its gear and close show): 556 + 170 passes 718.5.
|
||||
const page = load({ tabs: [150, 150, 150, 170, 150] });
|
||||
page.api.apply(NARROW);
|
||||
expect(page.margins()).toEqual({ 2: { 'margin-right': '240px' } });
|
||||
expect(page.places()[3]).toEqual([794, 964, 8]);
|
||||
// The fifth follows it in the row, with nothing under the housing.
|
||||
expect(page.places()[4]).toEqual([966, 1116, 8]);
|
||||
});
|
||||
|
||||
it('takes its margins back when the housing is gone', () => {
|
||||
const page = load({ tabs: FIVE });
|
||||
page.api.apply(NARROW);
|
||||
page.api.apply(null);
|
||||
expect(page.margins()).toEqual({});
|
||||
expect(page.places()[4]).toEqual([708, 858, 8]);
|
||||
});
|
||||
|
||||
it('adds nothing to the strip and never reorders it', () => {
|
||||
const source = read('host-cutout.js');
|
||||
expect(source).not.toMatch(/createElement|insertBefore|appendChild|\.order\b/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('camera housing: the toolbar', () => {
|
||||
it('stays as it is when it ends right of the housing', () => {
|
||||
const page = load({ toolbarLeft: 1131 });
|
||||
page.api.apply(NARROW);
|
||||
expect([...page.classes]).toEqual(['host-cutout']);
|
||||
});
|
||||
|
||||
it('takes the box that covers the housing when it would reach it', () => {
|
||||
// 793 is inside the 8 px of air right of the housing (793.5).
|
||||
const page = load({ toolbarLeft: 793 });
|
||||
page.api.apply(NARROW);
|
||||
expect([...page.classes].sort()).toEqual(['host-cutout', 'host-cutout-toolbar']);
|
||||
page.api.apply(null);
|
||||
expect(page.classes.size).toBe(0);
|
||||
});
|
||||
|
||||
it('always takes it in a solo window, whose title shares the row', () => {
|
||||
const page = load({ pathname: '/session/abc', toolbarLeft: 1131 });
|
||||
page.api.apply(NARROW);
|
||||
expect(page.classes.has('host-cutout-toolbar')).toBe(true);
|
||||
});
|
||||
|
||||
it('covers the housing until the header can be measured, then decides', () => {
|
||||
const page = load({ toolbarLeft: null });
|
||||
page.api.apply(NARROW);
|
||||
expect(page.classes.has('host-cutout-toolbar')).toBe(true);
|
||||
page.parseHeader(1131);
|
||||
expect([...page.classes]).toEqual(['host-cutout']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('camera housing: the option in App Settings', () => {
|
||||
it('knows nothing until the app says, and then what the app said', () => {
|
||||
const page = load();
|
||||
expect(page.api.wholeScreen()).toBeNull();
|
||||
expect(page.api.option({ available: true, enabled: true })).toBe(true);
|
||||
expect(page.api.wholeScreen()).toEqual({ available: true, enabled: true });
|
||||
page.api.option({ available: 'yes', enabled: 1 });
|
||||
expect(page.api.wholeScreen()).toEqual({ available: false, enabled: false });
|
||||
page.api.option(null);
|
||||
expect(page.api.wholeScreen()).toBeNull();
|
||||
});
|
||||
|
||||
it('has the settings page show it as soon as the app says', () => {
|
||||
const page = load();
|
||||
let synced = 0;
|
||||
(page.window.app as Record<string, unknown>).syncHostWholeScreenSetting = () => synced++;
|
||||
page.api.option({ available: true, enabled: false });
|
||||
expect(synced).toBe(1);
|
||||
});
|
||||
|
||||
it('turns it on and off in the app, and only with a plain true', () => {
|
||||
const page = load();
|
||||
expect(page.api.setWholeScreen(true)).toBe(true);
|
||||
expect(page.api.setWholeScreen('true')).toBe(true);
|
||||
expect(page.api.setWholeScreen(false)).toBe(true);
|
||||
expect(page.switched).toEqual([true, false, false]);
|
||||
});
|
||||
|
||||
it('says there is no app to tell in a browser tab', () => {
|
||||
const page = load({ host: false });
|
||||
expect(page.api.setWholeScreen(true)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('camera housing: wiring', () => {
|
||||
const html = read('index.html');
|
||||
const css = read('styles.css');
|
||||
@@ -276,20 +554,51 @@ describe('camera housing: wiring', () => {
|
||||
expect(read('host-cutout.js')).toContain('window.CodemanHost.cutoutReady(ready)');
|
||||
});
|
||||
|
||||
it('lays the toolbar out from the housing in every desktop layout', () => {
|
||||
const rule = /html\.host-cutout \.header > \.header-right \{([^}]*)\}/.exec(css)?.[1] ?? '';
|
||||
it('gives a toolbar that would reach the housing a box that covers it', () => {
|
||||
const rule = /html\.host-cutout-toolbar \.header > \.header-right \{([^}]*)\}/.exec(css)?.[1] ?? '';
|
||||
expect(rule).toContain('width: calc(100vw - 0.75rem - var(--host-cutout-left) + var(--host-cutout-gap));');
|
||||
expect(rule).toContain('padding-left: calc(var(--host-cutout-width) + 2 * var(--host-cutout-gap));');
|
||||
expect(rule).toContain('flex-wrap: wrap;');
|
||||
expect(rule).toContain('box-sizing: border-box;');
|
||||
// 0.75rem is the header's own side padding: the two must change together.
|
||||
expect(/\n\.header \{[^}]*padding: 0\.35rem 0\.75rem;/.test(css)).toBe(true);
|
||||
// And the gap is the module's GAP.
|
||||
expect(css).toMatch(/html\.host-cutout \{\s*--host-cutout-gap: 8px;/);
|
||||
expect(read('host-cutout.js')).toContain('const GAP = 8;');
|
||||
});
|
||||
|
||||
it('wins over a toolbar width the user chose, and hides the handle that sets it', () => {
|
||||
it('lets that box win over a toolbar width the user chose, and hides the handle that sets it', () => {
|
||||
expect(css).toMatch(
|
||||
/html\[data-header-right-width\]:not\(\.host-cutout\):not\(\[data-tab-orientation='vertical'\]\)/
|
||||
/html\[data-header-right-width\]:not\(\.host-cutout-toolbar\):not\(\[data-tab-orientation='vertical'\]\)/
|
||||
);
|
||||
expect(css).toMatch(/html\.host-cutout \.header-divider \{\s*display: none;/);
|
||||
expect(css).toMatch(/html\.host-cutout-toolbar \.header-divider \{\s*display: none;/);
|
||||
// A toolbar that ends right of the housing keeps the user's width and the handle.
|
||||
expect(css).not.toMatch(/html\.host-cutout \.header-divider/);
|
||||
expect(css).not.toMatch(/html\.host-cutout \.header > \.header-right/);
|
||||
});
|
||||
|
||||
it('has the tab strip place the tabs once its row mode is decided, and before one row is measured', () => {
|
||||
const app = read('app.js');
|
||||
const mode = /\n updateTabOverflowMode\(\) \{([\s\S]*?)\n \}/.exec(app)?.[1] ?? '';
|
||||
expect(mode.indexOf('this._syncTabStripCorner(container);')).toBeGreaterThan(-1);
|
||||
expect(mode.indexOf('window.CodemanHostCutout?.fitTabs?.(container);')).toBeGreaterThan(
|
||||
mode.indexOf('this._syncTabStripCorner(container);')
|
||||
);
|
||||
const decide = /\n _decideTabOverflow\(container\) \{([\s\S]*?)\n \}/.exec(app)?.[1] ?? '';
|
||||
const fit = decide.lastIndexOf('window.CodemanHostCutout?.fitTabs?.(container);');
|
||||
expect(fit).toBeGreaterThan(decide.lastIndexOf("container.classList.remove('tabs-auto-wrap');"));
|
||||
expect(fit).toBeLessThan(decide.indexOf('scrollWidth: container.scrollWidth'));
|
||||
});
|
||||
|
||||
it('has a switch in App Settings that only the Mac app shows, wired to the app and not to the settings blob', () => {
|
||||
const html = read('index.html');
|
||||
expect(html).toMatch(/<div class="set-group" id="appSettingsHostGroup" style="display: none">/);
|
||||
expect(html).toContain('<input type="checkbox" id="appSettingsHostWholeScreen">');
|
||||
const ui = read('settings-ui.js');
|
||||
expect(ui).toContain("group.style.display = option?.available ? '' : 'none';");
|
||||
expect(ui).toContain('window.CodemanHostCutout.setWholeScreen(hostBox.checked);');
|
||||
// Never a key of the settings object the page stores and sends to the server.
|
||||
expect(ui).not.toMatch(/wholeScreen\s*:/);
|
||||
expect(shim).toContain("setWholeScreen: function (on) { return post({ cmd: 'wholeScreen', on: on === true }); }");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user