Skip to content

Provide a mechanism for macOS apps to restore themselves to their original Spaces #10124

Closed

Description

@nchammas

This feature request is related to #5362 but is specific to macOS. It is motivated by microsoft/vscode#979.

Expected behavior

When an Electron app is restarted on macOS, all the windows should restore to the Space (i.e. virtual desktop) they were originally in.

Actual behavior

Currently, there doesn't appear to be a way to do this, and restarted Electron apps like Visual Studio Code restore all their windows to the default Space. The user then has to manually replace all the windows in their correct Space. This happens every time the app or OS is restarted.

How to reproduce

Install Visual Studio Code and follow the steps here: microsoft/vscode#979 (comment)

Some notes on a potential solution

macOS seems to offer a concept known as a restoration class by which applications can preserve interface data like what Space they belong to. This may be what Electron needs to wrap in order to provide the functionality described here.

For additional information, see these threads:

Activity

  1. ericdrobinson commented on Jul 26, 2017

    @ericdrobinson

    As pointed out in the linked threads, Apple does not provide a mechanism for apps to restore to previous Spaces during app restart.

    However, Apple does provide this capability across system restart. Adding support for this would allow apps that were active when the computer began it's reboot process to restore to their previous configuration (including Space assignment) when the computer completes the process. All native Apple apps work this way. The fix is outlined in the Chromium bug thread:

    [I]f they’re trying to do their own state restoration and not going through NSWindow, the space isn’t going to be restored.

    These apps need to use NSWindow’s encodeRestorableStateWithCoder: and restoreStateWithCoder:.

  2. ericdrobinson commented on Jul 28, 2017

    @ericdrobinson

    I should add that this is only related to #5362 in that it refers to "workspaces/virtual desktops". However, it appears that Apple does not provide public APIs for programmatic Space assignment.

    This issue is specifically related to being a "good macOS citizen" and properly restoring windows to their previous Spaces after a system reboot.

  3. codebytere commented on Jan 30, 2018

    @codebytere
    Member

    Hi, while we appreciate this enhancement request it's not something that our team will be able to implement in the foreseeable future, and since we use our issues tab as the team's backlog, we prefer to only retain issues that are on our immediate roadmap. If you'd like to make a PR for this request we would welcome that but in the meantime I'm going to go ahead and close this.

  4. ericdrobinson commented on Jan 30, 2018

    @ericdrobinson

    since we use our issues tab as the team's backlog, we prefer to only retain issues that are on our immediate roadmap.

    🤔

    @codebytere Am I missing something? If you do use the issues tab as the team's backlog, then shouldn't this remain?

    It is correctly labeled as a macOS enhancement. I understand not prioritizing it - perhaps add a Backlog label?

  5. gandalfsaxe commented on Nov 28, 2018

    @gandalfsaxe

    Please prioritize this 👍 It's madness to have to rearrange all the VSCode windows upon system restart.

  6. ericdrobinson commented on Oct 11, 2019

    @ericdrobinson

    @codebytere The relevant upstream(?) issue (in Chromium) was recently closed as fixed. Is it possible that the Chromium support will affect Electron support for the feature?

  7. xgdgsc commented on Jun 18, 2020

    @xgdgsc
  8. gandalfsaxe commented on Jun 18, 2020

    @gandalfsaxe

    @xgdgsc I'm not 100% sure but it seems to work for me on multiple monitors, at least some of the time. I did notice that it never works if the Mac was not properly shut down, but always if it was restarting / shut down properly.

  9. ericdrobinson commented on Jun 18, 2020

    @ericdrobinson

    @xgdgsc The bug you linked is for Windows. This Issue is specifically for macOS.

    @gandalfsaxe Are you seeing that on macOS with Chrome or Electron-based apps?

    Regardless, you might do well to post about your experience on this Chromium bug report to help the cause.

  10. gandalfsaxe commented on Jun 20, 2020

    @gandalfsaxe

    @ericdrobinson I meant Chrome, not electron apps.

    But though the fix for Chrome once worked for me (at least most of the time), it doesn't work anymore.

    Thanks, left a comment in the issue thread.

  11. brandonzylstra commented on Nov 5, 2021

    @brandonzylstra

    Hi, while we appreciate this enhancement request it's not something that our team will be able to implement in the foreseeable future,

    This is a request for a bug fix, not for an "enhancement".

  12. xxalilov commented on Nov 5, 2021

    @xxalilov
  13. bpasero commented on Oct 11, 2023

    @bpasero
    Contributor

    @codebytere can this be reopened to better support VS Code scenarios around restoring all state that the user has setup?

    Related to #5362

  14. ericdrobinson commented on Oct 11, 2023

    @ericdrobinson

    @bpasero I created Issue #37494 to track this feature request. It's both still open and contains a lot more information/context (it links both this issue and microsoft/vscode#146915 in the summary, for instance). That might be the better issue to reference...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions