feat: 记住并恢复上次的窗口大小/位置#15
Merged
Merged
Conversation
启动时恢复上次 resize 后的窗口尺寸与位置,而非每次都用默认大小。 - windowStateCore.ts:纯函数 resolveWindowBounds,把保存的几何与 当前显示器对账——离屏(拔显示器/改分辨率)时保留尺寸、丢坐标让 系统居中;尺寸 clamp 到 [最小值, 最大显示器];非法值回退默认。 - windowStateStore.ts:持久化到 window-state.json(独立于 settings.json, 纯主进程、不过 IPC,避免频繁抖动渲染层配置)。存 getNormalBounds() + isMaximized,最大化态退出下次先恢复合理尺寸再最大化。 - index.ts:createWindow 读取并恢复;resize/move/maximize 防抖 400ms 持久化,close 同步 flush;写盘失败静默兜底。 - 配套 windowStateCore 单测 9 条。
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.
这是什么
启动应用时恢复上次 resize 后的窗口尺寸与位置,而不是每次都用默认 1440×920。最大化态与原生全屏态也一并记忆、下次启动还原。
改动
src/main/store/windowStateCore.ts(新)resolveWindowBounds——把保存的几何与当前接的显示器对账src/main/store/windowStateStore.ts(新)window-state.json(userData,ADR-0006 纯 JSON)src/main/index.ts(改)createWindow读取并恢复;监听 resize/move/maximize/fullscreen 持久化test/unit/main/windowStateCore.test.ts(新)设计要点
window-state.json,不塞进settings.json:窗口尺寸是纯主进程关注点,每次拖拽都变、永不过 IPC;混进面向渲染层的 settings 会让那个文件频繁抖动。getNormalBounds()(还原态尺寸)+isMaximized/isFullScreen标志:最大化/全屏态下退出,下次先恢复合理尺寸,再最大化或进全屏(二者互斥,全屏优先)。windowStateCore的核心):拔了外接显示器 / 改了分辨率导致窗口落到屏幕外时,保留尺寸、丢坐标让系统居中;尺寸 clamp 到[最小值, 最大显示器];只有非法值(NaN/Infinity/≤0/缺失)才回退默认。close时同步 flush;写盘失败静默兜底,绝不因窗口状态崩溃或阻塞退出。验证
pnpm typecheck✅pnpm test:unit✅(352 passed,含新增 9 条)