Skip to content

Hand window-state its displays and a narrow window (#120) - #129

Merged
shovon merged 1 commit into
mainfrom
worktree-issue-120
Oct 28, 2026
Merged

shovon merged 1 commit into
mainfrom
worktree-issue-120

Conversation

@shovon

@shovon shovon commented Oct 28, 2026

Copy link
Copy Markdown
Owner

Closes #120.

What changed

window-state (app/src/main/features/window-state/window-state.ts) no longer imports anything from electron:

  • Displays: createWindowState(db, workAreaFor) takes a WorkAreaFor: the work area of the display a saved rectangle is on, or of the primary display for none. This replaces the module-level import { screen }.
  • The window: trackWindowState(window) takes a TrackedWindow, which has the five events it listens to (resize, move, maximize, unmaximize, close, one overload each) and the four getters it reads (isDestroyed, isFullScreen, isMaximized, getNormalBounds). A BrowserWindow is one as it is, and typecheck confirms it at the call in index.ts.
  • Rectangle from Electron gives way to the Rect already in window-bounds.ts. The save delay is a named constant (SAVE_AFTER_MS, 400 ms, unchanged).

index.ts builds workAreaFor from screen.getDisplayMatching and screen.getPrimaryDisplay once the app is ready, and passes it in.

app/CLAUDE.md lists the displays with the other I/O made at the root, and names the new signature and the two interfaces.

For the reviewer

  • No behaviour changes are intended. The debounce keeps its own setTimeout, like the ledger's timers, and the tests drive it with node:test's mock timers rather than an injected clock.
  • workAreaFor receives the saved row with its maximized flag too, as screen.getDisplayMatching did before. The extra field is harmless.
  • The bounds and the flag are now copied field by field when saved and read, rather than spread. A window or a row that carries more fields than x, y, width, height and maximized no longer passes them on.

Tests

  • window-state.test.ts (5 tests, new), over an in-memory database, a fake display lookup that records what it was asked, and a fake window that fires the events a test asks for:
    • the default size with nothing saved, on the primary display
    • a window coming back where it was, maximized flag and all, with the display looked up for the saved rectangle
    • a run of moves and resizes saved once it settles, and not before
    • close saving at once with a save still waiting, and that waiting save never running
    • fullscreen never saved, and neither is a window that is already gone
  • End to end, in a scratch instance (its own --user-data-dir), driven in the main process through --inspect-electron:
    • setBounds to 150, 100, 1000×700: saved after the debounce
    • maximize(), then close() at once: the row kept the normal bounds and set maximized
    • after a relaunch, the window opened maximized, and unmaximize() returned it to 150, 100, 1000×700
  • npm test (201 tests across all workspaces), npm run typecheck and npm run lint pass.

🤖 Generated with Claude Code

window-state.ts did two jobs, keeping the window's bounds in the
window_state table and tracking a live BrowserWindow, and it imported
Electron's screen at module level to pick a display. That kept the whole
module out of node --test: reading the saved row back, choosing the
display, and the save rules (normal bounds rather than maximized ones,
never fullscreen, close saving at once) had no test.

createWindowState now takes workAreaFor beside the database: the work area
of the display a saved rectangle is on, or of the primary display for none.
index.ts builds it from screen once the app is ready. trackWindowState takes
a TrackedWindow, the five events and four getters it uses, which a
BrowserWindow is as it is. The module imports nothing from electron.

No behaviour changes. The debounce keeps its own timer; the tests drive it
with node:test's mock timers.

The new tests cover the default size with nothing saved, a window coming
back where it was with its maximized flag on the display it was on, a run
of moves and resizes saved once it settles, close saving at once and the
waiting save never running, and fullscreen or a destroyed window never
being saved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shovon
shovon merged commit e714afd into main Oct 28, 2026
1 check passed
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.

Split window-state's saved bounds from its live window tracking

1 participant