Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(desktop): restore native window maximize and tiling behavior
vastsafceabebecb2a
diff --git a/apps/desktop/electron/main/bootstrap/window.ts b/apps/desktop/electron/main/bootstrap/window.tsindex d42073a19..ed49f3b71 100644--- a/apps/desktop/electron/main/bootstrap/window.ts+++ b/apps/desktop/electron/main/bootstrap/window.ts@@ -40,6 +40,11 @@ import { readWindowState, writeWindowState } from "../window-preferences";import { suppressLinuxFramelessSystemMenu } from "../frameless-system-menu";import { isWindowFullScreen } from "../window-fullscreen";import { installWindowsNativeSnap } from "../window-native-snap";+import {+ installMaximizedWindowGuard,+ installTransparentWindowsMaximize,+ nativeWindowMinimumSize,+} from "../window-native-behavior";import { DEFAULT_WINDOW_CORNER_RADIUS, installWindowShape } from "../window-shape";import {installWindows11CornerController,@@ -195,9 +200,10 @@ export async function createWindow({? clampBoundsToWorkArea(savedState, restoreWorkArea): null;const { width: initialMinWidth, height: initialMinHeight } =- clampMinimumSizeToWorkArea(+ nativeWindowMinimumSize({ width: windowMinWidth, height: windowMinHeight },restoreWorkArea,+ process.platform,);const initialWindowBackground = builtinWindowBackground(nativeTheme.shouldUseDarkColors ? "dark" : "light",@@ -277,7 +283,18 @@ export async function createWindow({},});const window = windowState.mainWindow;+ installMaximizedWindowGuard(window, process.platform);+ const setNativeMinimumSize = (width: number, height: number) => {+ if (window.isMaximized() || isWindowFullScreen(window)) return;+ const minimum = nativeWindowMinimumSize(+ { width, height },+ screen.getDisplayMatching(window.getBounds()).workArea,+ process.platform,+ );+ window.setMinimumSize(minimum.width, minimum.height);+ };if (process.platform === "win32") {+ if (!windows11NativeCorners) installTransparentWindowsMaximize(window);await installWindowsNativeSnap(window, () => windowState.host, logger);if (windows11NativeCorners) {await installWindows11CornerController(@@ -403,7 +420,7 @@ export async function createWindow({display.workArea.width,windowMinWidth + panelWidth,);- window.setMinimumSize(+ setNativeMinimumSize(minimumWidth,Math.min(windowMinHeight, display.workArea.height),);@@ -449,7 +466,7 @@ export async function createWindow({// Never demand more width than the current work area offers, or a narrow// display could no longer shrink the window back on-screen (issue #544).const resizeWorkArea = screen.getDisplayMatching(currentBounds).workArea;- window.setMinimumSize(+ setNativeMinimumSize(Math.min(baseBounds.width + WORK_PANEL_MIN_WIDTH, resizeWorkArea.width),Math.min(windowMinHeight, resizeWorkArea.height),);@@ -491,12 +508,12 @@ export async function createWindow({);const minimumHeight = Math.min(windowMinHeight, display.workArea.height);if (next.bounds.width < currentBounds.width) {- window.setMinimumSize(minimumWidth, minimumHeight);+ setNativeMinimumSize(minimumWidth, minimumHeight);}windowState.expectedWorkPanelBounds = next.bounds;window.setBounds(next.bounds, false);if (next.bounds.width >= currentBounds.width) {- window.setMinimumSize(minimumWidth, minimumHeight);+ setNativeMinimumSize(minimumWidth, minimumHeight);}const appliedBounds = window.getBounds();windowState.expectedWorkPanelBounds = appliedBounds;@@ -692,7 +709,7 @@ export async function createWindow({{ width: windowMinWidth, height: windowMinHeight },workArea,);- window.setMinimumSize(minimum.width, minimum.height);+ setNativeMinimumSize(minimum.width, minimum.height);const fitted = clampBoundsToWorkArea(currentBounds, workArea);if (windowBoundsEqual(fitted, currentBounds)) return;windowState.expectedWorkPanelBounds = fitted;@@ -703,14 +720,14 @@ export async function createWindow({};// Custom window controls (Windows/Linux) need maximize state to swap the// maximize/restore glyph.+ window.on("maximize", sendMaximized);if (process.platform !== "darwin") {- window.on("maximize", sendMaximized);// Native-runner E2E fixture: establish the initial native state before// the renderer mounts, then let WindowControls query it through IPC.if (process.env.PI_DESKTOP_START_MAXIMIZED === "1") window.maximize();}window.on("unmaximize", () => {- if (process.platform !== "darwin") sendMaximized();+ sendMaximized();refitWindowToWorkArea();scheduleWorkPanelReservation();});@@ -720,6 +737,9 @@ export async function createWindow({const display = screen.getDisplayMatching(window.getBounds());const nextDisplayKey = displayWorkAreaKey(display.id, display.workArea);if (nextDisplayKey === windowState.workPanelDisplayKey) return;+ // Refresh the snap constraint after a cross-display move without enlarging+ // a window the user already placed in a narrower native tile.+ setNativeMinimumSize(Math.min(windowMinWidth, window.getBounds().width), windowMinHeight);scheduleWorkPanelReservation();};@@ -784,7 +804,7 @@ export async function createWindow({{ width: workPanelMinimumWindowWidth(), height: windowMinHeight },screen.getDisplayMatching(window.getBounds()).workArea,);- window.setMinimumSize(minimum.width, minimum.height);+ setNativeMinimumSize(minimum.width, minimum.height);}reconcileWorkPanelDisplay();};@@ -915,7 +935,7 @@ export async function createWindow({{ width: windowMinWidth, height: windowMinHeight },screen.getDisplayMatching(electronBounds).workArea,);- window.setMinimumSize(minimum.width, minimum.height);+ setNativeMinimumSize(minimum.width, minimum.height);// Prefer normal layer so CG helpers and Stage Manager stay stable.window.setAlwaysOnTop(false);window.show();@@ -1653,7 +1673,7 @@ export async function createWindow({await new Promise((r) => setTimeout(r, 250));captureViewportOverride = true;try {- windowState.mainWindow!.setMinimumSize(windowMinWidth, windowMinHeight);+ setNativeMinimumSize(windowMinWidth, windowMinHeight);windowState.mainWindow!.setSize(windowMinWidth, windowMinHeight, false);await new Promise((r) => setTimeout(r, 350));await probeWorkPanelHeader("minimum-supported");@@ -1664,7 +1684,7 @@ export async function createWindow({{ width: workPanelMinimumWindowWidth(), height: windowMinHeight },screen.getDisplayMatching(windowState.mainWindow!.getBounds()).workArea,);- windowState.mainWindow!.setMinimumSize(+ setNativeMinimumSize(restoredMinimum.width,restoredMinimum.height,);@@ -1886,7 +1906,7 @@ export async function createWindow({{ width: workPanelMinimumWindowWidth(), height: windowMinHeight },screen.getDisplayMatching(windowState.mainWindow!.getBounds()).workArea,);- windowState.mainWindow!.setMinimumSize(+ setNativeMinimumSize(restoredMinimum.width,restoredMinimum.height,);diff --git a/apps/desktop/electron/main/window-native-behavior.ts b/apps/desktop/electron/main/window-native-behavior.tsnew file mode 100644index 000000000..a4cbbb1ae--- /dev/null+++ b/apps/desktop/electron/main/window-native-behavior.ts@@ -0,0 +1,80 @@+import type { BrowserWindow } from "electron";+import { isWindowFullScreen } from "./window-fullscreen.ts";++/** Keep the OS minimum small enough for a side-by-side tile in DIP. */+export function nativeWindowMinimumSize(+ requested: { width: number; height: number },+ workArea: { width: number; height: number },+ platform: NodeJS.Platform,+): { width: number; height: number } {+ // Sequoia places a gutter around native tiles, unlike Windows/X11 halves.+ const tileWidth = Math.floor(workArea.width / 2) - (platform === "darwin" ? 16 : 0);+ return {+ width: Math.max(1, Math.floor(Math.min(requested.width, tileWidth))),+ height: Math.max(1, Math.floor(Math.min(requested.height, workArea.height))),+ };+}++/** Protect a maximized window without disabling native zoom/fullscreen controls. */+export function installMaximizedWindowGuard(+ window: BrowserWindow,+ platform: NodeJS.Platform,+): () => void {+ // Linux does not expose cancellable will-move/will-resize events. Its window+ // manager owns the maximized hit regions and drag-to-restore behavior.+ if (platform !== "darwin" && platform !== "win32") return () => {};+ // macOS reports isMaximized() during the zoom animation, before its saved+ // normal frame is stable. Only protect the settled maximize event, or the+ // animation itself can be cancelled and the normal frame corrupted.+ let settledMaximized = window.isMaximized();+ const maximize = () => { settledMaximized = true; };+ const unmaximize = () => { settledMaximized = false; };+ const resize = () => {+ if (!window.isDestroyed() && !window.isMaximized()) settledMaximized = false;+ };+ const preventMaximizedDrag = (event: { preventDefault(): void }) => {+ if (settledMaximized && !window.isDestroyed()) event.preventDefault();+ };+ const dispose = () => {+ window.removeListener("maximize", maximize);+ window.removeListener("unmaximize", unmaximize);+ window.removeListener("resize", resize);+ window.removeListener("will-resize", preventMaximizedDrag);+ window.removeListener("closed", dispose);+ };+ window.on("maximize", maximize);+ window.on("unmaximize", unmaximize);+ window.on("resize", resize);+ window.on("will-resize", preventMaximizedDrag);+ window.once("closed", dispose);+ return dispose;+}+++/** Electron suppresses SC_MAXIMIZE for transparent HWNDs, including caption double-click. */+export function installTransparentWindowsMaximize(window: BrowserWindow): () => void {+ const WM_SYSCOMMAND = 0x0112;+ const SC_MAXIMIZE = 0xf030;+ let pending: NodeJS.Immediate | null = null;+ let disposed = false;+ window.hookWindowMessage(WM_SYSCOMMAND, (wParam) => {+ if (wParam.length < 4 || (wParam.readUInt32LE(0) & 0xfff0) !== SC_MAXIMIZE || pending || disposed) return;+ // Let Electron consume the unsupported native command first. Its public+ // maximize API still works for this surface and does not resend SC_MAXIMIZE.+ pending = setImmediate(() => {+ pending = null;+ if (!disposed && !window.isDestroyed() && !window.isMaximized() && !isWindowFullScreen(window)) {+ window.maximize();+ }+ });+ });+ const dispose = () => {+ disposed = true;+ if (pending) clearImmediate(pending);+ pending = null;+ window.removeListener("closed", dispose);+ if (!window.isDestroyed()) window.unhookWindowMessage(WM_SYSCOMMAND);+ };+ window.once("closed", dispose);+ return dispose;+}diff --git a/apps/desktop/src/features/app/AppShell.tsx b/apps/desktop/src/features/app/AppShell.tsxindex 87deac2c8..4767aea0e 100644--- a/apps/desktop/src/features/app/AppShell.tsx+++ b/apps/desktop/src/features/app/AppShell.tsx@@ -25,6 +25,7 @@ import { cx, TooltipButton } from "../../components/ui";import { WindowControls } from "../../components/WindowControls";import { useCopyTex } from "../../hooks/use-copy-tex";import { api } from "../../lib/api";+import { installMaximizedWindowChrome } from "../../lib/maximized-window-chrome";import { PortalVisibilityProvider } from "../../lib/portal-visibility";import { workPanelLayout } from "../../lib/work-panel-resize";import { LiveVoiceStatusHost } from "../voice/live/LiveVoiceStatusHost";@@ -103,6 +104,9 @@ export function AppShell() {} = useAppShellRuntime();const [toastAnchor, setToastAnchor] = useState<HTMLElement | null>(null);useCopyTex();+ useEffect(() => installMaximizedWindowChrome(+ window.piDesktop?.platform ?? "darwin", document, window, api,+ ), []);useEffect(() => {void loadChatSurface().catch((error: unknown) => {diff --git a/apps/desktop/src/lib/maximized-window-chrome.ts b/apps/desktop/src/lib/maximized-window-chrome.tsnew file mode 100644index 000000000..c27f7da53--- /dev/null+++ b/apps/desktop/src/lib/maximized-window-chrome.ts@@ -0,0 +1,54 @@+type WindowChromeApi = {+ windowControl(action: "getState" | "toggleMaximize"): Promise<{ maximized: boolean }>;+ onWindowMaximized(listener: (state: { maximized: boolean }) => void): () => void;+};++/** Disable macOS caption dragging without disabling native zoom or green controls. */+export function installMaximizedWindowChrome(+ platform: string,+ document: Document,+ view: Pick<Window, "getComputedStyle">,+ api: WindowChromeApi,+): () => void {+ if (platform !== "darwin") return () => {};+ let disposed = false;+ let revision = 0;+ let maximized = false;+ let pending = false;+ const root = document.documentElement;+ const previous = root.dataset.windowMaximized;+ const apply = (state: { maximized: boolean }) => {+ maximized = state.maximized;+ root.dataset.windowMaximized = String(maximized);+ };+ const unsubscribe = api.onWindowMaximized((state) => {+ revision += 1;+ if (!disposed) apply(state);+ });+ void api.windowControl("getState").then((state) => {+ if (!disposed && revision === 0) apply(state);+ }).catch((error: unknown) => console.error("window chrome state query failed", error));++ const doubleClick = (event: MouseEvent) => {+ if (!maximized || pending || event.defaultPrevented || event.button !== 0) return;+ if (!(event.target instanceof Element)) return;+ // The marker inherits through caption text but explicit no-drag controls+ // reset it, matching the native draggable-region exclusions.+ if (view.getComputedStyle(event.target).getPropertyValue("--window-drag-region").trim() !== "drag") return;+ event.preventDefault();+ pending = true;+ const expectedRevision = revision;+ void api.windowControl("toggleMaximize").then((state) => {+ if (!disposed && revision === expectedRevision) apply(state);+ }).catch((error: unknown) => console.error("window chrome restore failed", error))+ .finally(() => { pending = false; });+ };+ document.addEventListener("dblclick", doubleClick);+ return () => {+ disposed = true;+ unsubscribe();+ document.removeEventListener("dblclick", doubleClick);+ if (previous === undefined) delete root.dataset.windowMaximized;+ else root.dataset.windowMaximized = previous;+ };+}diff --git a/apps/desktop/src/styles/chat-shell.css b/apps/desktop/src/styles/chat-shell.cssindex cc88a8791..b0828d91b 100644--- a/apps/desktop/src/styles/chat-shell.css+++ b/apps/desktop/src/styles/chat-shell.css@@ -29,10 +29,12 @@}.drag {+ --window-drag-region: drag;-webkit-app-region: drag;}.no-drag {+ --window-drag-region: no-drag;-webkit-app-region: no-drag;}@@ -439,6 +441,7 @@cursor: col-resize;touch-action: none;user-select: none;+ --window-drag-region: no-drag;-webkit-app-region: no-drag;app-region: no-drag;}@@ -538,6 +541,7 @@calc(4px - var(--minimap-marker-count) * 0.05px),2px);+ --window-drag-region: no-drag;-webkit-app-region: no-drag;app-region: no-drag;}diff --git a/apps/desktop/src/styles/chrome.css b/apps/desktop/src/styles/chrome.cssindex 8e4ebae42..522dc8a4f 100644--- a/apps/desktop/src/styles/chrome.css+++ b/apps/desktop/src/styles/chrome.css@@ -27,6 +27,7 @@justify-content: center;padding: 24px;background: var(--ds-bg-primary);+ --window-drag-region: drag;-webkit-app-region: drag;animation: startup-splash-in var(--motion-duration-slow) var(--motion-ease-out) both;}@@ -59,6 +60,7 @@align-items: center;gap: 18px;width: min(100%, 280px);+ --window-drag-region: no-drag;-webkit-app-region: no-drag;}@@ -190,6 +192,7 @@background: #000;opacity: 1;/* The window has no chrome yet, so the surface itself has to be draggable. */+ --window-drag-region: drag;-webkit-app-region: drag;transition: opacity var(--motion-startup-reveal) var(--motion-ease-out);}@@ -298,6 +301,7 @@justify-content: center;padding: 24px;background: var(--ds-bg-primary);+ --window-drag-region: drag;-webkit-app-region: drag;animation: startup-splash-in var(--motion-duration-slow) var(--motion-ease-out) both;}@@ -319,6 +323,7 @@gap: 14px;width: min(100%, 420px);text-align: center;+ --window-drag-region: no-drag;-webkit-app-region: no-drag;}@@ -590,6 +595,7 @@/* Keep the shell continuous; titlebar hierarchy comes from spacing and* surface color instead of a hard lower rule. */border-bottom: 0;+ --window-drag-region: drag;-webkit-app-region: drag;}@@ -624,6 +630,7 @@* governs expansion; the .ct-collapsed rule below matches sidebar-out.*/transition: padding-left var(--motion-duration-normal) var(--motion-ease-out);+ --window-drag-region: drag;-webkit-app-region: drag;app-region: drag;}@@ -637,6 +644,7 @@.conversation-topbar .ct-left,.conversation-topbar .ct-right {+ --window-drag-region: no-drag;-webkit-app-region: no-drag;app-region: no-drag;display: flex;@@ -669,6 +677,7 @@min-width: 0;overflow: hidden;white-space: nowrap;+ --window-drag-region: drag;-webkit-app-region: drag; /* keep the title area draggable */app-region: drag;}@@ -744,6 +753,7 @@text-overflow: ellipsis;white-space: nowrap;cursor: text;+ --window-drag-region: no-drag;-webkit-app-region: no-drag;app-region: no-drag;}@@ -778,6 +788,7 @@font-weight: var(--font-weight-medium);letter-spacing: var(--tracking-tight);line-height: var(--leading-compact);+ --window-drag-region: no-drag;-webkit-app-region: no-drag;app-region: no-drag;}@@ -801,6 +812,7 @@background: transparent;color: var(--ds-text-secondary);cursor: pointer;+ --window-drag-region: no-drag;-webkit-app-region: no-drag;app-region: no-drag;transition: background var(--motion-duration-fast) var(--motion-ease-out),@@ -895,6 +907,7 @@right: var(--ds-work-panel-toggle-inset);z-index: 30;pointer-events: auto;+ --window-drag-region: no-drag;-webkit-app-region: no-drag;app-region: no-drag;}@@ -989,6 +1002,7 @@* own carve-out the button falls inside the top bar's drag region, which on* macOS swallows the click and keeps the arrow cursor instead of the pointer.*/+ --window-drag-region: no-drag;-webkit-app-region: no-drag;app-region: no-drag;opacity: 0;@@ -1294,6 +1308,7 @@}.window-controls {+ --window-drag-region: no-drag;-webkit-app-region: no-drag;app-region: no-drag;pointer-events: auto;@@ -1335,6 +1350,7 @@}.window-control-btn {+ --window-drag-region: no-drag;-webkit-app-region: no-drag;app-region: no-drag;pointer-events: auto;@@ -1382,6 +1398,7 @@justify-content: space-between;gap: 4px;padding: 0 8px;+ --window-drag-region: drag;-webkit-app-region: drag;}@@ -1472,6 +1489,7 @@.window-chrome-row button {pointer-events: auto;+ --window-drag-region: no-drag;-webkit-app-region: no-drag;app-region: no-drag;}@@ -1480,3 +1498,11 @@flex: 1 1 auto;align-self: stretch;}+++/* A zoomed macOS window stays fixed; double-click restore is renderer-owned+ * only while these native drag regions are disabled. Normal windows stay OS-owned. */+:root[data-platform="darwin"][data-window-maximized="true"] * {+ -webkit-app-region: no-drag !important;+ app-region: no-drag !important;+}diff --git a/apps/desktop/src/styles/composer-image-preview.css b/apps/desktop/src/styles/composer-image-preview.cssindex 211e1539f..6e4b61e22 100644--- a/apps/desktop/src/styles/composer-image-preview.css+++ b/apps/desktop/src/styles/composer-image-preview.css@@ -12,6 +12,7 @@background: transparent;color: var(--gray-0);overflow: hidden;+ --window-drag-region: no-drag;-webkit-app-region: no-drag;}diff --git a/apps/desktop/src/styles/generated-images.css b/apps/desktop/src/styles/generated-images.cssindex d83a8765e..76f27faeb 100644--- a/apps/desktop/src/styles/generated-images.css+++ b/apps/desktop/src/styles/generated-images.css@@ -106,6 +106,7 @@overflow: hidden;background: var(--ds-bg-primary);color: var(--ds-text-primary);+ --window-drag-region: no-drag;-webkit-app-region: no-drag;}.generated-image-viewer[open] { display: flex; flex-direction: column; }diff --git a/apps/desktop/src/styles/live-voice-widget.css b/apps/desktop/src/styles/live-voice-widget.cssindex c16fb85bc..03ae1af7b 100644--- a/apps/desktop/src/styles/live-voice-widget.css+++ b/apps/desktop/src/styles/live-voice-widget.css@@ -34,6 +34,7 @@ html[data-surface="live-voice-widget"] #root {.live-voice-widget {display: inline-flex;padding: 6px;+ --window-drag-region: drag;-webkit-app-region: drag;app-region: drag;cursor: grab;@@ -50,6 +51,7 @@ html[data-surface="live-voice-widget"] #root {.live-voice-widget .live-voice-call-bar button,.live-voice-widget .live-voice-call-bar code {+ --window-drag-region: no-drag;-webkit-app-region: no-drag;app-region: no-drag;}diff --git a/apps/desktop/src/styles/overlays.css b/apps/desktop/src/styles/overlays.cssindex 7855deca5..0118bde93 100644--- a/apps/desktop/src/styles/overlays.css+++ b/apps/desktop/src/styles/overlays.css@@ -203,6 +203,7 @@actions from competing for the same screen space.*/.update-notice {+ --window-drag-region: no-drag;-webkit-app-region: no-drag;pointer-events: auto;position: absolute;@@ -512,6 +513,7 @@}.toast {+ --window-drag-region: no-drag;-webkit-app-region: no-drag;pointer-events: auto;display: flex;diff --git a/apps/desktop/src/styles/plugin-launcher.css b/apps/desktop/src/styles/plugin-launcher.cssindex 4c1156ae8..b0d758b17 100644--- a/apps/desktop/src/styles/plugin-launcher.css+++ b/apps/desktop/src/styles/plugin-launcher.css@@ -11,6 +11,7 @@ html[data-surface="plugin-launcher"] #root {display: flex;align-items: stretch;color: var(--ds-text-primary);+ --window-drag-region: no-drag;-webkit-app-region: no-drag;app-region: no-drag;}diff --git a/apps/desktop/src/styles/plugins.css b/apps/desktop/src/styles/plugins.cssindex 2d0b64a4a..4caefdbeb 100644--- a/apps/desktop/src/styles/plugins.css+++ b/apps/desktop/src/styles/plugins.css@@ -77,6 +77,7 @@flex: 0 0 auto;/* The page sits under the absolute titlebar band, which is a native dragrectangle: without this the window moves instead of the button reacting. */+ --window-drag-region: no-drag;-webkit-app-region: no-drag;app-region: no-drag;}@@ -1384,6 +1385,7 @@align-items: center;gap: 12px;padding: 16px 16px 10px;+ --window-drag-region: no-drag;-webkit-app-region: no-drag;app-region: no-drag;}@@ -1629,6 +1631,7 @@padding: 16px 16px 10px;/* The head reaches the window's top edge, where the titlebar drag rectanglelives; its close button must take the click instead of moving the window. */+ --window-drag-region: no-drag;-webkit-app-region: no-drag;app-region: no-drag;}diff --git a/apps/desktop/src/styles/settings.css b/apps/desktop/src/styles/settings.cssindex 8533237ac..fb54081c4 100644--- a/apps/desktop/src/styles/settings.css+++ b/apps/desktop/src/styles/settings.css@@ -123,6 +123,7 @@background: var(--ds-bg-primary);/* Let the settings content and titlebar read as one surface. */border-bottom: 0;+ --window-drag-region: drag;-webkit-app-region: drag;}diff --git a/apps/desktop/src/styles/work-panel.css b/apps/desktop/src/styles/work-panel.cssindex bc271b1b8..c9c75a098 100644--- a/apps/desktop/src/styles/work-panel.css+++ b/apps/desktop/src/styles/work-panel.css@@ -150,6 +150,7 @@var(--ds-work-panel-control-gap))0 12px;+ --window-drag-region: drag;-webkit-app-region: drag;}diff --git a/apps/desktop/test/maximized-window-chrome.test.mjs b/apps/desktop/test/maximized-window-chrome.test.mjsnew file mode 100644index 000000000..0b6d416fa--- /dev/null+++ b/apps/desktop/test/maximized-window-chrome.test.mjs@@ -0,0 +1,97 @@+import assert from "node:assert/strict";+import test from "node:test";+import { installMaximizedWindowChrome } from "../src/lib/maximized-window-chrome.ts";++class Caption { constructor(region = "drag") { this.region = region; } }+globalThis.Element = Caption;+const settle = () => new Promise(setImmediate);+function deferred() { let resolve; const promise = new Promise((r) => { resolve = r; }); return { promise, resolve }; }+function fixture({ platform = "darwin", initial = Promise.resolve({ maximized: true }) } = {}) {+ const listeners = new Map();+ const document = {+ documentElement: { dataset: {} },+ addEventListener: (name, listener) => listeners.set(name, listener),+ removeEventListener: (name) => listeners.delete(name),+ };+ const calls = [];+ const restore = deferred();+ let subscriber;+ const api = {+ windowControl(action) { calls.push(action); return action === "getState" ? initial : restore.promise; },+ onWindowMaximized(listener) { subscriber = listener; return () => { subscriber = null; }; },+ };+ const dispose = installMaximizedWindowChrome(platform, document, {+ getComputedStyle: (target) => ({ getPropertyValue: () => target.region }),+ }, api);+ return {+ document, calls, restore, dispose,+ update: (maximized) => subscriber?.({ maximized }),+ click(region = "drag", overrides = {}) {+ const event = { target: new Caption(region), button: 0, defaultPrevented: false,+ preventDefault() { this.defaultPrevented = true; }, ...overrides };+ listeners.get("dblclick")?.(event);+ return event;+ },+ };+}++test("maximized caption double-click restores once; controls and normal windows remain native", async () => {+ const f = fixture();+ await settle();+ assert.equal(f.document.documentElement.dataset.windowMaximized, "true");+ assert.equal(f.click("no-drag").defaultPrevented, false);+ assert.equal(f.click("drag", { button: 2 }).defaultPrevented, false);+ assert.equal(f.click().defaultPrevented, true);+ f.click();+ assert.deepEqual(f.calls, ["getState", "toggleMaximize"]);+ f.restore.resolve({ maximized: false });+ await settle();+ assert.equal(f.document.documentElement.dataset.windowMaximized, "false");+ assert.equal(f.click().defaultPrevented, false);+ f.dispose();+ assert.equal(f.document.documentElement.dataset.windowMaximized, undefined);+});++test("a late initial query cannot overwrite a newer native maximize event", async () => {+ const initial = deferred();+ const f = fixture({ initial: initial.promise });+ f.update(true);+ initial.resolve({ maximized: false });+ await settle();+ assert.equal(f.document.documentElement.dataset.windowMaximized, "true");+ f.dispose();+});++test("a newer native event wins over a stale restore response", async () => {+ const f = fixture();+ await settle();+ f.click();+ f.update(false);+ f.update(true);+ f.restore.resolve({ maximized: false });+ await settle();+ assert.equal(f.document.documentElement.dataset.windowMaximized, "true");+ f.dispose();+});++test("unmount ignores outstanding queries and removes double-click handling", async () => {+ const initial = deferred();+ const f = fixture({ initial: initial.promise });+ f.dispose();+ initial.resolve({ maximized: true });+ await settle();+ assert.equal(f.document.documentElement.dataset.windowMaximized, undefined);+ f.click();+ assert.deepEqual(f.calls, ["getState"]);+});++for (const platform of ["win32", "linux"]) {+ test(`${platform}: native caption behavior is untouched`, async () => {+ const f = fixture({ platform });+ await settle();+ f.click();+ assert.deepEqual(f.calls, []);+ assert.equal(f.document.documentElement.dataset.windowMaximized, undefined);+ f.dispose();+ });+}diff --git a/apps/desktop/test/window-menu.test.mjs b/apps/desktop/test/window-menu.test.mjsindex 5ac37c06a..146aa7e87 100644--- a/apps/desktop/test/window-menu.test.mjs+++ b/apps/desktop/test/window-menu.test.mjs@@ -257,7 +257,7 @@ test("Windows and Linux use menu-free frameless chrome with window controls", ()assert.match(mainSource, /window\.on\("maximize", sendMaximized\)/);assert.match(mainSource,- /window\.on\("unmaximize", \(\) => \{[\s\S]*process\.platform !== "darwin"[\s\S]*scheduleWorkPanelReservation\(\)/,+ /window\.on\("unmaximize", \(\) => \{\s*sendMaximized\(\);[\s\S]*scheduleWorkPanelReservation\(\)/,);assert.match(mainSource,diff --git a/apps/desktop/test/window-native-behavior.test.mjs b/apps/desktop/test/window-native-behavior.test.mjsnew file mode 100644index 000000000..7b119f647--- /dev/null+++ b/apps/desktop/test/window-native-behavior.test.mjs@@ -0,0 +1,131 @@+import assert from "node:assert/strict";+import { EventEmitter } from "node:events";+import test from "node:test";+import { installMaximizedWindowGuard, installTransparentWindowsMaximize, nativeWindowMinimumSize } from "../electron/main/window-native-behavior.ts";++for (const platform of ["darwin", "win32", "linux"]) {+ test(`${platform}: a normal window fits a small display's native half tile`, () => {+ const minimum = nativeWindowMinimumSize({ width: 800, height: 560 }, { width: 1440, height: 900 }, platform);+ assert.ok(minimum.width <= 720 - (platform === "darwin" ? 16 : 0));+ assert.equal(minimum.height, 560);+ assert.deepEqual(nativeWindowMinimumSize({ width: 800, height: 560 }, { width: 1920, height: 1080 }, platform), { width: 800, height: 560 });+ assert.deepEqual(nativeWindowMinimumSize({ width: 800, height: 560 }, { width: 0, height: 0 }, platform), { width: 1, height: 1 });+ });+}++function fixture(platform, initiallyMaximized = false) {+ const window = new EventEmitter();+ let maximized = initiallyMaximized;+ let movable = true;+ window.isMaximized = () => maximized;+ window.isDestroyed = () => false;+ window.isMovable = () => movable;+ window.setMovable = (value) => { movable = value; };+ const dispose = installMaximizedWindowGuard(window, platform);+ const transition = (value) => { maximized = value; window.emit(value ? "maximize" : "unmaximize"); };+ const drag = (event) => {+ let prevented = false;+ window.emit(event, { preventDefault() { prevented = true; } });+ return prevented;+ };+ return { window, transition, drag, dispose, setNativeMaximized: (value) => { maximized = value; } };+}++for (const platform of ["darwin", "win32"]) {+ test(`${platform}: maximize protects edges; restore re-enables native gestures`, () => {+ const f = fixture(platform);+ assert.equal(f.drag("will-resize"), false);+ f.transition(true);+ assert.equal(f.drag("will-resize"), true);+ assert.equal(f.drag("will-move"), false, "native drag-to-restore remains OS-owned");+ f.transition(false);+ assert.equal(f.drag("will-resize"), false);+ assert.equal(f.drag("will-move"), false);+ assert.equal(f.window.isMovable(), true);+ f.window.emit("closed");+ for (const event of ["will-resize", "will-move", "maximize", "unmaximize"]) assert.equal(f.window.listenerCount(event), 0);+ });+}++test("macOS: an already maximized window protects edges without disabling native zoom", () => {+ const f = fixture("darwin", true);+ assert.equal(f.window.isMovable(), true);+ assert.equal(f.drag("will-resize"), true);+ f.dispose();+ assert.equal(f.window.isMovable(), true);+ assert.equal(f.drag("will-resize"), false);+});++test("Linux retains compositor-owned maximize and movement", () => {+ const f = fixture("linux", true);+ assert.equal(f.window.isMovable(), true);+ assert.equal(f.drag("will-move"), false);+ assert.equal(f.drag("will-resize"), false);+ f.dispose();+});+++function transparentFixture() {+ const window = new EventEmitter();+ let destroyed = false;+ let maximized = false;+ let fullscreen = false;+ const hooks = new Map();+ let count = 0;+ window.isDestroyed = () => destroyed;+ window.isMaximized = () => maximized;+ window.isFullScreen = () => fullscreen;+ window.maximize = () => { count += 1; maximized = true; };+ window.hookWindowMessage = (message, callback) => hooks.set(message, callback);+ window.unhookWindowMessage = (message) => hooks.delete(message);+ const dispose = installTransparentWindowsMaximize(window);+ return { window, dispose, hooks, get count() { return count; },+ setFullscreen: (value) => { fullscreen = value; },+ close() { destroyed = true; window.emit("closed"); },+ command(command) { const buffer = Buffer.alloc(8); buffer.writeUInt32LE(command); hooks.get(0x112)?.(buffer); },+ };+}++test("transparent Windows caption/keyboard maximize reaches the public API after native dispatch", async () => {+ const f = transparentFixture();+ f.command(0xf031); // low four bits are reserved by WM_SYSCOMMAND.+ f.command(0xf030);+ assert.equal(f.count, 0);+ await new Promise(setImmediate);+ assert.equal(f.count, 1);+ f.command(0xf030);+ await new Promise(setImmediate);+ assert.equal(f.count, 1, "already maximized is not toggled back");+ f.dispose();+ assert.equal(f.hooks.size, 0);+});++test("transparent Windows leaves unrelated commands/fullscreen alone and cancels on close", async () => {+ const f = transparentFixture();+ f.command(0xf020); // minimize+ f.command(0xf120); // restore+ await new Promise(setImmediate);+ assert.equal(f.count, 0);+ f.setFullscreen(true);+ f.command(0xf030);+ await new Promise(setImmediate);+ assert.equal(f.count, 0);+ f.setFullscreen(false);+ f.command(0xf030);+ f.close();+ await new Promise(setImmediate);+ assert.equal(f.count, 0);+});+++test("macOS zoom animation is not blocked by an early native maximize flag", () => {+ const f = fixture("darwin");+ f.setNativeMaximized(true); // native flag precedes the end-of-zoom event.+ assert.equal(f.drag("will-resize"), false);+ f.window.emit("maximize");+ assert.equal(f.drag("will-resize"), true);+ f.setNativeMaximized(false); // programmatic bounds change, without native zoom.+ f.window.emit("resize");+ assert.equal(f.drag("will-resize"), false);+ f.dispose();+});diff --git a/apps/desktop/test/window-topmost-lifecycle.test.mjs b/apps/desktop/test/window-topmost-lifecycle.test.mjsindex 33f5720bc..232ec99e8 100644--- a/apps/desktop/test/window-topmost-lifecycle.test.mjs+++ b/apps/desktop/test/window-topmost-lifecycle.test.mjs@@ -9,8 +9,13 @@ import {windowBoundsEqual,} from "../electron/main/work-panel-window.ts";import { readMainModule } from "./helpers/source-contracts.mjs";+import { nativeWindowMinimumSize } from "../electron/main/window-native-behavior.ts";+import { isWindowFullScreen } from "../electron/main/window-fullscreen.ts";const source = await readMainModule("bootstrap/window.ts");+const minimumStart = source.indexOf(" const setNativeMinimumSize =");+const nativeMinimum = source.slice(minimumStart,+ source.indexOf(' if (process.platform === "win32") {', minimumStart));// Execute the production recovery, event wiring and watchdog without booting Electron.const recovery = source.slice(source.indexOf(" const CODEX_BOUNDS ="),@@ -28,6 +33,7 @@ function createRecoveryWindow(platform, { tiny = false, visible = true, minimizeconst calls = [];const window = Object.assign(new EventEmitter(), {isMaximized: () => false,+ isFullScreen: () => false,isMinimized: () => minimized,isVisible: () => visible,getBounds: () => ({ ...bounds }),@@ -47,7 +53,7 @@ function createRecoveryWindow(platform, { tiny = false, visible = true, minimizetimers.set(id, { callback, at: now + delay, delay, repeat });return id;};- vm.runInNewContext(stripTypeScriptTypes(`${recovery}\n${watchdog}`), {+ vm.runInNewContext(stripTypeScriptTypes(`${nativeMinimum}\n${recovery}\n${watchdog}`), {window,windowState: {},windowMinWidth: 800,@@ -56,6 +62,8 @@ function createRecoveryWindow(platform, { tiny = false, visible = true, minimizeisLiveWindow: () => true,screen: { getDisplayMatching: () => ({ workArea: { x: 0, y: 0, width: 1920, height: 1080 } }) },clampMinimumSizeToWorkArea,+ nativeWindowMinimumSize,+ isWindowFullScreen,emptyWorkPanelReservationState,windowBoundsEqual,applyWorkPanelReservation: () => {},diff --git a/docs/spec/04-ux/09-interaction-patterns.md b/docs/spec/04-ux/09-interaction-patterns.mdindex c6eb146d3..b71614b53 100644--- a/docs/spec/04-ux/09-interaction-patterns.md+++ b/docs/spec/04-ux/09-interaction-patterns.md@@ -1992,3 +1992,33 @@ This does not prevent state changes — it makes them instant.the expanded sidebar yields at the threshold and returns when the panelcloses, and divider cancellation restores the prior panel width(ADR 0033 / ADR 0151 / ADR 0238)+++## Native main-window gestures++- Titlebar double-click and left/right edge tiling remain OS-owned. macOS+ honors the user's titlebar double-click preference; edge tiling requires+ macOS 15 or later and enabled system tiling. Linux behavior depends on its+ compositor/window manager. The renderer must not duplicate native double-click.+- On transparent Windows 10 main windows, Main observes `SC_MAXIMIZE` and+ defers the public maximize API until Electron has consumed the otherwise+ blocked native command. Caption double-click, keyboard and top-edge maximize+ share this repair. Restore/minimize, opaque Windows 11 windows and fullscreen+ are untouched; pending work is cancelled when the window closes.+- The native main-window minimum width is capped to half the current display's+ work area, with 16 DIP reserved for macOS tile margins. The nominal 800 DIP+ chat-width contract is unchanged; this exception only relaxes the native+ window constraint so small/scaled displays can accept side-by-side tiles.+ The minimum height remains 560 DIP, capped to the work-area height.+- On macOS and Windows a maximized main window rejects manual edge resizing.+ Windows retains native drag-to-restore. On macOS the shell temporarily disables+ CSS caption dragging and handles caption double-click as Restore; normal+ windows retain native double-click behavior. The inherited `--window-drag-region`+ marker distinguishes caption text from explicit no-drag controls. Do not use+ `setMovable(false)`: it prevents native double-click restore in parts of the+ inset titlebar. Native zoom/green controls, fullscreen, and programmatic bounds+ remain enabled. Linux retains compositor-owned maximized geometry and+ drag-to-restore.+- A settled cross-display move refreshes the native minimum without enlarging a+ window already placed in a narrower tile. Normal bounds persistence and the+ internal work-panel/chat-width IPC contracts are unchanged.diff --git a/docs/spec/06-delivery/e2e/ui-shell.md b/docs/spec/06-delivery/e2e/ui-shell.mdindex 986508867..8cfa519dc 100644--- a/docs/spec/06-delivery/e2e/ui-shell.md+++ b/docs/spec/06-delivery/e2e/ui-shell.md@@ -2655,6 +2655,37 @@## E2E-167: Window edge resize stays smooth and persists the settled bounds+Native gesture regression: run `node scripts/e2e-window-native-behavior.mjs`+with the pinned Electron in an interactive desktop. The isolated fixture uses+production minimum-size and maximize-guard logic. On macOS test both opaque+and translucent windows: a 1440 DIP display's half-width minimum must allow a+window below 800 DIP, maximize must preserve native zoom/green controls,+and restore must re-enable edge resizing. `node scripts/e2e-window-controls.mjs`+then covers the built shell: maximized caption regions must compute to no-drag,+and a double-click must restore through the real preload/IPC and unlock the+normal caption. `maximized-window-chrome.test.mjs` covers late-query/event races,+repeated clicks, no-drag controls and unmount cleanup.+Windows covers maximize/restore with the same production guard; Linux keeps+its compositor-owned geometry. Unit tests cover cancellable edge events and+listener cleanup (`window-native-behavior.test.mjs`).++For transparent Windows 10 windows, send native caption double-click and+Win+Up/top-edge maximize; `SC_MAXIMIZE` must reach the public maximize path+exactly once. Restore/minimize/fullscreen and closing before deferred dispatch+must not trigger a maximize. Opaque Windows 11 windows keep their existing path.+These native Windows commands are unit-covered, not qualified by the macOS run.++Physical acceptance remains required on each target OS: double-click empty+regions across the 46 DIP titlebar (not action buttons), restore, drag to both+screen edges on a small/scaled display, maximize, attempt each edge/corner+resize and titlebar movement, then restore and repeat ordinary resizing.+On macOS enable system edge tiling (15+) and double-click zoom; repeat with+translucency on/off. Preserve fullscreen entry/exit and green-button access.+On Linux record desktop environment and X11/Wayland; do not claim one+compositor's behavior qualifies the others. A missing native runner or input+permission is NOT RUN, not passing native gesture acceptance.++Native Windows snapping regression (issue #2330): on an interactive Windowsdesktop with a work-area half at least the nominal minimum width, run`pnpm test:e2e:window-snap` against the candidate Windows Host and pinned Electron.diff --git a/scripts/e2e-window-controls.mjs b/scripts/e2e-window-controls.mjsindex d493abcbe..873bb9f65 100644--- a/scripts/e2e-window-controls.mjs+++ b/scripts/e2e-window-controls.mjs@@ -25,7 +25,14 @@ const execFileAsync = promisify(execFile);const { appDir } = assertDesktopBuild(root);const { electronBinary } = resolveElectronBinary(root);const binary = resolveHostBinary();-const temp = await mkdtemp(join(tmpdir(), "pi-window-controls-"));+const temp = await mkdtemp(join(process.env.PI_SCRATCH_DIR || tmpdir(), "pi-window-controls-"));+const isolatedEnv = {+ HOME: join(temp, "home"), USERPROFILE: join(temp, "home"),+ XDG_CONFIG_HOME: join(temp, "home/.config"),+ PI_CODING_AGENT_DIR: join(temp, "home/.pi/agent"),+ PI_DESKTOP_AGENTS_DIR: join(temp, "home/agents"),+};+await mkdir(isolatedEnv.HOME, { recursive: true });const port = Number(process.env.PI_DESKTOP_CHROME_CDP_PORT || 9347);const pending = new Map();let sequence = 0;@@ -230,7 +237,7 @@ try {}));await writeFile(join(radiusPluginPath, "main.js"), "// E2E theme fixture.\n");await writeFile(join(radiusPluginPath, "theme.css"), ":root[data-theme=\"dark\"] { --ds-bg-primary: #181818; }\n");- const host = new Host(binary, join(temp, "data"));+ const host = new Host(binary, join(temp, "data"), { env: isolatedEnv });let sessionId;try {await host.start();@@ -240,7 +247,7 @@ try {} finally {await host.stop();}- const env = { ...process.env, PI_DESKTOP_DATA_DIR: join(temp, "data"),+ const env = { ...process.env, ...isolatedEnv, PI_DESKTOP_DATA_DIR: join(temp, "data"),PI_DESKTOP_HOST_BIN: binary, PI_DESKTOP_START_MAXIMIZED: "0",PI_DESKTOP_MCP_CONTROL: "0", ELECTRON_RENDERER_URL: "" };delete env.ELECTRON_RUN_AS_NODE;@@ -313,8 +320,17 @@ try {assert.equal(JSON.parse(stdout.trim()).appCoversTaskbar, true, `fullscreen covers the taskbar: ${stdout.trim()}`);console.log("PASS fullscreen covers the taskbar");}+ await evaluate(`(() => {+ window.__PI_WINDOW_E2E_LEFT_FULLSCREEN__ = false;+ const off = window.piDesktop.on('pi-desktop/window/event/fullscreen', payload => {+ if (payload.fullScreen) return;+ window.__PI_WINDOW_E2E_LEFT_FULLSCREEN__ = true;+ off();+ });+ })()`);await evaluate(`window.piDesktop.invoke('pi-desktop/menu/nativeAction', {action:'toggleFullScreen'})`);- await waitFor(() => evaluate(`window.piDesktop.invoke('pi-desktop/menu/nativeAction', {action:'restoreMainWindow'}).then(s => s.ok && !s.data.fullScreen)`), "leave native fullscreen");+ await waitFor(() => evaluate(`window.__PI_WINDOW_E2E_LEFT_FULLSCREEN__ === true`), "native leave-full-screen event");+ await waitFor(() => evaluate(`window.piDesktop.invoke('pi-desktop/window/control', {action:'getState'}).then(s => s.ok && !s.data.fullScreen)`), "leave native fullscreen");await settle();if (process.platform !== "darwin") {await click(".window-control-btn:nth-child(2)");@@ -322,6 +338,28 @@ try {await checkControls("native window maximized with panel open");await click(".window-control-btn:nth-child(2)");await waitFor(() => evaluate(`window.piDesktop.invoke('pi-desktop/window/control', {action:'getState'}).then(s => s.ok && !s.data.maximized)`), "native window restored");+ } else {+ await evaluate(`window.piDesktop.invoke('pi-desktop/window/control', {action:'toggleMaximize'})`);+ await waitFor(() => evaluate(`document.documentElement.dataset.windowMaximized === 'true'`), "macOS maximized caption lock");+ await settle();+ const point = await evaluate(`(() => {+ for (let y = 8; y < 46; y += 8) for (let x = 180; x < innerWidth - 40; x += 32) {+ const el = document.elementFromPoint(x, y);+ if (!el) continue;+ const style = getComputedStyle(el);+ if (style.getPropertyValue('--window-drag-region').trim() !== 'drag') continue;+ if (style.getPropertyValue('-webkit-app-region').trim() !== 'no-drag') throw new Error('Maximized caption is still natively draggable');+ return { x, y };+ }+ throw new Error('No visible caption region');+ })()`);+ await send("Input.dispatchMouseEvent", { type: "mouseMoved", ...point });+ for (const clickCount of [1, 2]) for (const type of ["mousePressed", "mouseReleased"]) {+ await send("Input.dispatchMouseEvent", { type, ...point, button: "left", clickCount });+ }+ await waitFor(() => evaluate(`window.piDesktop.invoke('pi-desktop/window/control', {action:'getState'}).then(s => s.ok && !s.data.maximized)`), "macOS caption double-click restore");+ await waitFor(() => evaluate(`document.documentElement.dataset.windowMaximized === 'false'`), "macOS normal caption unlock");+ console.log("PASS macOS maximized caption cannot drag and double-click restores through real IPC");}await click(".app-work-panel-toggle");await waitFor(() => evaluate(`!document.querySelector('.work-panel')`), "panel closed again");diff --git a/scripts/e2e-window-native-behavior.mjs b/scripts/e2e-window-native-behavior.mjsnew file mode 100644index 000000000..ad467b0f1--- /dev/null+++ b/scripts/e2e-window-native-behavior.mjs@@ -0,0 +1,87 @@+#!/usr/bin/env node+/** Isolated native window lifecycle; never attaches to a running Desktop. */+import assert from "node:assert/strict";+import { execFile } from "node:child_process";+import { createRequire } from "node:module";+import { mkdtemp, rm } from "node:fs/promises";+import { tmpdir } from "node:os";+import { join } from "node:path";+import { promisify } from "node:util";+import { repositoryRoot, resolveElectronBinary } from "./e2e/boot.mjs";++const root = repositoryRoot();+const require = createRequire(join(root, "apps/desktop/package.json"));+const { build } = require("esbuild");+const directory = await mkdtemp(join(process.env.PI_SCRATCH_DIR || tmpdir(), "pi-native-window-"));+const fixture = join(directory, "main.cjs");+try {+ await build({+ stdin: {+ resolveDir: root,+ contents: `+const assert = require("node:assert/strict");+const { app, BrowserWindow, screen } = require("electron");+const { installMaximizedWindowGuard, nativeWindowMinimumSize } = require("./apps/desktop/electron/main/window-native-behavior.ts");+app.on("window-all-closed", () => {});+function transition(window, action, event) {+ return new Promise((resolve, reject) => {+ const timeout = setTimeout(() => { cleanup(); reject(new Error("Timed out: " + event)); }, 10000);+ const done = () => { cleanup(); resolve(); };+ const cleanup = () => { clearTimeout(timeout); window.removeListener(event, done); };+ window.once(event, done);+ action();+ });+}+app.whenReady().then(async () => {+ // Reproduce the original native constraint before exercising the repair.+ const baseline = new BrowserWindow({ width: 900, height: 650, minWidth: 800, show: false });+ baseline.setSize(704, 650);+ assert.equal(baseline.getBounds().width, 800, "baseline: native minimum rejects a half-width tile");+ baseline.destroy();+ for (const transparent of process.platform === "darwin" ? [false, true] : [false]) {+ const minimum = nativeWindowMinimumSize({ width: 800, height: 560 }, { width: 1440, height: 900 }, process.platform);+ const window = new BrowserWindow({+ width: 900, height: 650, minWidth: minimum.width, minHeight: minimum.height,+ title: "PI isolated native window test", resizable: true,+ ...(process.platform === "darwin" ? {+ titleBarStyle: "hiddenInset", trafficLightPosition: { x: 12, y: 12 },+ transparent, ...(transparent ? { vibrancy: "sidebar" } : {}),+ } : { frame: false }),+ webPreferences: { sandbox: true },+ });+ installMaximizedWindowGuard(window, process.platform);+ await window.loadURL("data:text/html,<style>body{margin:0}.drag{height:46px;-webkit-app-region:drag}</style><div class=drag>Isolated native window test</div>");+ await window.webContents.executeJavaScript("new Promise(r=>requestAnimationFrame(()=>requestAnimationFrame(r)))");+ window.setSize(704, 650);+ assert.ok(window.getBounds().width <= 720, "native half-width tile is not blocked by the old 800 DIP minimum");+ await transition(window, () => window.maximize(), "maximize");+ assert.equal(window.isMaximized(), true);+ assert.equal(window.isResizable(), true, "native restore/green button is not disabled");+ if (process.platform === "darwin") {+ assert.equal(window.isMovable(), true, "native zoom remains available; renderer owns caption locking");+ assert.equal(window.isMaximizable(), true, "green button remains available");+ }+ await transition(window, () => window.unmaximize(), "unmaximize");+ assert.equal(window.isMaximized(), false);+ if (process.platform === "darwin") assert.equal(window.isMovable(), true);+ window.setSize(900, 650);+ assert.equal(window.getBounds().width, 900, "restored window can resize again");+ window.destroy();+ console.log("PASS native maximize/restore and half-width minimum: " + process.platform + ", transparent=" + transparent);+ }+ console.log("Environment: Electron " + process.versions.electron + ", " + JSON.stringify(screen.getPrimaryDisplay().workArea));+ app.exit(0);+}).catch(error => { console.error(error); app.exit(1); });+`,+ },+ outfile: fixture, bundle: true, platform: "node", format: "cjs", external: ["electron"],+ });+ const { ELECTRON_RUN_AS_NODE: _runAsNode, ...env } = process.env;+ const result = await promisify(execFile)(resolveElectronBinary(root).electronBinary,+ [fixture, `--user-data-dir=${join(directory, "profile")}`], { env, timeout: 60000 });+ process.stdout.write(result.stdout);+ process.stderr.write(result.stderr);+ assert.match(result.stdout, /PASS native maximize\/restore/);+} finally {+ await rm(directory, { recursive: true, force: true });+}