Repository navigation
Hand window-state its displays and a narrow window (#120) - #129
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #120.
What changed
window-state (
app/src/main/features/window-state/window-state.ts) no longer imports anything fromelectron:createWindowState(db, workAreaFor)takes aWorkAreaFor: the work area of the display a saved rectangle is on, or of the primary display for none. This replaces the module-levelimport { screen }.trackWindowState(window)takes aTrackedWindow, 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). ABrowserWindowis one as it is, and typecheck confirms it at the call inindex.ts.Rectanglefrom Electron gives way to theRectalready inwindow-bounds.ts. The save delay is a named constant (SAVE_AFTER_MS, 400 ms, unchanged).index.tsbuildsworkAreaForfromscreen.getDisplayMatchingandscreen.getPrimaryDisplayonce the app is ready, and passes it in.app/CLAUDE.mdlists the displays with the other I/O made at the root, and names the new signature and the two interfaces.For the reviewer
setTimeout, like the ledger's timers, and the tests drive it withnode:test's mock timers rather than an injected clock.workAreaForreceives the saved row with itsmaximizedflag too, asscreen.getDisplayMatchingdid before. The extra field is harmless.x,y,width,heightandmaximizedno 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:--user-data-dir), driven in the main process through--inspect-electron:setBoundsto 150, 100, 1000×700: saved after the debouncemaximize(), thenclose()at once: the row kept the normal bounds and setmaximizedunmaximize()returned it to 150, 100, 1000×700npm test(201 tests across all workspaces),npm run typecheckandnpm run lintpass.🤖 Generated with Claude Code