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

    @openPathOnEvent('application:open-license', path.join(process.resourcesPath, 'LICENSE.md'))

    app.on 'before-quit', =>
      @quitting = true

    app.on 'will-quit', =>

        if loadSettings = window.getLoadSettings()
          states.push(initialPaths: loadSettings.initialPaths)
    @storageFolder.store('application.json', states)

  hasEditorWindows: ->
    @windows.some (window) -> not window.isSpec

  loadState: ->
    if (states = @storageFolder.load('application.json'))?.length > 0
