Skip to content

Conversation

miya
Copy link
Contributor

@miya miya commented Sep 28, 2025

Description

This PR adds the ability to persist window position, size, and maximized state across application restarts, providing a consistent user experience by restoring the user's preferred window configuration.

Checklist

  • New tests and/or benchmarks are included
  • Documentation is changed or added
  • If this change updates the UI, screenshots/videos are added and a design review is requested
  • I have signed the MongoDB Contributor License Agreement (https://www.mongodb.com/legal/contributor-agreement)

Motivation and Context

  • Bugfix
  • New feature
  • Dependency update
  • Misc

Open Questions

Dependents

Types of changes

  • Backport Needed
  • Patch (non-breaking change which fixes an issue)
  • Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to change)

@miya miya requested a review from a team as a code owner September 28, 2025 05:47
@miya miya requested review from Anemy and Copilot September 28, 2025 05:47
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements window bounds persistence to save and restore the application window's position, size, and maximized state across application restarts, providing a consistent user experience.

  • Adds window bounds persistence functionality with debounced saving to avoid frequent disk writes
  • Integrates window bounds validation to ensure windows remain visible on screen
  • Updates preferences schema to store window bounds configuration

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
packages/compass/src/main/window-manager.ts Implements window bounds persistence logic, validation, and event handlers for saving/restoring window state
packages/compass-preferences-model/src/preferences-schema.tsx Adds windowBounds preference schema with validation for storing window position and state

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 208 to 211
const windowOpts = {
width: Number(DEFAULT_WIDTH),
height: Number(DEFAULT_HEIGHT),
...validatedBounds,
minWidth: Number(MIN_WIDTH),
minHeight: Number(MIN_HEIGHT),
Copy link

Copilot AI Sep 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spread operator ...validatedBounds may override the minWidth and minHeight properties if validatedBounds contains width and height properties with smaller values than the minimums. The spread should come after the min properties to ensure minimums are enforced.

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...validatedBounds has been removed.

Additionally, since the ...bounds return value does not include minWidth and minHeight, they are not overwritten.

Comment on lines 142 to 144
// Ensure minimum size
const width = Math.max(bounds.width, Number(MIN_WIDTH));
const height = Math.max(bounds.height, Number(MIN_HEIGHT));
Copy link

Copilot AI Sep 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The Math.max calls enforce minimum dimensions but this validation is duplicated with the minWidth/minHeight properties set on the BrowserWindow. Consider removing this duplication since Electron will enforce the minimums automatically.

Suggested change
// Ensure minimum size
const width = Math.max(bounds.width, Number(MIN_WIDTH));
const height = Math.max(bounds.height, Number(MIN_HEIGHT));
// Use provided size; Electron will enforce minimums
const width = bounds.width;
const height = bounds.height;

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed: 1b40f27

Comment on lines 275 to 277
if (savedBounds?.isMaximized) {
window.maximize();
}
Copy link

Copilot AI Sep 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The maximized state restoration should happen after the window is shown to avoid potential visual glitches. Consider moving this logic after the showWindowWhenReady(window) call or inside the showWindowWhenReady function.

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed: 65171d9

@miya miya changed the title feat: Window bounds persistence feat: implement window bounds persistence Sep 28, 2025
Copy link
Member

@Anemy Anemy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, thanks for opening the PR! Left two comments/questions.

const windowOpts = {
width: Number(DEFAULT_WIDTH),
height: Number(DEFAULT_HEIGHT),
...bounds,
Copy link
Member

@Anemy Anemy Sep 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does electron gracefully handle if a user tries to open a window that's larger than their screen size or out of bounds of their current screen? I'm wondering if we need to account for situations where a user goes from a larger monitor to a smaller one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are the results I observed on macOS (v15.6.1).
I wasn’t able to test on Windows or Linux since I don’t have access to those machines.

When the window size was larger than the display or even slightly out of bounds, macOS automatically adjusted it.
If the window exceeded the display size, it was resized to fit within the screen.
If it was positioned partially outside the display, it was automatically moved so that the entire window remained visible.

I checked the Electron documentation but couldn’t find any mention of this behavior.
It might be handled by the operating system rather than Electron itself, so if possible, could you also test it on Windows and Linux?

2025-10-06.1.19.03.mov

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows and Linux do same - when its out of bounds, it resizes the app to fit it on the screen.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for testing this! I'm looking forward to the release.

@mabaasit mabaasit changed the title feat: implement window bounds persistence feat: implement window bounds persistence COMPASS-6561 Oct 7, 2025
@miya miya requested review from Anemy and mabaasit October 7, 2025 14:25
@mabaasit
Copy link
Collaborator

mabaasit commented Oct 9, 2025

Looks nice. I approved the CI to run tests. I'll try to check this on Linux and possibly windows.

@mabaasit mabaasit changed the title feat: implement window bounds persistence COMPASS-6561 feat(preferences): implement window bounds persistence COMPASS-6561 Oct 10, 2025
@mabaasit mabaasit merged commit 066b78c into mongodb-js:main Oct 13, 2025
33 of 36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants