Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions scripts/patch-linux-window-ui.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1110,13 +1110,13 @@ test("window controls safe-area descriptor matches current app shell chunks", ()
assert.ok(descriptor);
assert.equal(
descriptor.pattern.test(
"app-initial~app-main~appgen-settings-page~settings-page~skills-settings~plugins-settings~re~old.js",
"app-initial~app-main~new-thread-panel-page~appgen-library-page~hotkey-window-thread-page~ho~legacy.js",
),
false,
);
assert.equal(
descriptor.pattern.test(
"app-initial~app-main~new-thread-panel-page~appgen-library-page~hotkey-window-thread-page~ho~iufn7mg3-current.js",
"app-initial~avatarOverlayCompositionSurface~artifact-tab-content.electron~app-main~appgen-s~j5d6n91g-DVu-pwEX.js",
),
true,
);
Expand Down Expand Up @@ -1151,10 +1151,14 @@ test("optional webview descriptors follow the current upstream chunk split", ()
assert.ok(tooltipCollision);
assert.equal(
tooltipCollision.pattern.test(
"app-initial~app-main~hotkey-window-new-thread-page~hotkey-window-home-page~composer-utility-bar-D9zyQF1n.js",
"app-initial~avatarOverlayCompositionSurface~artifact-tab-content.electron~notebook-preview-~kr7rxhqe-BaAm4SxE.js",
),
true,
);
assert.equal(
tooltipCollision.pattern.test("composer-utility-bar-Cpb8DT_h.js"),
false,
);
assert.equal(
tooltipCollision.pattern.test(
"app-initial~app-main~onboarding-page~hotkey-window-thread-page~quick-chat-window-page~chatg~legacy.js",
Expand Down Expand Up @@ -2785,6 +2789,7 @@ test("adds a right-side safe area for Linux window controls in application menu
const source = [
"var l=Object.freeze({default:Object.freeze({left:0,right:0}),mac:Object.freeze({legacy:Object.freeze({left:66+c,right:0}),modern:Object.freeze({left:76+c,right:0})}),applicationMenu:Object.freeze({left:0,right:0})});",
"var m=Object.freeze({applicationMenu:Object.freeze({left:0,right:0})});",
"function sl({entries:e,fitWidth:t,side:n,slotWidth:r}){let i=e.some(({align:e})=>e===`end`),o=a({\"ps-[max(var(--spacing-token-safe-header-left),0.5rem)]\":n===`start`,\"pe-2\":n===`start`&&i||n===`end`}),s=vr(e=>{let{width:n}=sr(e);t.set(n)});return jsx(o)}",
].join("");

const patched = applyPatchTwice(applyLinuxWindowControlsSafeAreaPatch, source);
Expand All @@ -2797,12 +2802,18 @@ test("adds a right-side safe area for Linux window controls in application menu
patched,
/applicationMenu:Object\.freeze\(\{left:0,right:0\}\)/,
);
assert.match(
patched,
/"pe-2":n===`start`&&i,"pe-\(--spacing-token-safe-header-right\)":n===`end`/,
);
assert.doesNotMatch(patched, /"pe-2":n===`start`&&i\|\|n===`end`/);
});

test("patches remaining Linux window controls safe areas when another copy is already patched", () => {
const source = [
"var l=Object.freeze({applicationMenu:Object.freeze({left:0,right:138})});",
"var m=Object.freeze({applicationMenu:Object.freeze({left:0,right:0})});",
"function sl({entries:e,fitWidth:t,side:n,slotWidth:r}){let i=e.some(({align:e})=>e===`end`),o=a({\"ps-[max(var(--spacing-token-safe-header-left),0.5rem)]\":n===`start`,\"pe-2\":n===`start`&&i||n===`end`}),s=vr(e=>{let{width:n}=sr(e);t.set(n)});return jsx(o)}",
].join("");

const patched = applyPatchTwice(applyLinuxWindowControlsSafeAreaPatch, source);
Expand All @@ -2815,6 +2826,23 @@ test("patches remaining Linux window controls safe areas when another copy is al
patched,
/applicationMenu:Object\.freeze\(\{left:0,right:0\}\)/,
);
assert.match(
patched,
/"pe-2":n===`start`&&i,"pe-\(--spacing-token-safe-header-right\)":n===`end`/,
);
});

test("patches remaining Linux header safe-area padding when the menu inset is already patched", () => {
const source =
"var l=Object.freeze({applicationMenu:Object.freeze({left:0,right:138})});function sl({entries:e,fitWidth:t,side:n,slotWidth:r}){let i=e.some(({align:e})=>e===`end`),o=a({\"ps-[max(var(--spacing-token-safe-header-left),0.5rem)]\":n===`start`,\"pe-2\":n===`start`&&i||n===`end`}),s=vr(e=>{let{width:n}=sr(e);t.set(n)});return jsx(o)}";

const patched = applyPatchTwice(applyLinuxWindowControlsSafeAreaPatch, source);

assert.match(
patched,
/"pe-2":n===`start`&&i,"pe-\(--spacing-token-safe-header-right\)":n===`end`/,
);
assert.doesNotMatch(patched, /"pe-2":n===`start`&&i\|\|n===`end`/);
});

test("keeps tooltips out of the Linux window controls titlebar area", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module.exports = [
phase: "webview-asset",
order: 1040,
ciPolicy: "optional",
pattern: /^app-initial~app-main~new-thread-panel-page~appgen-library-page~hotkey-window-thread-page~ho~.*\.js$/,
pattern: /^app-initial~avatarOverlayCompositionSurface~artifact-tab-content\.electron~app-main~appgen-s~[^.]+\.js$/,
missingDescription: "window controls safe-area bundle",
skipDescription: "Linux window controls safe-area patch",
apply: applyLinuxWindowControlsSafeAreaPatch,
Expand All @@ -57,7 +57,7 @@ module.exports = [
phase: "webview-asset",
order: 1050,
ciPolicy: "optional",
pattern: /^app-initial~app-main~hotkey-window-new-thread-page~hotkey-window-home-page~composer-utility-bar-[^.]+\.js$/,
pattern: /^app-initial~avatarOverlayCompositionSurface~artifact-tab-content\.electron~notebook-preview-~kr7rxhqe-[^.]+\.js$/,
missingDescription: "tooltip bundle",
skipDescription: "Linux tooltip titlebar collision patch",
apply: applyLinuxTooltipWindowControlsCollisionPatch,
Expand Down
28 changes: 23 additions & 5 deletions scripts/patches/impl/webview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,33 @@ function applyLinuxOpaqueWindowsDefaultPatch(currentSource) {
function applyLinuxWindowControlsSafeAreaPatch(currentSource) {
const currentInset = `applicationMenu:Object.freeze({left:0,right:${LINUX_WINDOW_CONTROLS_SAFE_AREA_RIGHT}})`;
const defaultInset = "applicationMenu:Object.freeze({left:0,right:0})";
if (currentSource.includes(defaultInset)) {
return currentSource.split(defaultInset).join(currentInset);
const currentHeaderSlotPadding =
'"pe-2":n===`start`&&i,"pe-(--spacing-token-safe-header-right)":n===`end`';
const defaultHeaderSlotPadding = '"pe-2":n===`start`&&i||n===`end`';

let patchedSource = currentSource;
if (patchedSource.includes(defaultInset)) {
patchedSource = patchedSource.split(defaultInset).join(currentInset);
}

if (currentSource.includes(currentInset)) {
return currentSource;
if (patchedSource.includes(defaultHeaderSlotPadding)) {
patchedSource = patchedSource.split(defaultHeaderSlotPadding).join(currentHeaderSlotPadding);
}

if (
patchedSource !== currentSource ||
(
patchedSource.includes(currentInset) &&
patchedSource.includes(currentHeaderSlotPadding)
)
) {
return patchedSource;
}

if (currentSource.includes("applicationMenu:Object.freeze({left:0,right:")) {
if (
currentSource.includes("applicationMenu:Object.freeze({left:0,right:") ||
currentSource.includes("spacing-token-safe-header-right")
) {
console.warn(
"WARN: Could not find Linux window controls safe-area insertion point — skipping safe-area patch",
);
Expand Down