Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(desktop): reapply Windows corner shape after restore (#1521)

Landb83f95ebd96
diff --git a/apps/desktop/electron/main/window-shape.ts b/apps/desktop/electron/main/window-shape.ts
index 14c88e2d0..fb3e086fc 100644
--- a/apps/desktop/electron/main/window-shape.ts
+++ b/apps/desktop/electron/main/window-shape.ts
@@ -27,26 +27,32 @@ export function roundedWindowShape(width: number, height: number, radius: number
export function installWindowShape(window: BrowserWindow, initialRadius = DEFAULT_WINDOW_CORNER_RADIUS) {
let radius = initialRadius;
let lastShape = "";
- const apply = () => {
+ const apply = (force = false) => {
if (window.isDestroyed()) return;
const { width, height } = window.getBounds();
const rectangular = window.isMaximized() || isWindowFullScreen(window);
const shapeKey = `${width}:${height}:${rectangular ? 0 : radius}`;
- if (shapeKey === lastShape) return;
+ if (!force && shapeKey === lastShape) return;
window.setShape(rectangular ? [] : roundedWindowShape(width, height, radius));
lastShape = shapeKey;
};
+ // Windows can reset the native window region during visibility transitions.
+ const reapply = () => apply(true);
window.on("resize", apply);
window.on("maximize", apply);
window.on("unmaximize", apply);
window.on("enter-full-screen", apply);
window.on("leave-full-screen", apply);
+ window.on("show", reapply);
+ window.on("restore", reapply);
const dispose = () => {
window.removeListener("resize", apply);
window.removeListener("maximize", apply);
window.removeListener("unmaximize", apply);
window.removeListener("enter-full-screen", apply);
window.removeListener("leave-full-screen", apply);
+ window.removeListener("show", reapply);
+ window.removeListener("restore", reapply);
window.removeListener("closed", dispose);
controllers.delete(window);
};
diff --git a/apps/desktop/test/window-shape.test.mjs b/apps/desktop/test/window-shape.test.mjs
index 47114706b..94d74bffc 100644
--- a/apps/desktop/test/window-shape.test.mjs
+++ b/apps/desktop/test/window-shape.test.mjs
@@ -61,3 +61,27 @@ test("shape follows resize and becomes rectangular in maximized or fullscreen st
assert.equal(window.listenerCount("resize"), 0);
assert.equal(setWindowCornerRadius(window, 8), null);
});
+
+test("native shape is re-applied after the window is shown or restored", () => {
+ const window = new EventEmitter();
+ let bounds = { x: 20, y: 30, width: 100, height: 80 };
+ let setShapeCalls = 0;
+ window.getBounds = () => bounds;
+ window.isDestroyed = () => false;
+ window.isMaximized = () => false;
+ window.isFullScreen = () => false;
+ window.setShape = () => { setShapeCalls += 1; };
+
+ installWindowShape(window);
+ assert.equal(setShapeCalls, 1);
+
+ window.emit("show");
+ assert.equal(setShapeCalls, 2);
+ window.emit("restore");
+ assert.equal(setShapeCalls, 3);
+
+ window.emit("closed");
+ window.emit("show");
+ window.emit("restore");
+ assert.equal(setShapeCalls, 3);
+});
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index abe612b25..7cd8d844f 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -12163,6 +12163,8 @@ This test plan spec is accepted when:
`--radius-md` token, before and after
resizing. Apply an authorized theme with `cornerRadius: 0`, then return to
a built-in theme. Reject an out-of-range radius without changing the shape.
+ 7. On Windows, minimize and restore the window, then confirm all four native
+ corner cutouts still match the selected radius.
- **Expected**: Native edge and corner hit regions remain available in frameless
chrome, the minimum size remains 800×560 (capped to the display
work area), and the recovery watchdog does not
@@ -12182,8 +12184,9 @@ This test plan spec is accepted when:
ADR 0029 / ADR 0151 / ADR 0317
- **Acceptance**: A (app shell), F (persistence), Quality
- **Milestone**: M6+
-- **Status**: `test:e2e:window-controls` covers corner cutouts, theme radius
- changes, fullscreen, maximize, and controls in an isolated profile.
+- **Status**: `test:e2e:window-controls` covers corner cutouts before and after
+ minimize/restore, theme radius changes, fullscreen, maximize, and controls
+ in an isolated profile.
`test:e2e:window-resize-native` adds physical Windows left/right/bottom/corner
drags and the 800×560 minimum; run it on a dedicated interactive desktop,
since another app can take foreground or pointer input during the gesture.
diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index 29fc08f03..00ebbc8e0 100644
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@ -7036,7 +7036,8 @@ eleven-tool-round desktop paths are verified by
4. 在 Windows 上检查默认 12 DIP 圆角在调整大小前后保持一致;选择获授权
的 `cornerRadius: 0` 主题,再切回内置主题,确认恢复为全局 `--radius-md`;
输入超过 24 DIP 的半径应被拒绝。
- 5. 等待调整大小稳定后关闭并重新启动应用。
+ 5. 在 Windows 上最小化并恢复窗口,然后确认四个原生圆角仍与所选半径一致。
+ 6. 等待调整大小稳定后关闭并重新启动应用。
- **预期**:无边框外壳仍提供原生边缘和角落命中区域;Windows 默认圆角使用
全局 12 DIP `--radius-md`,最大化/全屏时为矩形。最小尺寸保持
800×560(按显示器工作区裁剪),恢复看门狗不会与慢速调整大小流竞争。最后稳定的基础边界会
@@ -7046,7 +7047,7 @@ eleven-tool-round desktop paths are verified by
`04-ux/09-interaction-patterns.md`、ADR 0029 / ADR 0122 / ADR 0317 / D637
- **验收**:A(应用外壳)、F(坚持)、质量
- **里程碑**:M6+
-- **状态**:`test:e2e:window-controls` 覆盖圆角裁切、主题半径变化、全屏、最大化和窗口控件;
+- **状态**:`test:e2e:window-controls` 覆盖最小化/恢复前后的圆角裁切、主题半径变化、全屏、最大化和窗口控件;
Windows 原生拖动需在专用交互式桌面上运行 `test:e2e:window-resize-native`。
#### E2E-168:展开侧边栏宽度跟随锚定的调整手势
diff --git a/scripts/e2e-window-controls.mjs b/scripts/e2e-window-controls.mjs
index 7671d8c4e..af3999aac 100644
--- a/scripts/e2e-window-controls.mjs
+++ b/scripts/e2e-window-controls.mjs
@@ -360,6 +360,7 @@ try {
await waitFor(() => evaluate(`document.visibilityState === 'visible'`), "native window shown");
await settle();
await checkControls("restored after native minimize");
+ await checkWindowsRoundedCorners("corners remain transparent after native minimize and restore");
// Configure only the disposable profile so close-to-tray can be observed
// without leaving a blocking native confirmation dialog on the test runner.
await evaluate(`window.piDesktop.invoke('pi-desktop/window/closeBehavior/set', {behavior:'tray'})`);