修复窗口大小和位置似乎无法记忆的问题#327
Open
Jack251970 wants to merge 3 commits into
Open
Conversation
…ition fix: persist window position and size across restarts using tauri-plugin-window-state
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
变更摘要
tauri.conf.json硬编码默认值)。根因:无任何窗口状态持久化逻辑。tauri-plugin-window-state2.4.1,自动在窗口创建时恢复、销毁时保存位置/大小/最大化/全屏等状态。在CloseRequested事件中显式调用save_window_state,确保 lightweight tray close 和 hide-to-tray 两条路径均在窗口销毁前落盘。Fix #326.
改动范围
主要文件
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.rs—CloseRequested处理中显式保存窗口状态验证
pnpm -C apps run testpnpm -C apps run buildpnpm -C apps run test:uicargo test --workspace已执行的验证:
未执行的验证与原因:
风险与影响面
app_config_dir(Windows 为%APPDATA%),首次升级后无历史状态文件,行为与之前一致(使用tauri.conf.json默认值),无破坏性变更。StateFlags::all()同时保存 maximized/fullscreen 状态;如需仅保存 position + size 可收窄为StateFlags::SIZE | StateFlags::POSITION。备注