Skip to content

feat: add window state persistence with settings toggle#47

Merged
j4rviscmd merged 1 commit intomainfrom
feat/window-state
Mar 25, 2026
Merged

feat: add window state persistence with settings toggle#47
j4rviscmd merged 1 commit intomainfrom
feat/window-state

Conversation

@j4rviscmd
Copy link
Copy Markdown
Owner

Summary

Add window position and size persistence using tauri-plugin-window-state.

The plugin always saves window state on close, but restoration is controlled by a toggle in the Settings dialog (default: ON). When disabled, the app opens with the default 1200×800 centered window.

Changes

Backend (Rust)

  • Add tauri-plugin-window-state dependency
  • Register plugin with skip_initial_state("main") to defer restore to frontend
  • Configure StateFlags::POSITION | StateFlags::SIZE (excludes maximized/fullscreen)
  • Add window-state:default capability permission

Frontend (TypeScript/React)

  • Add @tauri-apps/plugin-window-state dependency
  • Pre-fetch toggle value in store-provider.tsx initPromise (no visual flash)
  • Conditionally call restoreStateCurrent() with try-catch for error resilience
  • Add WindowStateOption switch component in Settings dialog
  • Add useWindowState hook following existing toggle pattern
  • Export constants and hook via public API (index.ts)

Architecture

Uses Option A: Plugin + skip_initial_state approach:

  1. Plugin auto-saves on window close (always)
  2. skip_initial_state prevents auto-restore on startup
  3. Frontend checks toggle → calls restoreStateCurrent() before React renders
  4. No visual flash since restoration happens in initPromise (before Suspense resolves)

Add tauri-plugin-window-state to save and restore window position and
size across app restarts. The plugin always saves state on close, but
restoration is controlled by a toggle in Settings.

- Register window-state plugin with skip_initial_state to defer restore
- Add StateFlags::POSITION | SIZE for selective state tracking
- Pre-fetch toggle value in store-provider initPromise (no visual flash)
- Add WindowStateOption switch component in Settings dialog
- Default: restore enabled (ON)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@j4rviscmd j4rviscmd added the enhancement New feature or request label Mar 25, 2026
@j4rviscmd j4rviscmd merged commit eae6b3b into main Mar 25, 2026
@j4rviscmd j4rviscmd deleted the feat/window-state branch March 25, 2026 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant