Skip to content

Remember Desktop No. on app restart in macOS #15211

Closed

Description

@HelloKashif

Start the app
Move in to another desktop (macOS virtual spaces)
Restart the app

Result: App jumps back to the first desktop

Would be nice if it remembers the last desktop it was on

Activity

  1. welcome commented on Oct 17, 2018

    @welcome

    👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

    To help make it easier for us to investigate your issue, please follow the contributing guidelines.

  2. MarshallOfSound commented on Oct 17, 2018

    @MarshallOfSound
    Member

    This is something apps can implement (by saving window location on quit and restoring on start)

  3. ericdrobinson commented on Mar 3, 2023

    @ericdrobinson

    @MarshallOfSound With respect to this:

    This is something apps can implement (by saving window location on quit and restoring on start)

    How certain of this are you? If you're certain that it's something apps can implement themselves, then do you have any pointers for enabling this?

    My understanding is that it requires implementation at the NSWindow level. From the Mac App Programming Guide:

    You must do the following to preserve the state of your user interface:

    • For each window, you must set whether the window should be preserved using the setRestorable: method.
    • For each preserved window, you must specify an object whose job is to re-create that window at launch time.
    • Any objects involved in your user interface must write out the data they require to restore their state later.
    • At launch time, you must use the provided data to restore your objects to their previous state.

    I haven't done any development with Electron myself - I've just used many Electron apps over the years and had to deal with Space reassignment after every app update/restart and would rejoice at no longer having to do that. That said, it sounds as though the main Electron user facing API would be too high level to allow app developers to hook in and implement this on their own without modifying Electron source code.

    Do you know of an Electron-based app that has successfully implemented this?

    Additionally, the best resource I've found for how Google implemented this to be in this initial changelist (found in this comment).

  4. ericdrobinson commented on Mar 4, 2023

    @ericdrobinson

    @MarshallOfSound I dug a bit more into this and my guess is that you're equating this issue with the concept of "Saving and Restoring Window State" as expressed in solutions provided in #526 (using win.setBounds). Unfortunately, "Desktop Number" (or, in macOS parlance, "Spaces") cannot be addressed in this manner: Apple does not provide APIs for assigning windows to particular Spaces so it isn't something that Electron could even provide an API for anyway.

    Apple expects Spaces to work as follows:

    1. Space Assignment: User moves a window directly to a target Space within the macOS UI. There are a number of ways to do this.
    2. Space Restoration: On computer restart (and, apparently, on forced app restart?), Apple requests that NSWindow instances save their state on shutdown and then restore that state on startup.

    As "simple" as that. Indeed, that second item is exactly what the changelist I linked in my previous comment implements.

    Unfortunately, this isn't something that applications built on top of Electron can handle without modifying Electron's source code.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions