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 macOS window bounds after zoom
Linuxdazhao2b104a8c509a
diff --git a/apps/desktop/electron/main/window-native-behavior.ts b/apps/desktop/electron/main/window-native-behavior.tsindex a4cbbb1ae..bbb22d45f 100644--- a/apps/desktop/electron/main/window-native-behavior.ts+++ b/apps/desktop/electron/main/window-native-behavior.ts@@ -15,17 +15,14 @@ export function nativeWindowMinimumSize(};}-/** Protect a maximized window without disabling native zoom/fullscreen controls. */+/** Keep the edges locked while a Windows window is maximized. */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.+ // AppKit routes both edge dragging and Zoom/Restore through will-resize.+ // On macOS and Linux the window manager owns the resize gesture.+ if (platform !== "win32") return () => {};let settledMaximized = window.isMaximized();const maximize = () => { settledMaximized = true; };const unmaximize = () => { settledMaximized = false; };diff --git a/apps/desktop/test/window-native-behavior.test.mjs b/apps/desktop/test/window-native-behavior.test.mjsindex 7b119f647..e07272642 100644--- a/apps/desktop/test/window-native-behavior.test.mjs+++ b/apps/desktop/test/window-native-behavior.test.mjs@@ -28,32 +28,30 @@ function fixture(platform, initiallyMaximized = false) {window.emit(event, { preventDefault() { prevented = true; } });return prevented;};- return { window, transition, drag, dispose, setNativeMaximized: (value) => { maximized = value; } };+ return { window, transition, drag, dispose };}-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);+test("Windows: maximize protects edges; restore re-enables native gestures", () => {+ const f = fixture("win32");+ assert.equal(f.drag("will-resize"), false);+ f.transition(true);assert.equal(f.drag("will-resize"), true);- f.dispose();+ 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 leaves native Zoom and edge resizing available after maximize", () => {+ const f = fixture("darwin");+ f.transition(true);assert.equal(f.window.isMovable(), true);+ assert.equal(f.window.listenerCount("will-resize"), 0);assert.equal(f.drag("will-resize"), false);+ f.dispose();});test("Linux retains compositor-owned maximize and movement", () => {@@ -64,7 +62,6 @@ test("Linux retains compositor-owned maximize and movement", () => {f.dispose();});-function transparentFixture() {const window = new EventEmitter();let destroyed = false;@@ -116,16 +113,3 @@ test("transparent Windows leaves unrelated commands/fullscreen alone and cancelsawait 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/docs/spec/04-ux/09-interaction-patterns.md b/docs/spec/04-ux/09-interaction-patterns.mdindex 786207fb2..ebcfa5963 100644--- a/docs/spec/04-ux/09-interaction-patterns.md+++ b/docs/spec/04-ux/09-interaction-patterns.md@@ -2032,8 +2032,10 @@ This does not prevent state changes — it makes them instant.chat-width contract is unchanged; this exception only relaxes the nativewindow 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+- On Windows a maximized main window rejects manual edge resizing and retains+ native drag-to-restore. AppKit owns edge resizing and Zoom/Restore on macOS.+ Both use the same cancellable resize event, so cancelling it would also block+ restoration of the window's original frame. The macOS shell temporarily disablesCSS caption dragging and handles caption double-click as Restore; normalwindows retain native double-click behavior. The inherited `--window-drag-region`marker distinguishes caption text from explicit no-drag controls. Do not usediff --git a/docs/spec/06-delivery/e2e/ui-shell.md b/docs/spec/06-delivery/e2e/ui-shell.mdindex a27e4e6e6..a982ddad5 100644--- a/docs/spec/06-delivery/e2e/ui-shell.md+++ b/docs/spec/06-delivery/e2e/ui-shell.md@@ -2689,8 +2689,9 @@ Native gesture regression: run `node scripts/e2e-window-native-behavior.mjs`with the pinned Electron in an interactive desktop. The isolated fixture usesproduction minimum-size and maximize-guard logic. On macOS test both opaqueand 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`+window below 800 DIP. Zoom/Restore must return the window to its original+position and size, and AppKit must be able to resize its edges.+`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 thenormal caption. `maximized-window-chrome.test.mjs` covers late-query/event races,diff --git a/scripts/e2e-window-native-behavior.mjs b/scripts/e2e-window-native-behavior.mjsindex ad467b0f1..175211698 100644--- a/scripts/e2e-window-native-behavior.mjs+++ b/scripts/e2e-window-native-behavior.mjs@@ -54,6 +54,7 @@ app.whenReady().then(async () => {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");+ const normalBounds = window.getBounds();await transition(window, () => window.maximize(), "maximize");assert.equal(window.isMaximized(), true);assert.equal(window.isResizable(), true, "native restore/green button is not disabled");@@ -63,7 +64,10 @@ app.whenReady().then(async () => {}await transition(window, () => window.unmaximize(), "unmaximize");assert.equal(window.isMaximized(), false);- if (process.platform === "darwin") assert.equal(window.isMovable(), true);+ if (process.platform === "darwin") {+ assert.deepEqual(window.getBounds(), normalBounds, "macOS Zoom must restore the entire window frame");+ assert.equal(window.isMovable(), true);+ }window.setSize(900, 650);assert.equal(window.getBounds().width, 900, "restored window can resize again");window.destroy();