Skip to content

修复窗口大小和位置似乎无法记忆的问题#327

Open
Jack251970 wants to merge 3 commits into
qxcnm:mainfrom
Jack251970:main
Open

修复窗口大小和位置似乎无法记忆的问题#327
Jack251970 wants to merge 3 commits into
qxcnm:mainfrom
Jack251970:main

Conversation

@Jack251970

Copy link
Copy Markdown

变更摘要

  • Windows 平台下窗口关闭后再打开,位置不会被记忆(大小看似"记忆"实为 tauri.conf.json 硬编码默认值)。根因:无任何窗口状态持久化逻辑。
  • 集成 tauri-plugin-window-state 2.4.1,自动在窗口创建时恢复、销毁时保存位置/大小/最大化/全屏等状态。在 CloseRequested 事件中显式调用 save_window_state,确保 lightweight tray close 和 hide-to-tray 两条路径均在窗口销毁前落盘。

Fix #326.

改动范围

  • Frontend
  • Desktop / Tauri
  • Service
  • Gateway / Protocol Adapter
  • Docs / Governance
  • Workflow / Release

主要文件

  • apps/src-tauri/Cargo.toml — 新增 tauri-plugin-window-state = "2.4.1" 依赖
  • apps/src-tauri/src/lib.rs — 注册插件(StateFlags::all()
  • apps/src-tauri/capabilities/default.json — 添加 window-state:default 权限
  • apps/src-tauri/src/app_shell/lifecycle.rsCloseRequested 处理中显式保存窗口状态

验证

  • pnpm -C apps run test
  • pnpm -C apps run build
  • pnpm -C apps run test:ui
  • cargo test --workspace
  • 其他本地验证已说明

已执行的验证:

cargo check -p CodexManager (apps/src-tauri) — 编译通过,无 warning
cargo test (apps/src-tauri) — 48 passed, 0 failed
cargo test --workspace — 1083 passed, 4 failed (均为沙箱 DNS 不可达的网络测试,与本次变更无关)

未执行的验证与原因:

pnpm 前端构建/测试 — 本次无前端改动
Windows 实机验证 — 不是特别会使用Rust

风险与影响面

  • 插件将窗口状态写入 app_config_dir(Windows 为 %APPDATA%),首次升级后无历史状态文件,行为与之前一致(使用 tauri.conf.json 默认值),无破坏性变更。
  • StateFlags::all() 同时保存 maximized/fullscreen 状态;如需仅保存 position + size 可收窄为 StateFlags::SIZE | StateFlags::POSITION
  • 仅影响桌面端(Tauri),不影响 service/web 模式。

备注

  • 提交前请确认未包含敏感 token、cookie、API key

Copilot AI and others added 2 commits June 27, 2026 06:19
…ition

fix: persist window position and size across restarts using tauri-plugin-window-state
Copilot AI review requested due to automatic review settings June 27, 2026 06:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 在Windows平台下,窗口大小和位置似乎无法记忆

3 participants