Skip to content

Persist and restore desktop window size across launches #22

Description

@badcuban

Priority: P2

User request

When the user closes BadCode after resizing the desktop app window, the next launch should reopen at the same size.

Current test result

A quick packaged-app test on May 26, 2026 showed the basic persist/restore path working: resizing the desktop window, closing BadCode, and reopening restored the window size.

However, there is still a maximized-window edge case:

  • Maximize the desktop window.
  • Close BadCode while maximized.
  • Reopen BadCode. It reopens maximized as expected.
  • Click the maximize/restore button again.
  • Instead of returning to the previous smaller restored size, the window restores to a nearly full-screen normal window.

This suggests closing while maximized may be overwriting the last normal bounds with maximized/full-screen-sized bounds.

Current code starting points

There appears to already be an intended implementation in apps/desktop/src/window/DesktopWindow.ts:

  • MAIN_WINDOW_STATE_FILE_NAME = window-state.json
  • loadPersistedMainWindowState(...) reads persisted width/height/isMaximized.
  • createWindow(...) applies persisted width and height to the BrowserWindow options.
  • The window close handler calls window.getBounds() and writes width/height/isMaximized.

The likely gap is that window.getBounds() on close can capture maximized bounds. The implementation probably needs to preserve the last normal bounds separately, or avoid replacing normal bounds when window.isMaximized() is true.

Acceptance criteria

  • Resizing the main desktop window and closing the app persists the final window size.
  • Reopening BadCode restores the last valid window size.
  • Maximized windows reopen maximized without losing the last normal restored size.
  • Closing while maximized does not overwrite the last normal bounds with maximized display bounds.
  • After reopening maximized, clicking restore/unmaximize returns to the previous smaller normal window size.
  • Invalid, off-screen, or too-small persisted values fall back safely to defaults/minimums.
  • Add regression coverage for persisted window size restore, close-time save behavior, and the close-while-maximized restore edge case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementRequested improvement or new capability.needs-triageIssue needs maintainer review and initial categorization.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions