fix(win32/linux) Quit when the user closes the last window. Was broken because of hidden windows

Test Plan: Run on win32/linux

Reviewers: evan

Reviewed By: evan

Differential Revision: https://review.inboxapp.com/D1386
This commit is contained in:
Ben Gotow 2015-04-03 10:08:12 -07:00
parent 80afdcb7fa
commit 402e481b31
2 changed files with 17 additions and 2 deletions

View file

@ -114,6 +114,7 @@ class AtomWindow
if @neverClose and !global.atomApplication.quitting
event.preventDefault()
@browserWindow.hide()
@emit 'window:close-prevented'
@browserWindow.on 'closed', =>
global.atomApplication.removeWindow(this)

View file

@ -158,6 +158,7 @@ class AtomApplication
removeWindow: (window) ->
@windows.splice @windows.indexOf(window), 1
@applicationMenu?.enableWindowSpecificItems(false) if @windows.length == 0
@windowClosedOrHidden()
# Public: Adds the {AtomWindow} to the global window list.
# IMPORTANT: AtomWindows add themselves - you don't need to manually add them
@ -169,10 +170,23 @@ class AtomApplication
unless window.isSpec
focusHandler = => @lastFocusedWindow = window
closePreventedHandler = => @windowClosedOrHidden()
window.on 'window:close-prevented', closePreventedHandler
window.browserWindow.on 'focus', focusHandler
window.browserWindow.once 'closed', =>
@lastFocusedWindow = null if window is @lastFocusedWindow
window.browserWindow.removeListener 'focus', focusHandler
window.removeListener('window:close-prevented', closePreventedHandler)
window.browserWindow.removeListener('focus', focusHandler)
windowClosedOrHidden: ->
if process.platform in ['win32', 'linux']
visible = false
visible ||= window.isVisible() for window in @windows
if visible is false
@quitting = true
# Quitting the app from within a window event handler causes
# an assertion error. Wait a moment.
_.defer -> app.quit()
# Creates server to listen for additional atom application launches.
#
@ -247,7 +261,7 @@ class AtomApplication
@on 'application:zoom', -> @focusedWindow()?.maximize()
app.on 'window-all-closed', ->
app.quit() if process.platform in ['win32', 'linux']
@windowClosedOrHidden()
app.on 'will-quit', =>
@deleteSocketFile()