Skip to content

feat(tauri): persist window size/position/maximized state under AppData with monitor clamping - #4

Draft
crazyrob425 with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-window-state-persistence
Draft

crazyrob425 with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-window-state-persistence

Conversation

Copilot AI commented Mar 26, 2026

Copy link
Copy Markdown

Tauri v2 wrapper had no window state persistence — every launch reopened at the default size/position with no memory of the previous session. Adds full save/restore of window geometry and maximized state stored under the OS app_data_dir, with off-screen clamping on restore.

Changes

src-tauri/src/lib.rs

  • WindowState — serialisable struct (x, y, width, height, maximized); defaults to 1200×800 at (100, 100)
  • Load on startup — reads window-state.json from app_data_dir; silently falls back to defaults on first run or corrupt file
  • Monitor clamping (clamp_to_monitors) — finds the monitor containing the saved top-left corner (falls back to first monitor); clamps size to monitor bounds and enforces ≥ 50 px title-bar visibility to prevent off-screen windows after display layout changes
  • Apply + show (apply_window_state) — sets size/position, maximises if flagged, then calls window.show() after geometry is applied
  • Debounced persistence (setup_state_persistence) — Arc<Mutex<WindowState>> + mpsc::channel; background thread absorbs rapid move/resize events and flushes after DEBOUNCE_MS (500 ms) of quiet; CloseRequested triggers an immediate synchronous save
// On every Moved/Resized event:
// - update shared state (skip geometry update when maximized)
// - signal the debounce thread
tauri::WindowEvent::Resized(size) => {
    if size.width == 0 || size.height == 0 { return; } // minimised
    let maximized = win.is_maximized().unwrap_or(false);
    let mut s = shared.lock().unwrap();
    s.maximized = maximized;
    if !maximized { s.width = size.width; s.height = size.height; }
    let _ = tx.send(());
}

src-tauri/tauri.conf.json

  • "visible": false on the main window — prevents the position-flicker that would occur if the window appeared at the default position before Rust applies the restored geometry
  • Default dimensions updated to 1200×800

README.md

  • New AppData Storage (Desktop) section documents window-state.json paths on Windows (%APPDATA%\com.tauri.dev\), macOS, and Linux, and describes restore/maximized/clamping/debounce behaviour
Original prompt

In crazyrob425/KDP-E-Book-Generator (ref main), ensure the Tauri v2 wrapper persists window size/position and maximized state on Windows, stores the window state and all app data under the OS AppData directory, and clamps/restores window bounds to the current monitor work area so it never opens off-screen. Implement minimal Rust changes using Tauri v2 APIs: load state on startup and apply to main window; listen to window move/resize/maximize/unmaximize events with debounce and save state to a JSON settings file in app_data_dir. Update README to document AppData paths and behavior. Open a PR targeting main.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: @copilot Accepted Confirmation: Are you sure?

Assistant: GitHub is just where the code lives. Building a Tauri desktop app can’t happen “inside GitHub” by itself—you need either:

  1. a computer (yours) to run the build commands, or
  2. a GitHub Actions workflow that runs those build commands on GitHub’s build machines and gives you a downloadable installer as an artifact.

Right now I can’t directly push the Tauri wrapper into your blacklistedrob-prog/KDP-E-Book-Generator repo from this chat (GitHub is blocking write access for this session), so I can’t “just do it” in-place for you yet.

Two paths forward (pick one)

Path A (no local setup): GitHub Actions builds the Windows installer for you

This is the closest to what you want: you click “Run workflow” (or push a commit) and GitHub produces a .msi installer you download.

To do that, we still need one of these:

  • I need write access to your repo so I can add the workflow + Tauri wrapper, or
  • you (or someone with repo write access) adds a small set of files once (Tauri wrapper + the workflow YAML). After that, it’s all “hosted on GitHub” builds.

Path B (local once): you generate the wrapper with one command, then everything else can be GitHub-built

You’d do one local step to create the wrapper; then we add Actions and you never build locally again.

Quick questions (so I give you the exact minimal-click instructions)

  1. Do you have a Windows PC available at all (yes/no)?
  2. Do you have Git installed (yes/no/unsure)?
  3. In the GitHub repo page, do you see a tab called “Actions” (yes/no)?

If you answer those, I’ll tell you the lowest-effort route and exactly what to click/do—aiming for “one-time setup, then GitHub builds the installer forever.”

User: can you fork the repo and do it??

Assistant: We’re waiting for your response to the “Are you sure?” confirmation dialog so I can proceed with forking Blacklisted-Binary/demo-repository and applying the Tauri + SQLite + Windows CI changes in the fork.

User: @copilot Accepted Confirmation: Are you sure?

Assistant: Yes—forking is a good workaround if you can’t (or don’t want to) fight the permission issue on the original repo.

What I can do vs. what I can’t do

  • I can implement the Tauri wrapper + SQLite backend + Windows GitHub Actions build pipeline in a fork so you get a working version you can download installers from.
  • I cannot directly fork/push into blacklistedrob-prog/KDP-E-Book-Generator from here right now because this session doesn’t have the necessary write privileges on that repo, and forking itself may also be blocked depending on what GitHub allows the integration to do in your account.

If forking is available on your side, this is the fastest path

You do one click:

  1. Go to blacklistedrob-prog/KDP-E-Book-Generator
  2. Click Fork
  3. After it creates crazyrob425/KDP-E-Book-Generator (or whatever name you pick), send me the fork repo name.

Then I can work against the fork and you’ll get:

  • src-tauri/ recreated
  • Rust-only commands + progress events
  • SQLite (bundled) initialized on app start (no UI)
  • GitHub Actions workflow that builds Windows MSI and uploads it as an artifact
  • README instructions: “download artifact → install → run”

What I need from you

Reply with either:

  • A) “I forked it: crazyrob425/KDP-E-Book-Generator” (best), or
  • B) “I can’t fork because ____” (error message / restriction)

Once you give me the fork repo path, I’ll proceed with the full rebuild there and keep it as close as possible to your current project structure and vibe.

User: i forked it: crazyrob425/KDP-E-Book-Generator

Assistant: I’ve started the Copilot coding agent work on your fork crazyrob425/KDP-E-Book-Generator to add the full Tauri v2 wrapper, Rust-only SQLite backend, job progress events, and a Windows MSI GitHub Actions build workflow; you can track progress at the task link below.

data:
  - title: "[WIP] Add Tauri v2 wrapper + Rust SQLite backend + Windows MSI CI workflow"
    repository: "crazyrob425/KDP-E-Book-Generator"
    url: https://github.com/copilot/tasks/pull/PR_kwDORrTYZM7N3TMP?session_id=e90b41bf-e178-49ad-b8df-4693713808ef
    state:...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.

Copilot AI changed the title [WIP] Ensure Tauri v2 wrapper persists window state on Windows feat(tauri): persist window size/position/maximized state under AppData with monitor clamping Mar 26, 2026
Copilot AI requested a review from crazyrob425 March 26, 2026 21:44
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