Repository navigation
feat: add save/restore window state API - #51510
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
a6c1d36 to
9f6e2d9
Compare
|
EDIT: This doesn't seem to actually depend on macOS-specific persisted state API's. Still confirming on my end, though, to be absolutely sure. EDIT 2: Yeah, I read this incorrectly. It does not use macOS's persisted state. |
* feat: save/restore window state * cleanup * remove constructor option * refactor: apply suggestions from code review Co-authored-by: Charles Kerr <[email protected]> * 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 <[email protected]> * docs: update docs/api/structures/base-window-options.md Co-authored-by: Erick Zhao <[email protected]> * 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 <[email protected]> * fix: add warning when window state persistence enabled without window name * docs: lowercase capital B for consistency --------- Co-authored-by: Charles Kerr <[email protected]> Co-authored-by: David Sanders <[email protected]> Co-authored-by: Erick Zhao <[email protected]>
* test: support for multimonitor tests * fix: update yarn.lock file * test: support any resolution for new displays * test: support display positioning * docs: multi-monitor tests * test: remove dummy test
…#47764) * feat: save window state (#47425) * feat: save/restore window state * cleanup * remove constructor option * refactor: apply suggestions from code review Co-authored-by: Charles Kerr <[email protected]> * 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 <[email protected]> * docs: update docs/api/structures/base-window-options.md Co-authored-by: Erick Zhao <[email protected]> * 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 <[email protected]> * fix: add warning when window state persistence enabled without window name * docs: lowercase capital B for consistency --------- Co-authored-by: Charles Kerr <[email protected]> Co-authored-by: David Sanders <[email protected]> Co-authored-by: Erick Zhao <[email protected]> * feat: enforce unique window names across BaseWindow and BrowserWindow * docs: update docs for name property * fix: linter issue with symbol --------- Co-authored-by: Charles Kerr <[email protected]> Co-authored-by: David Sanders <[email protected]> Co-authored-by: Erick Zhao <[email protected]>
* feat: save window state (#47425) * feat: save/restore window state * cleanup * remove constructor option * refactor: apply suggestions from code review Co-authored-by: Charles Kerr <[email protected]> * 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 <[email protected]> * docs: update docs/api/structures/base-window-options.md Co-authored-by: Erick Zhao <[email protected]> * 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 <[email protected]> * fix: add warning when window state persistence enabled without window name * docs: lowercase capital B for consistency --------- Co-authored-by: Charles Kerr <[email protected]> Co-authored-by: David Sanders <[email protected]> Co-authored-by: Erick Zhao <[email protected]> * feat: restore window state * feat: flush display modes on show * refactor: move utility functions to common area * feat: clear window state * fix: wait for the prefs to update * test: clearWindowState extra test * test: refine clear window state tests * test: single monitor restore window tests chore: rebase on gsoc-2025 * refactor: refine clearWindowState test * fix: revert default_app back to original * docs: add comment linking AdjustBoundsToBeVisibleOnDisplay to Chromium code * fix: add correct permalink * refactor: ci friendly * fix: disable windowStatePersistence when no display * refactor: use reference instead pointer * fix: skip window state persistence for invalid/fake displays * refactor: better flag placement * test: add test to verify window state is not saved when no display * fix: restore display mode inside show() * feat: save window state (#47425) * feat: save/restore window state * cleanup * remove constructor option * refactor: apply suggestions from code review Co-authored-by: Charles Kerr <[email protected]> * 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 <[email protected]> * docs: update docs/api/structures/base-window-options.md Co-authored-by: Erick Zhao <[email protected]> * 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 <[email protected]> * fix: add warning when window state persistence enabled without window name * docs: lowercase capital B for consistency --------- Co-authored-by: Charles Kerr <[email protected]> Co-authored-by: David Sanders <[email protected]> Co-authored-by: Erick Zhao <[email protected]> * test: clear sharedUserPath before and test * refactor: hasInvalidDisplay function * debug: add display info logging for CI * fix: do not save/restore when window is 0x0 * test: support for multimonitor tests (#47911) * test: support for multimonitor tests * fix: update yarn.lock file * test: support any resolution for new displays * test: support display positioning * docs: multi-monitor tests * test: remove dummy test * feat: enforce unique window names across BaseWindow and BrowserWindow (#47764) * feat: save window state (#47425) * feat: save/restore window state * cleanup * remove constructor option * refactor: apply suggestions from code review Co-authored-by: Charles Kerr <[email protected]> * 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 <[email protected]> * docs: update docs/api/structures/base-window-options.md Co-authored-by: Erick Zhao <[email protected]> * 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 <[email protected]> * fix: add warning when window state persistence enabled without window name * docs: lowercase capital B for consistency --------- Co-authored-by: Charles Kerr <[email protected]> Co-authored-by: David Sanders <[email protected]> Co-authored-by: Erick Zhao <[email protected]> * feat: enforce unique window names across BaseWindow and BrowserWindow * docs: update docs for name property * fix: linter issue with symbol --------- Co-authored-by: Charles Kerr <[email protected]> Co-authored-by: David Sanders <[email protected]> Co-authored-by: Erick Zhao <[email protected]> * test: remove invalid display test --------- Co-authored-by: Charles Kerr <[email protected]> Co-authored-by: David Sanders <[email protected]> Co-authored-by: Erick Zhao <[email protected]> Co-authored-by: Keeley Hammond <[email protected]>
* feat: save window state (#47425) * feat: save/restore window state * cleanup * remove constructor option * refactor: apply suggestions from code review Co-authored-by: Charles Kerr <[email protected]> * 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 <[email protected]> * docs: update docs/api/structures/base-window-options.md Co-authored-by: Erick Zhao <[email protected]> * 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 <[email protected]> * fix: add warning when window state persistence enabled without window name * docs: lowercase capital B for consistency --------- Co-authored-by: Charles Kerr <[email protected]> Co-authored-by: David Sanders <[email protected]> Co-authored-by: Erick Zhao <[email protected]> * feat: restore window state * feat: flush display modes on show * refactor: move utility functions to common area * feat: clear window state * fix: wait for the prefs to update * test: clearWindowState extra test * test: refine clear window state tests * test: single monitor restore window tests chore: rebase on gsoc-2025 * refactor: refine clearWindowState test * fix: revert default_app back to original * docs: add comment linking AdjustBoundsToBeVisibleOnDisplay to Chromium code * fix: add correct permalink * refactor: ci friendly * fix: disable windowStatePersistence when no display * refactor: use reference instead pointer * fix: skip window state persistence for invalid/fake displays * refactor: better flag placement * test: add test to verify window state is not saved when no display * fix: restore display mode inside show() * feat: support for multimonitor tests * fix: update yarn.lock file * feat: support any resolution for new displays * feat: support display positioning * docs: multi-monitor tests * test: remove dummy test * feat: save window state (#47425) * feat: save/restore window state * cleanup * remove constructor option * refactor: apply suggestions from code review Co-authored-by: Charles Kerr <[email protected]> * 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 <[email protected]> * docs: update docs/api/structures/base-window-options.md Co-authored-by: Erick Zhao <[email protected]> * 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 <[email protected]> * fix: add warning when window state persistence enabled without window name * docs: lowercase capital B for consistency --------- Co-authored-by: Charles Kerr <[email protected]> Co-authored-by: David Sanders <[email protected]> Co-authored-by: Erick Zhao <[email protected]> * test: clear sharedUserPath before and test * refactor: hasInvalidDisplay function * debug: add display info logging for CI * fix: do not save/restore when window is 0x0 * test: support for multimonitor tests (#47911) * test: support for multimonitor tests * fix: update yarn.lock file * test: support any resolution for new displays * test: support display positioning * docs: multi-monitor tests * test: remove dummy test * fix: native-addon forceCleanup * docs: add forceCleanup description * test: add two basic multi-monitor tests * fix: find the closest display for non-overlapping saved bounds * test: windowStatePersistence multi-monitor tests * docs: add note on display APIs in CI * fix: remove duplicate destroy registration * feat: enforce unique window names across BaseWindow and BrowserWindow (#47764) * feat: save window state (#47425) * feat: save/restore window state * cleanup * remove constructor option * refactor: apply suggestions from code review Co-authored-by: Charles Kerr <[email protected]> * 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 <[email protected]> * docs: update docs/api/structures/base-window-options.md Co-authored-by: Erick Zhao <[email protected]> * 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 <[email protected]> * fix: add warning when window state persistence enabled without window name * docs: lowercase capital B for consistency --------- Co-authored-by: Charles Kerr <[email protected]> Co-authored-by: David Sanders <[email protected]> Co-authored-by: Erick Zhao <[email protected]> * feat: enforce unique window names across BaseWindow and BrowserWindow * docs: update docs for name property * fix: linter issue with symbol --------- Co-authored-by: Charles Kerr <[email protected]> Co-authored-by: David Sanders <[email protected]> Co-authored-by: Erick Zhao <[email protected]> * docs: remove inaccurate comment * fix: move expect blocks outside beforeEach * test: exclude macOS-x64 for now * test: remove invalid display test * test: remove invalid display test * feat: save window state (#47425) * feat: save/restore window state * cleanup * remove constructor option * refactor: apply suggestions from code review Co-authored-by: Charles Kerr <[email protected]> * 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 <[email protected]> * docs: update docs/api/structures/base-window-options.md Co-authored-by: Erick Zhao <[email protected]> * 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 <[email protected]> * fix: add warning when window state persistence enabled without window name * docs: lowercase capital B for consistency --------- Co-authored-by: Charles Kerr <[email protected]> Co-authored-by: David Sanders <[email protected]> Co-authored-by: Erick Zhao <[email protected]> * test: support for multimonitor tests (#47911) * test: support for multimonitor tests * fix: update yarn.lock file * test: support any resolution for new displays * test: support display positioning * docs: multi-monitor tests * test: remove dummy test * feat: enforce unique window names across BaseWindow and BrowserWindow (#47764) * feat: save window state (#47425) * feat: save/restore window state * cleanup * remove constructor option * refactor: apply suggestions from code review Co-authored-by: Charles Kerr <[email protected]> * 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 <[email protected]> * docs: update docs/api/structures/base-window-options.md Co-authored-by: Erick Zhao <[email protected]> * 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 <[email protected]> * fix: add warning when window state persistence enabled without window name * docs: lowercase capital B for consistency --------- Co-authored-by: Charles Kerr <[email protected]> Co-authored-by: David Sanders <[email protected]> Co-authored-by: Erick Zhao <[email protected]> * feat: enforce unique window names across BaseWindow and BrowserWindow * docs: update docs for name property * fix: linter issue with symbol --------- Co-authored-by: Charles Kerr <[email protected]> Co-authored-by: David Sanders <[email protected]> Co-authored-by: Erick Zhao <[email protected]> * feat: clear and restore window state (#47781) * feat: save window state (#47425) * feat: save/restore window state * cleanup * remove constructor option * refactor: apply suggestions from code review Co-authored-by: Charles Kerr <[email protected]> * 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 <[email protected]> * docs: update docs/api/structures/base-window-options.md Co-authored-by: Erick Zhao <[email protected]> * 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 <[email protected]> * fix: add warning when window state persistence enabled without window name * docs: lowercase capital B for consistency --------- Co-authored-by: Charles Kerr <[email protected]> Co-authored-by: David Sanders <[email protected]> Co-authored-by: Erick Zhao <[email protected]> * feat: restore window state * feat: flush display modes on show * refactor: move utility functions to common area * feat: clear window state * fix: wait for the prefs to update * test: clearWindowState extra test * test: refine clear window state tests * test: single monitor restore window tests chore: rebase on gsoc-2025 * refactor: refine clearWindowState test * fix: revert default_app back to original * docs: add comment linking AdjustBoundsToBeVisibleOnDisplay to Chromium code * fix: add correct permalink * refactor: ci friendly * fix: disable windowStatePersistence when no display * refactor: use reference instead pointer * fix: skip window state persistence for invalid/fake displays * refactor: better flag placement * test: add test to verify window state is not saved when no display * fix: restore display mode inside show() * feat: save window state (#47425) * feat: save/restore window state * cleanup * remove constructor option * refactor: apply suggestions from code review Co-authored-by: Charles Kerr <[email protected]> * 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 <[email protected]> * docs: update docs/api/structures/base-window-options.md Co-authored-by: Erick Zhao <[email protected]> * 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 <[email protected]> * fix: add warning when window state persistence enabled without window name * docs: lowercase capital B for consistency --------- Co-authored-by: Charles Kerr <[email protected]> Co-authored-by: David Sanders <[email protected]> Co-authored-by: Erick Zhao <[email protected]> * test: clear sharedUserPath before and test * refactor: hasInvalidDisplay function * debug: add display info logging for CI * fix: do not save/restore when window is 0x0 * test: support for multimonitor tests (#47911) * test: support for multimonitor tests * fix: update yarn.lock file * test: support any resolution for new displays * test: support display positioning * docs: multi-monitor tests * test: remove dummy test * feat: enforce unique window names across BaseWindow and BrowserWindow (#47764) * feat: save window state (#47425) * feat: save/restore window state * cleanup * remove constructor option * refactor: apply suggestions from code review Co-authored-by: Charles Kerr <[email protected]> * 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 <[email protected]> * docs: update docs/api/structures/base-window-options.md Co-authored-by: Erick Zhao <[email protected]> * 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 <[email protected]> * fix: add warning when window state persistence enabled without window name * docs: lowercase capital B for consistency --------- Co-authored-by: Charles Kerr <[email protected]> Co-authored-by: David Sanders <[email protected]> Co-authored-by: Erick Zhao <[email protected]> * feat: enforce unique window names across BaseWindow and BrowserWindow * docs: update docs for name property * fix: linter issue with symbol --------- Co-authored-by: Charles Kerr <[email protected]> Co-authored-by: David Sanders <[email protected]> Co-authored-by: Erick Zhao <[email protected]> * test: remove invalid display test --------- Co-authored-by: Charles Kerr <[email protected]> Co-authored-by: David Sanders <[email protected]> Co-authored-by: Erick Zhao <[email protected]> Co-authored-by: Keeley Hammond <[email protected]> --------- Co-authored-by: Charles Kerr <[email protected]> Co-authored-by: David Sanders <[email protected]> Co-authored-by: Erick Zhao <[email protected]> Co-authored-by: Keeley Hammond <[email protected]>
* docs: add note on display APIs in CI * docs: remove inaccurate comment * test: set show to true * docs: restored-window-state event * feat: add 'restored-window-state' event to BaseWindow * test: add tests for 'restored-window-state' event emission * test: move createWindowAndSave * docs: differentiate between name and title * test: add checks for virtual display creation * docs: tutorial for windowStatePersistence * fix: ensure only single display before multi monitor tests * docs: better docs for virtual display addon * docs: better docs for virtual display addon * refactor: rename event restored-window-state to restored-persisted-state * refactor: rename BaseWindow.clearWindowState to clearPersistedState * docs: improve docs for name property and fix typos * build: run yarn install * fix: update base::Value::Dict -> base::DictValue * fix: add install script to virtual-display native addon The virtual-display fixture was missing an "install" script, so node-gyp never compiled it during `yarn install`. This caused "Cannot find module '../build/Release/virtual_display.node'" in CI. Also removed unused dependencies (bindings, @types/jest, node-gyp) to match the pattern of other native addon fixtures. Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Nilay Arya <[email protected]> Co-authored-by: Claude <[email protected]>
Remove stale `#include "shell/browser/native_window_features.h"` (header was deleted in #51160) and add the required `animate` parameter to the `SetBounds` call in `RestoreBounds` (signature changed on main).
…endency The CI runner's Xcode 16.4 has a broken Swift toolchain where swift-frontend cannot load lib_CompilerSwiftIDEUtils.dylib. Since the addon only uses CoreGraphics private C/ObjC APIs (CGVirtualDisplay, CGVirtualDisplayDescriptor, etc.), rewrite the implementation entirely in Objective-C to eliminate the Swift compilation step. Co-Authored-By: Claude <[email protected]>
f52bef4 to
005d088
Compare
18ab30b to
2845784
Compare
| const startTime = Date.now(); | ||
|
|
||
| // Keep main thread busy for 25 seconds | ||
| while (Date.now() - startTime < 25000); |
There was a problem hiding this comment.
I don't know how I feel about the implementation of this test- keeping our CI main thread 25 seconds per test run is a bit of a smell for me
There was a problem hiding this comment.
suggestion: can we move this to a worker?
itsananderson
left a comment
There was a problem hiding this comment.
Are there any edge-cases with the show/hide APIs? For example if I create a window with show: false and windowStatePersistence: true, will any of the persisted state have trouble restoring?
|
|
||
| Returns `BaseWindow | null` - The window with the given `id`. | ||
|
|
||
| #### `BaseWindow.clearPersistedState(name)` |
There was a problem hiding this comment.
Presumably the best time to call this would be right before launching a window with name, but what happens if this is called when name window is currently active. Will any subsequent state changes to that window be persisted? This behavior might be worth clarifying.
| function createWindow () { | ||
| const win = new BrowserWindow({ | ||
| name: 'main-window', | ||
| width: 800, |
There was a problem hiding this comment.
Is it worth noting here that these width and height values will only be used if there are no previously persisted bounds?
There was a problem hiding this comment.
good suggestion, I think its a good idea to be explicit about this
| middleDisplay.workArea.y + middleDisplay.workArea.height | ||
| ); | ||
|
|
||
| // Window should maintain its original size |
There was a problem hiding this comment.
What's the expected behavior if the window's size is larger than the size of the nearest remaining display?
There was a problem hiding this comment.
The window should get shrunken down to fit the remaining work area- see AdjustToFit()
The is_being_restored_ guard was reset on the deferred display-mode callback invocation rather than the actual restoration lifecycle, which caused three defects: 1. A window created with show:false and destroyed before show() left the guard stuck true, so the close-time FlushWindowState save no-op'd and state changes made while hidden were dropped. 2. showInactive() never flushed the deferred display mode, so a persisted hidden window shown inactive did not re-apply saved fullscreen/ maximize/kiosk and left the guard stuck true. 3. On macOS the guard was reset synchronously after the async SetFullScreen/Maximize/SetKiosk calls, so a flush during the transition persisted transitional bounds over the saved state. Reset the guard from the NotifyWindowEnterFullScreen/NotifyWindowMaximize observers once the transition completes, drain a never-run callback in FlushWindowState, flush the pending display mode from ShowInactive on both backends, and skip saves while a fullscreen transition is in flight.
…-2025 # Conflicts: # spec/api-browser-window-spec.ts
itsananderson
left a comment
There was a problem hiding this comment.
I still have a few outstanding comments about areas where we could clarify/improve documentation around edge-case behaviors, but I don't think any of them impact the actual API surface, and they'd be fine to address as follow-ups, so I'm going ahead and leaving an API LGTM
…-2025 # Conflicts: # shell/browser/native_window.h # spec/package.json # yarn.lock
|
Release Notes Persisted
|
|
I was unable to backport this PR to "43-x-y" cleanly; |
|
I have automatically backported this PR to "44-x-y", please check out #52270 |
|
A comment in the WG Releases meeting: The PR is quite chunky. Maybe we wouldn't want to backport to 43. |
|
@VerteDinde has manually backported this PR to "43-x-y", please check out #52935 |
Description of Change
Note
This PR is part of GSoC 2025 [project] [rfc].
This PR attempts to land a new save/restore window state API for Electron that was developed by @nilayarya for Google Summer of Code in the summer of 2025. Each individual PR was reviewed and merged into this branch, which has now been rebased against main - each of those PRs have been preserved as a separate commit, for easy reference.
Checklist
npm testpassesRelease Notes
Notes: Added a Save/Restore Window State API for cross-platform use.