Skip to content

Restore the window size/position reliably and stop auto-starting fullscreen#34000

Open
hayaksi1 wants to merge 1 commit into
element-hq:developfrom
hayaksi1:pr/desktop-window-geometry
Open

Restore the window size/position reliably and stop auto-starting fullscreen#34000
hayaksi1 wants to merge 1 commit into
element-hq:developfrom
hayaksi1:pr/desktop-window-geometry

Conversation

@hayaksi1

Copy link
Copy Markdown
Contributor

Problem

The desktop window did not reliably restore its previous size and position, and could relaunch
into fullscreen even when the user had left it windowed (#32228, #32360). This was handled by
the unmaintained electron-window-state package, which persists to its own JSON file and re-applies
a stored fullscreen rectangle on launch.

Fix

Replace electron-window-state with an in-repo WindowStateManager:

  • Persists size / position / maximized state durably through the existing electron-store-backed
    Store (atomic, alongside the rest of the app's state) instead of a separate JSON file.
  • Clamps restored bounds to the displays currently connected, so a window stranded on a
    now-disconnected monitor falls back to sensible defaults instead of opening off-screen.
  • Deliberately never restores fullscreen (only the last normal rectangle is persisted), so the
    app never auto-starts fullscreen (Riot always starts in full screen #32360).
  • Flushes geometry on close and before app.exit() — including the macOS hide-on-close path where
    closed never fires — and debounces high-frequency resize/move events.

This drops the electron-window-state dependency.

Tests

window-state.test.ts (Vitest, 43 passing) covers bounds persistence, restore + display clamping
(including disconnected-monitor fallback), the maximized round-trip, the no-fullscreen rule, and the
debounce/flush behaviour.

Fixes #32228
Fixes #32360

Notes: Reliably restores the desktop window's size/position/maximized state (clamped to connected displays) and no longer auto-starts fullscreen, replacing the unmaintained electron-window-state package.

Checklist

…screen

The desktop window did not reliably restore its previous size and position, and could
relaunch into fullscreen even when the user had left it windowed (element-hq#32228, element-hq#32360).
That was handled by the unmaintained electron-window-state package, which persists to
its own JSON file and re-applies a stored fullscreen rectangle on launch.

Replace it with an in-repo WindowStateManager that persists size/position/maximized
state durably through the existing electron-store-backed Store, clamps restored bounds
to the displays currently connected (so a window stranded on a now-disconnected monitor
falls back to defaults), and deliberately never restores fullscreen. Geometry is flushed
on close and before exit — including the macOS hide-on-close path where `closed` never
fires — and high-frequency resize/move events are debounced.

Drops the electron-window-state dependency.
@hayaksi1 hayaksi1 requested review from a team as code owners June 27, 2026 07:42
@hayaksi1 hayaksi1 requested review from dbkr and florianduros June 27, 2026 07:42
@github-actions github-actions Bot added the Z-Community-PR Issue is solved by a community member's PR label Jun 27, 2026
mainWindowState.manage(global.mainWindow);

// Now the window exists, restore the maximized state and start tracking changes. Fullscreen
// is deliberately not restored so the app never auto-starts fullscreen (#32360).

@t3chguy t3chguy Jun 29, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure about this change, I always use Element full screen on my mac so having to re-maximise it on every restart/update would not be ideal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-Defect Z-Community-PR Issue is solved by a community member's PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Riot always starts in full screen Element desktop should remember window size after a restart

2 participants