Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

load initialPaths for first new-window event #12486

Closed
wants to merge 1 commit into from

Conversation

hongyuanw
Copy link
Contributor

@hongyuanw hongyuanw commented Aug 20, 2016

Fix bug #11361

1、On macOS, the sate is not saved when the last window is removed because the progress is running, so "removeWindow" function must be updated to :

@saveState(false) unless window.isSpec

2、We must load paths from '.atom/storage/application.json' for the first window when the application is running and no window, especially on macOS

@hongyuanw
Copy link
Contributor Author

@maxbrunsfeld @50Wliu @lee-dohm Could you review this code when you get a chance?

@50Wliu 50Wliu added the mac Issues that occur on macOS but not on other platforms. label Aug 25, 2016
@maxbrunsfeld
Copy link
Contributor

@yuanwhy I believe the current behavior is already correct. I may be misunderstanding the problem that you're describing. Could you describe step by step what you're doing, what you expect to see, and what you actually see?

@lee-dohm
Copy link
Contributor

@maxbrunsfeld Also see #12495

@hongyuanw
Copy link
Contributor Author

hongyuanw commented Aug 27, 2016

@maxbrunsfeld Let's review the original code

 # Public: Removes the {AtomWindow} from the global window list.
  removeWindow: (window) ->
    if @windows.length is 1
      @applicationMenu?.enableWindowSpecificItems(false)
      if process.platform in ['win32', 'linux']
        app.quit()
        return
    @windows.splice(@windows.indexOf(window), 1)
    @saveState(true) unless window.isSpec 

The atom progress will quit on win32 and linux when the last window is closed, but is not for macOS.

So, on macOS, when we close the last window, code

@windows.splice(@windows.indexOf(window), 1)

will remove the last window and its state from windows container, then

@saveState(true) unless window.isSpec 

will not save the last window's state to application.json becase of "true" argument ...

the saveState function :

saveState: (allowEmpty=false) ->
    return if @quitting
    states = []
    for window in @windows  # when you close the last window, @windows is empty !
      unless window.isSpec
        if loadSettings = window.getLoadSettings()
          states.push(initialPaths: loadSettings.initialPaths)
    if states.length > 0 or allowEmpty  # if you use saveState(true), you will write []  to 'application.json'
      @storageFolder.storeSync('application.json', states)

That means you can't save sate to application.json on macOS

@abarisain
Copy link

It looks like it is saving an empty state, as it should, since no windows are open. That's a valid state on osx. If I manually close all windows and then quit atom, nothing should be reopened on start. It would mean that it is not possible to close the last project if you don't persist an empty state.

If anything, atom has the opposite problem, where it saves its state on quitting, disregarding OSX's state restoration option (in SysPrefs -> general). It's quite handy for an IDE though.

@maxbrunsfeld
Copy link
Contributor

maxbrunsfeld commented Aug 27, 2016

will not save the last window's state to application.json becase of "true" argument

No, it does save the state because of the true argument. The state is that there are no windows.

Again, it is the expected behavior on Mac that if you quit the app with no windows open, when you reopen the app, you see none of your previous windows.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
mac Issues that occur on macOS but not on other platforms. more-information-needed needs-review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants