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 Copilot and Anemy 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
Preview

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
Preview

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
Preview

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.

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