Skip to content

feat: enforce unique window names across BaseWindow and BrowserWindow #47764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 12, 2025

Conversation

nilayarya
Copy link
Contributor

@nilayarya nilayarya commented Jul 15, 2025

Description of Change

Note

This PR is part of GSoC 2025 [project] [rfc]

This PR adds validation to ensure BaseWindow and BrowserWindow instances cannot be created with duplicate names.

Checklist

Release Notes

Notes: Added validation to ensure BaseWindow and BrowserWindow instances have unique names.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened recently label Jul 15, 2025
@nilayarya nilayarya changed the title Unique name feat: enforce unique window names across BaseWindow and BrowserWindow Jul 15, 2025
@nilayarya nilayarya marked this pull request as draft July 15, 2025 22:48
@nilayarya nilayarya marked this pull request as ready for review July 16, 2025 01:47
@nilayarya nilayarya requested review from a team as code owners July 16, 2025 14:16
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Hello @nilayarya! It looks like this pull request touches one of our dependency files, and per our contribution policy we do not accept these types of changes in PRs.

@nilayarya nilayarya marked this pull request as draft July 16, 2025 14:18
@georgexu99 georgexu99 force-pushed the unique-name branch 2 times, most recently from 49dc185 to 86d3436 Compare July 16, 2025 16:21
@nilayarya nilayarya marked this pull request as ready for review July 16, 2025 16:26
@georgexu99 georgexu99 added no-backport GSoC 2025 Google Summer of Code 2025 backport-check-skip Skip trop's backport validity checking labels Jul 16, 2025
@electron-cation electron-cation bot added new-pr 🌱 PR opened recently and removed new-pr 🌱 PR opened recently labels Jul 16, 2025
@georgexu99 georgexu99 added the semver/minor backwards-compatible functionality label Jul 17, 2025
@dsanders11 dsanders11 removed request for a team July 23, 2025 15:54
* feat: save/restore window state

* cleanup

* remove constructor option

* refactor: apply suggestions from code review

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: forward declare prefservice

* refactor: remove constructor option

* refactor: save window state on move/resize instead of moved/resized

* feat: resave window state after construction

* test: add basic window save tests

* test: add work area tests

* test: asynchronous batching behavior

* docs: add windowStateRestoreOptions to BaseWindowConstructorOptions

* chore: move includes to main block

* Update spec/api-browser-window-spec.ts

Co-authored-by: David Sanders <dsanders11@ucsbalum.com>

* docs: update docs/api/structures/base-window-options.md

Co-authored-by: Erick Zhao <erick@hotmail.ca>

* fix: preserve original bounds during window state save in special modes

* feat: save kiosk state in window preferences

* chore: remove ts-expect-error

* test: check hasCapturableScreen before running tests

* test: remove multimonitor tests

* test: add missing hasCapturableScreen checks before tests

* docs: add blurb on saving mechanism

* feat: add debounce window of 200ms to saveWindowState

* docs: remove blurb until finalized

* style: convert constants from snake_case to camelCase

* refactor: initialize prefs_ only if window state is configured to be saved/restored

* refactor: rename window states key

* refactor: store in application-level Local State instead of browser context

* refactor: switch to more accurate function names

* fix: add dcheck for browser_process

* fix: flush window state to avoid race condition

* refactor: change stateId to name

* refactor: change windowStateRestoreOptions to windowStatePersistence

* Update docs/api/structures/base-window-options.md

Co-authored-by: David Sanders <dsanders11@ucsbalum.com>

* fix: add warning when window state persistence enabled without window name

* docs: lowercase capital B for consistency

---------

Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: David Sanders <dsanders11@ucsbalum.com>
Co-authored-by: Erick Zhao <erick@hotmail.ca>
@nilayarya
Copy link
Contributor Author

Copy link
Member

@erickzhao erickzhao left a comment

Choose a reason for hiding this comment

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

API LGTM

@erickzhao erickzhao added the api-review/skip-delay ⏰ Skip the mandatory 7 day waiting period for new APIs label Aug 7, 2025
Copy link
Member

@VerteDinde VerteDinde left a comment

Choose a reason for hiding this comment

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

Code changes look good to me! We can merge after API LGTM is done

@@ -42,7 +42,7 @@
Default is `false`.
* `hiddenInMissionControl` boolean (optional) _macOS_ - Whether window should be hidden when the user toggles into mission control.
* `kiosk` boolean (optional) - Whether the window is in kiosk mode. Default is `false`.
* `name` string (optional) - An identifier for the window that enables features such as state persistence.
* `name` string (optional) - A unique identifier for the window, used to enable features such as state persistence. Each window must have a distinct name. It can only be reused after the corresponding window has been destroyed.
Copy link
Member

Choose a reason for hiding this comment

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

Could we call this property something like identifier or key? I suspect the name property will be confusing for developers, who might try to use it in place of title.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe windowKey?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would there be an issue if we used the existing id property? We could allow developers to pass a unique id through the BaseWindowConstructorOptions to enable windowStatePersistence

Copy link
Member

Choose a reason for hiding this comment

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

@nilayarya I think in the interest of keeping the PR moving, let's merge this into the GSoC branch and we can bikeshed on the specific name when we're ready to merge the feature into main. I've made an action item in the channel to follow up.

@VerteDinde VerteDinde merged commit 65345ee into electron:gsoc-2025 Aug 12, 2025
56 checks passed
@release-clerk
Copy link

release-clerk bot commented Aug 12, 2025

Release Notes Persisted

Added validation to ensure BaseWindow and BrowserWindow instances have unique names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-review/skip-delay ⏰ Skip the mandatory 7 day waiting period for new APIs backport-check-skip Skip trop's backport validity checking GSoC 2025 Google Summer of Code 2025 no-backport semver/minor backwards-compatible functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants