Skip to content

feat: restore windows to their original macOS Spaces on restart#308301

Open
tnayuki wants to merge 2 commits intomicrosoft:mainfrom
tnayuki:feat/macos-spaces-restoration
Open

feat: restore windows to their original macOS Spaces on restart#308301
tnayuki wants to merge 2 commits intomicrosoft:mainfrom
tnayuki:feat/macos-spaces-restoration

Conversation

@tnayuki
Copy link
Copy Markdown

@tnayuki tnayuki commented Apr 7, 2026

Fixes #123517

Summary

  • Add electron-osx-spaces as a dependency to save and restore the macOS Space (virtual desktop) each window belongs to
  • Use AppKit's native NSWindow state restoration APIs (encodeRestorableStateWithCoder: / restoreStateWithCoder:) via the electron-osx-spaces package
  • The restorable state is persisted as base64-encoded data in IWindowState.macOSRestorableState
  • No-op on Windows and Linux

Changes

File Change
package.json Add electron-osx-spaces to dependencies
window.ts Add macOSRestorableState field to IWindowState
windowImpl.ts Encode Space state on quit, restore on window creation

How to test

  1. Build and launch Code - OSS on macOS
  2. Open multiple windows (Cmd+Shift+N)
  3. Drag each window to a different Space (virtual desktop)
  4. Quit (Cmd+Q)
  5. Relaunch — windows should restore to their original Spaces

Compatibility

  • Backwards compatible: macOSRestorableState is optional; old state data works without it
  • Cross-platform: electron-osx-spaces returns no-op on non-macOS platforms
  • macOS 15+: The package includes a workaround for NSWindowRestoresWorkspaceAtLaunch being broken (FB15644170)

Add electron-osx-spaces dependency to save and restore the Space
(virtual desktop) each window belongs to. This uses AppKit's native
NSWindow state restoration APIs via the electron-osx-spaces package.

Fixes microsoft#123517
@vs-code-engineering
Copy link
Copy Markdown
Contributor

vs-code-engineering bot commented Apr 7, 2026

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@bpasero

Matched files:

  • src/vs/platform/window/electron-main/window.ts
  • src/vs/platform/windows/electron-main/windowImpl.ts

@tnayuki
Copy link
Copy Markdown
Author

tnayuki commented Apr 7, 2026

@microsoft-github-policy-service agree

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.

Relaunching VSCode forgets what macOS Desktop each window belongs to

2 participants