mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-12-01 00:49: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();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user