Skip to content

[WIP] Implement and adjust Tauri v2 window restore logic on Windows#6

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/implement-tauri-window-restore-logic
Draft

[WIP] Implement and adjust Tauri v2 window restore logic on Windows#6
Copilot wants to merge 2 commits into
mainfrom
copilot/implement-tauri-window-restore-logic

Conversation

Copilot AI commented Mar 26, 2026

Copy link
Copy Markdown
  • Implement window state persistence in src-tauri/src/lib.rs
    • WindowState struct (x, y, width, height, maximized) with serde support
    • Load/save JSON state file under AppData (%APPDATA%\KDP E-Book Generator\window-state.json)
    • On startup: enumerate monitors, choose monitor (same → top-left contained → primary), shrink-to-fit work area, clamp position, restore bounds, maximize if needed
    • Debounced save on Moved / Resized window events (500 ms debounce)
  • Update src-tauri/Cargo.toml if needed (no new deps expected)
  • Update README.md to document window state persistence behavior and AppData path
  • Verify Rust build compiles cleanly
Original prompt

In crazyrob425/KDP-E-Book-Generator (ref main), implement and/or adjust the Tauri v2 window restore logic on Windows so that when restoring saved window bounds, the app will shrink the window if the saved width/height exceed the chosen monitor's work area (rather than only shifting/clamping position). Behavior requirements:

  • Persist window state (x, y, width, height, maximized) under AppData in a JSON settings file.
  • On startup, restore onto the same monitor if available; otherwise choose a monitor that contains the saved top-left corner; else fallback to primary.
  • Compute the chosen monitor work area; if saved size is larger than work area, shrink width/height to fit within the work area (optionally with a small margin).
  • Then clamp x/y so the window rectangle is entirely within the work area.
  • If maximized was saved, restore normal bounds first (sane, shrunk/clamped), then maximize.
  • Debounce saves on move/resize/maximize/unmaximize.
  • Update README to document the shrink+clamp behavior and AppData path.

Deliverable: open/update a PR against main with these changes and any tests or logging needed to validate behavior on Windows.

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

User: @copilot Accepted Confirmation: Are you sure?

Assistant: I’m proceeding on your fork and kicking off the work to add the Tauri v2 wrapper + Rust SQLite backend + Windows MSI GitHub Actions build. You can track it here:

data:
    - title: '[WIP] Add full Tauri v2 desktop wrapper to KDP-E-Book-Generator'
      repository: crazyrob425/KDP-E-Book-Generator
      url: https://github.com/copilot/tasks/pull/PR_kwDOQrzIB87N3Wq8?session_id=c1184aff-4831-4ecb-a697-e79461fa6cb9
      state: queued

While that runs, if you want the result to feel exactly like your current app on Windows, tell me two preferences (one line is fine):

  1. Window behavior: remember size/position (yes/no)
  2. Data location: keep everything in %AppData% (default) or a folder next to the project files

User: yes, in appdata

Assistant: Waiting on your response in the confirmation dialog to continue updating the in-progress PR with Windows window state persistence and AppData-based storage.

User: @copilot Accepted Confirmation: Are you sure?

Assistant: Got it: persist window size/position = yes, and store everything under AppData.

I can’t apply more repo changes from this message (I’m temporarily unable to run the repo-update automation right now), but here’s exactly what will be done in the PR so you know it’s handled correctly:

  • Window state persistence (Windows): save the window’s size/position on move/resize, write it to a small settings file under the app’s AppData directory, and restore it on next launch.
  • AppData storage: keep the SQLite DB (and any caches/export temp files) under the OS-provided app data directory (e.g., %AppData%\\Binary Books E-Crafter\\... or the Tauri app data path), not next to your project files.

If you want me to match your preference precisely, confirm one detail:

  • When restoring, should it clamp to the current monitor bounds (so it never opens off-screen after you change monitors)? yes/no

User: yes

Assistant: Window-state persistence (with off-screen clamping) + AppData-only storage is now queued to be implemented on crazyrob425/KDP-E-Book-Generator (base main) as minimal Rust/Tauri changes, with a README note about the AppData location.

User: @copilot Accepted Confirmation: Are you sure?

Assistant: Yes—got it.

The plan is:

  • Persist window size + position on every resize/move (with a small debounce so it doesn’t spam disk).
  • Save it under AppData (same place as the SQLite DB and other app state).
  • On launch, restore the saved bounds but clamp to the current monitor/work-area so it can’t reopen off-screen after monitor/layout changes.

I can’t make repo changes from this message (I don’t have write automation available in this exact turn), but that’s the exact behavior that will be implemented in the PR work already in flight. If you want one more preference locked in: should it restore maximized state too (so if you closed it maximized, it reopens maximized)?

User: yes

Assistant: I’m waiting for your response to the tool confirmation dialog so I can continue updating the PR to also persist maximized state (along with size/position) and keep everything stored under AppData with off-screen clamping.

User: @copilot Accepted Confirmation: Are you sure?

Assistant: Yes—maximized state will be persisted too.

What that means in practice (Windows):

  • On close / move / resize / maximize / unmaximize, the app will save window state (x, y, width, height, and isMaximized) to a small JSON file under AppData.
  • On next launch, it will:
    1. read that file,
    2. if isMaximized was true, reopen maximized,
    3. otherwise restore the last bounds **but clamp th...

This pull request was created from Copilot chat.


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Agent-Logs-Url: https://github.com/crazyrob425/KDP-E-Book-Generator/sessions/e4a9eafb-7042-42ee-bd5b-c762d520b258

Co-authored-by: crazyrob425 <247058665+crazyrob425@users.noreply.github.com>
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