Skip to content

fix(desktop): restore maximized main window state on startup - #2435

Merged
wsp1911 merged 2 commits into
GCWing:1.0.0-explorefrom
YodonTan:fix/restore-maximized-window-state
Aug 24, 2026
Merged

fix(desktop): restore maximized main window state on startup#2435
wsp1911 merged 2 commits into
GCWing:1.0.0-explorefrom
YodonTan:fix/restore-maximized-window-state

Conversation

@YodonTan

Copy link
Copy Markdown

Problem

BitFun did not remember the main window geometry on startup: after quitting while maximized, the next launch reopened the near-fullscreen frameless window without the maximized state (or, in one revision, relocated off-screen). Windows only.

Root cause

Two layers conspired for undecorated main windows (decorations(false) on Windows):

  1. A maximized frameless window could be persisted by tauri-plugin-window-state as maximized: false with its stretched maximized frame stored as normal bounds. Every launch faithfully restored that degenerate near-fullscreen normal window, so the perceived "fixed startup geometry" self-perpetuated.
  2. Maximizing while the window is hidden is unreliable on Windows: the zoomed state is dropped on show(), and the window falls back to Windows' tracked normal-placement rect, which for a maximized undecorated window is not trustworthy (observed blending the pre-restore centered origin with monitor-sized dimensions).

Fix

  • After every explicit save the persisted main entry is corrected against the authoritative GetWindowPlacement signal: when the window is genuinely maximized the entry is marked maximized: true. Geometry fields are deliberately never rewritten from rcNormalPosition.
  • The restore path no longer maximizes during the hidden phase; the persisted maximized flag is re-asserted after the window becomes visible.
  • Save call sites now carry a reason string for failure diagnostics; failure paths log with the reason.

Verification

  • New unit tests in src/apps/desktop/src/window_state_support.rs cover flag-only correction, idempotency, non-maximized no-ops, legacy/partial entries, and file round-trips (invalid files are kept untouched).
  • Existing main_window_geometry_tests and the Web UI startup performance contract test still pass.
  • Verified by manual testing on Windows: quit while maximized -> next launch starts maximized; windowed exit -> geometry remembered.

@wsp1911
wsp1911 changed the base branch from main to 1.0.0-explore August 24, 2026 02:58
The tauri plugin window-state flow already persists the main window
geometry, but a maximized undecorated window was saved as
maximized:false together with its stretched frame stored as normal
bounds. Every launch then restored that degenerate near-fullscreen
normal window instead of the remembered geometry.

Fix both sides on Windows:

- After each explicit save, treat GetWindowPlacement as the
  authoritative maximized signal and flip the persisted flag when it
  disagrees. Geometry fields are never rewritten from the placement:
  rcNormalPosition is unreliable for maximized undecorated windows and
  previously blended the pre-restore centered origin with monitor-sized
  dimensions, which moved the restored window off-screen.
- Skip maximizing during the hidden restore phase and re-assert the
  persisted maximized flag after the window becomes visible, because
  maximizing a hidden undecorated window is dropped on show.

Save call sites now carry a reason for failure diagnostics.
@wsp1911
wsp1911 force-pushed the fix/restore-maximized-window-state branch from ec076a7 to 8854a45 Compare August 24, 2026 03:04
A maximized frameless main window could be persisted with stretched normal bounds or lose its maximized flag during startup geometry repair. The correction path also replaced the state file by deleting the existing file first and assumed the plugin's default filename.

Keep the persisted state reliable across startup and explicit save boundaries:

- Separate full-state saves from geometry-only saves so startup size repair cannot overwrite maximized.

- Defer maximized restoration only on Windows, where maximizing a hidden undecorated window is not reliable.

- Resolve the state path through tauri-plugin-window-state's filename API.

- Replace the state file atomically with ReplaceFileW and write-through semantics on Windows, and rename it atomically on other platforms.

- Add regression coverage for replacement failures, preserved state, and platform-specific state flags.

Validation: cargo check -p bitfun-desktop; cargo build -p bitfun-desktop; git diff --check.

Refs: GCWing#2435
@wsp1911
wsp1911 force-pushed the fix/restore-maximized-window-state branch from db1247c to 9c7274f Compare August 24, 2026 03:33
@wsp1911
wsp1911 merged commit 92bbbd2 into GCWing:1.0.0-explore Aug 24, 2026
8 checks passed
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.

2 participants