Repository navigation
fix(window): 记住窗口大小和位置,重启后不再回到默认尺寸 - #110
Merged
std-microblock merged 1 commit intoNov 30, 2026
Merged
std-microblock merged 1 commit into
std-microblock merged 1 commit into
Conversation
之前窗口几何完全没有保存:tauri.conf.json 里写死 1100x900,每次启动都是这个 尺寸,也没有任何地方在关闭时记录尺寸、位置或最大化状态,所以用户调过的窗口 一关就丢。 接上官方 tauri-plugin-window-state,只恢复尺寸、位置和最大化三项,可见性与 窗口边框仍由程序自己控制。插件在窗口关闭和进程退出时落盘,下次启动时恢复; 位置只在与现有显示器相交时才套用,拔掉副屏后窗口不会被放到屏幕外。 macOS / Windows / Linux 都生效;Wayland 下位置由合成器决定,只有尺寸能恢复。
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.
现象
1.3.1 里调过窗口大小和位置,关掉再开又回到 1100x900 的默认尺寸,位置也回到居中。
原因
窗口几何从来没存过:
tauri.conf.json里写死width: 1100 / height: 900,代码里既没有保存关闭时的尺寸和位置,也没有window-state之类的插件,前端只用到了 drop 安装需要的那几个窗口 API。所以每次启动都是配置里的默认值,与 1.3.1 具体版本无关。修改
接上官方
tauri-plugin-window-state,只恢复 SIZE / POSITION / MAXIMIZED 三项(可见性、边框仍由程序自己控制):插件在窗口关闭和进程退出时把状态写进 app config 目录(Windows 是
%APPDATA%\com.celemod.desktop\.window-state.json),下次启动在窗口就绪时恢复;位置只在与当前某台显示器相交时才套用,拔掉副屏后窗口不会被丢到屏幕外。依赖只加在桌面三个平台上,Android 构建不受影响。验证
Xvfb + openbox 下跑真机二进制,用
xdotool改窗口几何再正常关窗,对比修改前后:width=1240, height=830, x=160, y=90最大化也验证过:手工写入
maximized: true的状态文件后启动,窗口直接最大化,关闭后再打开仍是最大化状态。cargo tree --locked、cargo build --locked、cargo fmt --check均通过(CI 用的是--locked,Cargo.lock 已一并更新)。备注
Wayland 下窗口位置由合成器决定,只有尺寸能恢复;X11 / Windows / macOS 三项都能恢复。