Skip to content

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

修复(window):任务栏还原最大化窗口后盖住任务栏(补充 #1655) (#1672)

AnJia499bdabbb7a7
diff --git a/apps/desktop/electron/main/bootstrap/window.ts b/apps/desktop/electron/main/bootstrap/window.ts
index 6337f325d..c2aac41db 100644
--- a/apps/desktop/electron/main/bootstrap/window.ts
+++ b/apps/desktop/electron/main/bootstrap/window.ts
@@ -22,6 +22,8 @@ import {
displayWorkAreaKey,
emptyWorkPanelReservationState,
isWorkPanelOuterResizeEdge,
+ maximizedBoundsExceedWorkArea,
+ maximizedBoundsForWorkArea,
planWorkPanelChatResize,
planWorkPanelReservation,
WORK_PANEL_MAX_WIDTH,
@@ -920,6 +922,35 @@ export async function createWindow({
window.on("show", () => ensureStableBounds(false));
window.on("focus", () => ensureStableBounds(false));
window.on("restore", () => ensureStableBounds(false));
+
+ // Windows restores a frameless maximized window to the full monitor rect
+ // instead of the work area, so the window covers the taskbar and reads as
+ // fullscreen (issue #1655). Re-apply the work-area-based maximized rect.
+ const reconcileRestoredMaximize = () => {
+ if (!isLiveWindow() || process.platform !== "win32") return;
+ if (
+ !window.isMaximized() ||
+ isWindowFullScreen(window) ||
+ window.isMinimized()
+ ) {
+ return;
+ }
+ const bounds = window.getBounds();
+ const workArea = screen.getDisplayMatching(bounds).workArea;
+ if (!maximizedBoundsExceedWorkArea(bounds, workArea)) return;
+ window.setBounds(maximizedBoundsForWorkArea(bounds, workArea));
+ };
+ // The OS finishes the restore after the event dispatch, overwriting a
+ // synchronous correction, so try now and again once the transition settles.
+ let restoredMaximizeTimer: NodeJS.Timeout | null = null;
+ window.on("restore", () => {
+ reconcileRestoredMaximize();
+ if (restoredMaximizeTimer) clearTimeout(restoredMaximizeTimer);
+ restoredMaximizeTimer = setTimeout(() => {
+ restoredMaximizeTimer = null;
+ reconcileRestoredMaximize();
+ }, windowBoundsSettleMs);
+ });
window.on("resize", observeNativeWorkPanelResize);
window.on("move", scheduleBoundsCheck);
window.on("move", noteUserWindowMove);
@@ -1090,6 +1121,10 @@ export async function createWindow({
clearTimeout(workPanelSettleExpiryTimer);
workPanelSettleExpiryTimer = null;
}
+ if (restoredMaximizeTimer) {
+ clearTimeout(restoredMaximizeTimer);
+ restoredMaximizeTimer = null;
+ }
if (boundsWatchdog) clearInterval(boundsWatchdog);
});
diff --git a/apps/desktop/electron/main/work-panel-window.ts b/apps/desktop/electron/main/work-panel-window.ts
index d2e6dfb48..b3c6eb670 100644
--- a/apps/desktop/electron/main/work-panel-window.ts
+++ b/apps/desktop/electron/main/work-panel-window.ts
@@ -167,6 +167,43 @@ export function clampMinimumSizeToWorkArea(
};
}
+/** The overshoot a maximized window keeps above the work area. */
+function maximizedBoundsInset(bounds: WindowBounds, workArea: WindowBounds): number {
+ return Math.max(0, workArea.y - bounds.y);
+}
+
+/**
+ * Windows restores a frameless maximized window to the full monitor rect
+ * instead of the work area, leaving the bottom edge below the work area by the
+ * taskbar height (issue #1655). A healthy maximized rect only overshoots the
+ * work area by the same inset above and below it.
+ */
+export function maximizedBoundsExceedWorkArea(
+ bounds: WindowBounds,
+ workArea: WindowBounds,
+): boolean {
+ const inset = maximizedBoundsInset(bounds, workArea);
+ return bounds.y + bounds.height > workArea.y + workArea.height + inset;
+}
+
+/**
+ * The work-area-based maximized rect matching the inset the window already has
+ * above the work area, so re-applying it reproduces the native maximize
+ * footprint instead of shrinking the window inside the taskbar.
+ */
+export function maximizedBoundsForWorkArea(
+ bounds: WindowBounds,
+ workArea: WindowBounds,
+): WindowBounds {
+ const inset = maximizedBoundsInset(bounds, workArea);
+ return {
+ x: workArea.x - inset,
+ y: workArea.y - inset,
+ width: workArea.width + inset * 2,
+ height: workArea.height + inset * 2,
+ };
+}
+
export function planWorkPanelReservation({
baseBounds,
workArea,
diff --git a/apps/desktop/test/window-fullscreen-maximize.test.mjs b/apps/desktop/test/window-fullscreen-maximize.test.mjs
index d2c6a81a4..5d166b706 100644
--- a/apps/desktop/test/window-fullscreen-maximize.test.mjs
+++ b/apps/desktop/test/window-fullscreen-maximize.test.mjs
@@ -20,6 +20,9 @@ register(pathToFileURL(join(here, "helpers/ts-import-hooks.mjs")));
const { isWindowFullScreen, setWindowFullScreen } = await import(
"../electron/main/window-fullscreen.ts"
);
+const { maximizedBoundsExceedWorkArea, maximizedBoundsForWorkArea } = await import(
+ "../electron/main/work-panel-window.ts"
+);
const { readMainSource } = await import("./helpers/source-contracts.mjs");
const lifecycleSource = await readMainSource();
@@ -194,3 +197,57 @@ test("the display-topology reconcile uses the tracked fullscreen flag", () => {
/if \(isLiveWindow\(\) && !isWindowFullScreen\(window\)\) \{/,
);
});
+
+test("a maximized rect that only overshoots the work area is left alone", () => {
+ const workArea = { x: 0, y: 0, width: 1920, height: 1032 };
+ const maximized = { x: -8, y: -8, width: 1936, height: 1048 };
+ assert.equal(maximizedBoundsExceedWorkArea(maximized, workArea), false);
+ assert.deepEqual(maximizedBoundsForWorkArea(maximized, workArea), maximized);
+});
+
+test("the frameless restore that hides the taskbar is detected and corrected", () => {
+ // Windows restores a frameless maximized window to the full monitor rect:
+ // height 1120 instead of the work-area-based 1048, so the taskbar is hidden.
+ const workArea = { x: 0, y: 0, width: 1920, height: 1032 };
+ const restored = { x: -8, y: -8, width: 1936, height: 1120 };
+ assert.equal(maximizedBoundsExceedWorkArea(restored, workArea), true);
+ assert.deepEqual(maximizedBoundsForWorkArea(restored, workArea), {
+ x: -8,
+ y: -8,
+ width: 1936,
+ height: 1048,
+ });
+});
+
+test("a monitor without a taskbar never reports a false positive", () => {
+ // Secondary display: the work area equals the monitor, so a healthy
+ // maximized window already overshoots the bottom by the same inset as the
+ // top and must not be treated as a broken restore.
+ const workArea = { x: 1920, y: 0, width: 1920, height: 1080 };
+ const maximized = { x: 1912, y: -8, width: 1936, height: 1096 };
+ assert.equal(maximizedBoundsExceedWorkArea(maximized, workArea), false);
+ const restored = { x: 1912, y: -8, width: 1936, height: 1120 };
+ assert.equal(maximizedBoundsExceedWorkArea(restored, workArea), true);
+});
+
+test("a windowed rect is never treated as a broken maximize", () => {
+ const workArea = { x: 0, y: 0, width: 1920, height: 1032 };
+ const windowed = { x: 360, y: 116, width: 1200, height: 800 };
+ assert.equal(maximizedBoundsExceedWorkArea(windowed, workArea), false);
+});
+
+test("the restore handler re-applies the work-area-based maximized rect", () => {
+ const block = lifecycleSource.slice(
+ lifecycleSource.indexOf("const reconcileRestoredMaximize"),
+ lifecycleSource.indexOf('window.on("resize", observeNativeWorkPanelResize)'),
+ );
+ assert.match(block, /maximizedBoundsExceedWorkArea\(bounds, workArea\)/);
+ assert.match(
+ block,
+ /window\.setBounds\(maximizedBoundsForWorkArea\(bounds, workArea\)\)/,
+ );
+ assert.match(block, /window\.on\("restore"/);
+ // The OS finishes the restore after the event dispatch, so the correction
+ // has to be repeated once the transition settles.
+ assert.match(block, /windowBoundsSettleMs/);
+});
diff --git a/docs/spec/04-ux/09-interaction-patterns.md b/docs/spec/04-ux/09-interaction-patterns.md
index d660da6a3..126e98f14 100644
--- a/docs/spec/04-ux/09-interaction-patterns.md
+++ b/docs/spec/04-ux/09-interaction-patterns.md
@@ -168,7 +168,9 @@ recency only breaks ties between equally relevant matches.
- On Windows, clicking the taskbar button of the focused visible main window
means **native minimize**. The window stays represented by its taskbar entry;
the next click restores and focuses it. A taskbar click while the window is
- merely covered brings it to the front and does not hide it to the tray.
+ merely covered brings it to the front and does not hide it to the tray. When
+ a maximized frameless window is restored, it respects the active display's
+ work area so the taskbar remains visible.
- Tray hiding, including a Windows/Linux close with `tray`, removes the main
window from the taskbar/dock window list while the Electron process and
background work remain alive. It does not persist a minimized geometry or
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 17997e036..36d01b880 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -11149,11 +11149,12 @@ This test plan spec is accepted when:
- **Preconditions**: Built desktop app on macOS, Windows, and Linux; English
and zh-CN locales are available; a normal main window is open.
-- **Steps**: 1) On Windows, leave the focused main window visible and click its
+- **Steps**: 1) On Windows, maximize the focused main window and click its
taskbar button; confirm it minimizes while the PI-Desktop taskbar entry
- remains. Click the same taskbar button again and confirm the window restores
- and focuses. Cover the window with another app, click the PI-Desktop taskbar
- entry, and confirm it comes to the front without entering the tray. 2) On
+ remains. Click the same taskbar button again; after the restore settles,
+ confirm the window remains maximized within the display work area and the
+ taskbar stays visible. Cover the window with another app, click the PI-Desktop
+ taskbar entry, and confirm it comes to the front without entering the tray. 2) On
- macOS, click the traffic-light minimize control and confirm it hides the
window to the tray. On Windows/Linux, use the renderer minimize control and
confirm the native taskbar entry remains available; click it again and
@@ -11164,7 +11165,9 @@ This test plan spec is accepted when:
zh-CN and invoke macOS app activation while the window is tray-hidden.
- **Expected**: Windows native taskbar toggling and the Windows/Linux renderer
minimize controls keep the taskbar entry and round-trip through native
- minimize/restore; a taskbar click on a covered window brings it to the front.
+ minimize/restore. Restoring a maximized frameless Windows window keeps it
+ within the display work area and leaves the taskbar visible. A taskbar click
+ on a covered window brings it to the front.
Close to tray is the only Windows/Linux close path that hides the window,
while Quit exits. On macOS the menu bar icon is a readable transparent
monochrome PI mark without the rounded application tile, and native minimize
diff --git a/docs/zh-CN/spec/04-ux/09-interaction-patterns.md b/docs/zh-CN/spec/04-ux/09-interaction-patterns.md
index f08493d3d..119c557b5 100644
--- a/docs/zh-CN/spec/04-ux/09-interaction-patterns.md
+++ b/docs/zh-CN/spec/04-ux/09-interaction-patterns.md
@@ -128,20 +128,22 @@
Dock 生命周期(关闭后应用留在 Dock 中,激活时重建窗口)。边界看门狗
永远不会恢复一个最小化或隐藏到托盘的窗口。
-### 1. 5.1 托盘驻留最小化
-
-- 最小化意味着 macOS、Windows 和 Linux 上**隐藏到托盘**。渲染器的
- Windows/Linux 最小化按钮、macOS 交通灯最小化按钮,以及
- macOS 窗口 → 最小化角色共享此行为。
-- 隐藏将从 taskbar/dock 窗口列表中删除主窗口,而
- Electron 进程和后台工作仍然有效。它不坚持
- 最小化几何形状或处置 host/sidecar。
-- Double-clicking the tray icon (or single-clicking on Windows/Linux), choosing
- Open, or activating the macOS Dock restores/focuses the existing window or
- creates a new one if it was closed. macOS single-click opens the menu.
-- The localized tray includes Open, bounded session groups, and Quit. Quit
- keeps confirmation and ordered shutdown. Close behavior remains user-owned
- on Windows/Linux (ADR 0090), and macOS retains its Dock lifecycle.
+### 1.5.1 托盘驻留与任务栏最小化
+
+- Windows 和 Linux 上的显式应用最小化是**原生任务栏最小化**:渲染器窗口控件和
+ 原生菜单最小化操作使用常规系统过渡。macOS 交通灯最小化和“窗口 → 最小化”仍然
+ **隐藏到托盘**。
+- 在 Windows 上,单击当前聚焦且可见的主窗口任务栏按钮表示**原生最小化**。窗口仍保留
+ 在任务栏中;再次单击会还原并聚焦。若窗口只是被其他应用遮挡,单击任务栏按钮会将其带到
+ 前台,而不会隐藏到托盘。最大化的无边框窗口还原后仍符合当前显示器的工作区,任务栏保持可见。
+- 隐藏到托盘(包括 Windows/Linux 上选择“托盘”行为的关闭操作)会将主窗口从任务栏或 Dock
+ 列表中移除,而 Electron 进程和后台任务继续运行。它不会保存最小化几何状态,也不会释放
+ host/sidecar。
+- 双击托盘图标(Windows/Linux 上单击即可)、选择“打开”或从 macOS Dock 激活应用,都会恢复并
+ 聚焦现有窗口;如果窗口已关闭,则创建新窗口。macOS 单击托盘图标会打开菜单。
+- 本地化托盘菜单使用当前应用语言,提供“打开”、有数量上限的会话分组和“退出”。“退出”仍需
+ 确认并按正常顺序关闭。Windows/Linux 上的关闭行为由用户选择(ADR 0090),macOS 保持其 Dock
+ 生命周期;两种关闭选择下,托盘图标都只在启动时创建一次。
### 1.5.2 Tray session navigation (issue #293)
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 d4a18ac60..056513bd9 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
@@ -6628,25 +6628,29 @@ eleven-tool-round desktop paths are verified by
在同一会话排队两个请求,提交第一个后为第二个选择不同答案,确认两次提交分别包含
自己的请求 ID 和所选答案。
-#### E2E-124:最小化隐藏跨平台托盘中的窗口
+#### E2E-124:窗口控件最小化到任务栏并关闭到所选界面
- **先决条件**:在 macOS、Windows 和 Linux 上构建桌面应用程序;英语
和 zh-CN 语言环境可用;正常的主窗口打开。
-- **步骤**:1)从平台的窗口控制最小化(macOS流量
- 光或 Windows/Linux 渲染器控制)。 2) 确认主窗口是
- 当应用程序进程保持驻留时隐藏。 3) 单击或双击
- 托盘图标并确认同一窗口已恢复并聚焦。 4) 打开
- 托盘菜单并选择“显示”,然后重复“退出”。 5) 在 zh-CN 中重复并
- 在窗口隐藏时调用 macOS 应用程序激活。
-- **预期**:所有最小化路径都隐藏到一个托盘图标,而不是退出或
- 留下任务栏最小化的窗口。 Show/click/double-click/app 激活
-恢复现有窗口;本地化菜单包含 Show PI-Desktop
- 并退出 PI-Desktop。 Quit 运行正常的关闭顺序,并且不留下任何内容
- 孤立主机、sidecar 或托盘进程。关闭窗口仍然是明确的
- 放弃行动。
-- **链接规格**:`03-runtime/07-process-model.md`,
- `04-ux/09-interaction-patterns.md`、`08-meta/decisions-log.md` (D216)、
- ADR 0078
+- **步骤**:1)在 Windows 上最大化主窗口,然后单击其任务栏按钮;确认窗口最小化,
+ PI-Desktop 的任务栏项仍然存在。再次单击同一任务栏按钮;还原过渡结束后,确认
+ 窗口仍在最大化状态、边界符合显示器工作区,且任务栏仍可见。用其他应用覆盖窗口,
+ 再单击 PI-Desktop 的任务栏项,确认窗口回到前台且没有隐藏到托盘。2)在 macOS 上
+ 单击交通灯最小化控件,确认窗口隐藏到托盘。3)在 Windows/Linux 上使用渲染器最小化控件,
+ 确认原生任务栏项仍然存在;再次单击后确认同一窗口还原并聚焦。选择“关闭到托盘”并关闭
+ Windows/Linux 窗口,确认任务栏项消失且可从托盘恢复;选择“退出”并重复,确认进程退出。
+ 4)打开托盘菜单并选择“显示”,再重复“退出”。5)在 zh-CN 中重复,并在窗口隐藏时
+ 调用 macOS 应用程序激活。
+- **预期**:Windows 原生任务栏切换和 Windows/Linux 渲染器最小化控件保留任务栏项,
+ 并通过原生最小化/还原完成往返。还原最大化的无边框 Windows 窗口后,窗口仍符合显示器
+ 工作区,任务栏保持可见。单击被覆盖窗口的任务栏项会将窗口带到前台。Windows/Linux 上
+ 只有“关闭到托盘”会隐藏窗口;“退出”会结束进程。macOS 菜单栏图标是清晰的透明单色 PI
+ 标记,不带圆角应用磁贴,原生最小化仍隐藏到托盘。“显示”、托盘图标点击/双击及应用激活
+ 会恢复现有窗口;本地化菜单包含“显示 PI-Desktop”和“退出 PI-Desktop”。退出按正常顺序关闭,
+ 不留下孤立的主机、sidecar 或托盘进程。
+- **链接规格**:`03-runtime/01-ipc-protocol.md`、`03-runtime/07-process-model.md`、
+ `04-ux/08-component-spec.md`、`04-ux/09-interaction-patterns.md`、
+ `08-meta/decisions-log.md` (D216、D230、D252、D256)、ADR 0078、ADR 0090、ADR 0117、ADR 0123
- **验收**:A(应用程序生命周期),质量
- **里程碑**:M6+
- **状态**:Unit/source-contract 已覆盖;原生跨平台托盘之旅