Desktop: Fixes #14861: Restore window position and size after relaunch on Windows#15003
Desktop: Fixes #14861: Restore window position and size after relaunch on Windows#15003gagansokhal-coder wants to merge 1 commit intolaurent22:devfrom
Conversation
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdded Windows-specific window state persistence logic to Changes
Suggested labels
Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error)
✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
I have read the CLA Document and I hereby sign the CLA |
|
recheck |
| this.win_.on('close', () => { | ||
| // Cancel any pending debounced save and do a final immediate save | ||
| if (snapSaveTimer) { | ||
| clearTimeout(snapSaveTimer); | ||
| snapSaveTimer = null; | ||
| } | ||
| try { | ||
| if (this.win_ && !this.win_.isDestroyed()) { | ||
| windowState.saveState(this.win_); | ||
| } | ||
| } catch (_e) { | ||
| // Window may have been destroyed | ||
| } | ||
| }); |
There was a problem hiding this comment.
This ensures that the final window position and size are saved when the app is closed.
Without this, when the window is snapped (e.g using Win + Arrow keys) the last updated bounds may not be persisted correctly because the debounced save might not execute before the app closes.
By handling the 'close' event, we cancel any pending debounced save and immediately persist the latest window state, ensuring the correct snapped position is restored on next launch.
There was a problem hiding this comment.
Without this, when the window is snapped (e.g using Win + Arrow keys) the last updated bounds may not be persisted correctly because the debounced save might not execute before the app closes.
"may not be" - under what condition that can happen?
There was a problem hiding this comment.
This can happen when the window state is updated shortly before the app is closed, while the debounced save is still pending.
For example, when the user snaps the window (Win + Arrow keys), a resize/move event triggers the debounced save. If the user immediately closes the app before the debounce delay completes, the pending save may not run, so the latest bounds are not persisted.
In that case, the previously saved window state (before snapping) would be restored on the next launch instead of the snapped position.
There was a problem hiding this comment.
You mean if the user resize then close the window within 1 second? is it worth the extra code?
There was a problem hiding this comment.
You're right that this scenario happens only when the window is resized or snapped and then closed very quickly.
I added this to ensure consistency, especially for snap behavior, since users might expect the last visible state to always be restored.
However, I agree that if this is considered too edge-case or adds unnecessary complexity, we can simplify the approach or rely on the existing debounced save.
Happy to adjust or remove this part based on your preference.
Fixes #14861
Problem
On Windows, when the Joplin window is snapped (docked) to the left or right, closing and reopening the app resets the window position and size.
Solution
Ensured that the correct window bounds are saved after snap by handling resize and move events and persisting final bounds.
Testing
Tested the following scenarios:
All cases correctly restore position and size after relaunch.
Notes
This change focuses on Windows behavior and does not affect macOS/Linux.