Repository navigation
feat(main): add WindowManager.owns() for O(1) ownership checks - #18
Merged
Merged
Conversation
Consumers that filter app-level events (browser-window-focus, will-navigate, etc.) by "is this one of the window manager's windows?" currently scan getAllWindows().some(w => w.window === win) per event. Add owns() backed by a WeakSet maintained at every register/unregister site so the check is O(1). Also extract addManagedWindow/removeManagedWindow helpers so the windows map and the WeakSet can never drift, and store the BrowserWindow ref in the map entry so removal works after the WindowInstance has been destroyed (its .window getter is null by then).
loc
force-pushed
the
claude/owns-window-check
branch
from
May 12, 2026 22:22
332b6dd to
962d2bc
Compare
|
🎉 This PR is included in version 1.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
Demo
N/A — main-process API addition, no UI. Behavior is fully covered by the new unit tests.
Summary
Consumers that filter app-level events (
browser-window-focus,-blur,will-navigate) by "is this BrowserWindow one of the manager's?" currently scan:per event. That's O(n) per focus/blur tick and re-implements the optional-chain dance for the no-manager case at every callsite.
This PR adds
windowManager.owns(win: BrowserWindow): boolean, backed by aWeakSet<BrowserWindow>maintained on every register/unregister path so it's O(1). It also extractsaddManagedWindow/removeManagedWindowprivate helpers so thewindowsmap and theWeakSetcan never drift, and stores theBrowserWindowref in the map entry so removal works after theWindowInstancehas been destroyed (instance.windowisnullby then).Stack
This is 1 of 4 stacked PRs absorbing consumer workarounds:
owns()(this PR)prepareForQuit()— quit-veto cleanupchildWindowOpenHandler/onChildWindowCreatedreapOnOwnerNavigateTests
6 new unit tests covering true/false across all lifecycle exits (DestroyWindow, UnregisterWindow, parent destroyed, manager.destroy()).