Skip to content
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

[Feature Request]: Enable Application Window Restoration #37494

Open
3 tasks done
ericdrobinson opened this issue Mar 4, 2023 · 6 comments
Open
3 tasks done

[Feature Request]: Enable Application Window Restoration #37494

ericdrobinson opened this issue Mar 4, 2023 · 6 comments

Comments

@ericdrobinson
Copy link

Preflight Checklist

Problem Description

Electron based applications fail to restore their windows to their user-assigned Virtual Desktop [Windows 10/11] or Space [macOS].

Unfortunately, this isn't something that Electron users can address in their application implementations. This is due to the fact that OS APIs do not [universally] exist to enable such direct management:

  • Microsoft provides the VirtualDesktopManager which supports a very limited set of APIs (so limited, in fact, that there does not appear to be a way to enumerate the user's current set of available Desktops).
  • Apple explains their own process in their Mac App Programming Guide which amounts to "conform to some protocols and NSWindow state will be saved on application shutdown/restored on application startup".

(I haven't looked into Linux window manager APIs...)

Regardless, Microsoft and Apple provide enough APIs for applications to save and restore their "Virtual Desktop"/"Space" assignment on application restart. While Microsoft's APIs appear to be usable at any point in the application's life cycle, Apple's APIs are very much tied to the implementation of the NSWindow.

Electron's upstream Chromium does properly support session restoration with Virtual Desktop / Space assignments for its windows. The bugs that tracked these features are as follows:

The implementations of these features can be seen in the following change lists:

These are clearly implemented in drastically different ways. The macOS implementation is most directly (and clearly) tied to Chromium's concept of "session restoration".

Current versions of Electron do not provide any ability to tap into Chromium's window restoration capabilities (or provide their own mechanism). Applications currently have to rely on APIs provided by the BrowserWindow class and that class does not (and cannot) provide the APIs necessary to support this feature.

Proposed Solution

I would like Electron to provide an option wherein an Electron application developer can specify that they would like the windows of an application to be restored on next start. This option should handle window Virtual Desktop/Space reassignment. I expect that APIs may be necessary to enable applications to "rehydrate" the restored windows with serialized application state.

Unfortunately, my personal experience with Electron application session restoration is insufficient to propose anything more than the high level ask above. Perhaps @bpasero might chime in - he seems like someone who may be sufficiently steeped in the complexities of window/state restoration to be able to suggest a solution or improved list of requirements for a solution.

Alternatives Considered

The alternatives considered are as follows:

  1. Use BrowserWindow APIs. The APIs do not provide any way to control Virtual Desktop/Space assignment.
  2. Wait for a separate set of "Workspace APIs". These APIs are not yet implemented. Moreover, the proposed set of APIs aren't currently feasible given the available set of APIs provided by the host OSes themselves (importantly, none of them are available on macOS).

These approaches are both at the level of "we can pass this off to Electron application developers". Unfortunately, due to the nature of how Virtual Desktop/Space systems work this needs to be something that is handled internally.

Additional Information

I should also explain that there are several scenarios that end users expect this feature:

  1. "I restarted my computer and my previously open applications automatically restore to the setup I had before rebooting."
  2. "I restarted my application to install an update."
  3. "I exited my application, went to lunch, came back, and re-opened my application."

Notably, Apple only explains that they support restoration when the computer restarts and applications are reopened. The other two scenarios aren't officially handled. That said, the Chromium developers were able to identify an approach that enables Chromium itself to restart (e.g. during an update) and restore windows to their previously assigned Spaces. This feature mostly works when quitting/starting Chrome normally (case 3 above), though this may require setting a custom preference.

It appears that the Windows APIs also operate on a "best effort" basis wherein if the ID of the Virtual Desktop targeted for restoration doesn't exist anymore, the window is moved instead to the active Virtual Desktop.


Related issues:

@ShivamPandey00
Copy link

Hey @ericdrobinson ,
I would like to work on this issue.

@ShivamPandey00
Copy link

My proposed solution is to add a new option in Electron's API which allows the developers to specify that they want the windows of their application to be restored on next start. This option should handle window Virtual Desktop/Space reassignment.

To implement this, we will need to add new APIs to allow applications to "rehydrate" the restored windows with serialized application state. We will also need to modify the codebase to tap into Chromium's window restoration capabilities, which are already implemented in Chromium for both Windows and macOS.

By leveraging Chromium's existing implementation, we can ensure that our solution is robust and reliable. Additionally, by adding this new feature to Electron's API, we can make it easy for developers to implement session restoration with Virtual Desktop / Space assignments in their applications.

@ericdrobinson
Copy link
Author

@coderdeadpool Are you planning on doing the legwork to develop out a solution to this issue? Or was your goal rather to outline a proposal and leave it at that?

I fear that it may be a bit ambiguous and I want to make sure that the status is clear for anyone encountering this issue (especially maintainers).

@ericdrobinson
Copy link
Author

I'd love to be proven wrong, but I think @ShivamPandey00 has abandoned any effort to implement this. While that account does have an Electron Repo fork, there doesn't appear to be any work done to it (main is untouched and no branches pushed to GitHub). The "proposed solution" was suspicious from the start as it was mostly a restatement of the writeup I provided in the summary.

@ericdrobinson
Copy link
Author

ericdrobinson commented Oct 11, 2023

@codebytere Any chance that this feature request could get some attention? No Electron-based application can properly hook into Virtual Desktop/Spaces settings/assignments unless it's supported within Electron itself 😕

@Igetin
Copy link

Igetin commented Dec 19, 2023

I didn’t see it mentioned, so: on Linux distributions, at least GNOME has a virtual desktop feature available (called “workspaces”). I would like to see the restoration also supported there.

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

No branches or pull requests

3 participants