Merge pull request #12645 from atom/as-fix-app-not-quitting-on-windows-and-linux

Fix app not quitting on win32 and linux when closing the last window
This commit is contained in:
Antonio Scandurra
2016-09-09 17:57:57 +02:00
committed by GitHub
2 changed files with 44 additions and 4 deletions

View File

@@ -14,10 +14,12 @@ const ATOM_RESOURCE_PATH = path.resolve(__dirname, '..', '..')
describe('AtomApplication', function () {
this.timeout(60 * 1000)
let originalAppQuit, originalAtomHome, atomApplicationsToDestroy
let originalPlatform, originalAppQuit, originalAtomHome, atomApplicationsToDestroy
beforeEach(function () {
originalPlatform = Object.getOwnPropertyDescriptor(process, 'platform')
originalAppQuit = electron.app.quit
mockElectronAppQuit()
originalAtomHome = process.env.ATOM_HOME
process.env.ATOM_HOME = makeTempDir('atom-home')
// Symlinking the compile cache into the temporary home dir makes the windows load much faster
@@ -32,6 +34,7 @@ describe('AtomApplication', function () {
})
afterEach(async function () {
Object.defineProperty(process, 'platform', originalPlatform)
electron.app.quit = originalAppQuit
process.env.ATOM_HOME = originalAtomHome
for (let atomApplication of atomApplicationsToDestroy) {
@@ -366,11 +369,48 @@ describe('AtomApplication', function () {
await focusWindow(app2Window)
assert.deepEqual(await getTreeViewRootDirectories(app2Window), [])
})
describe('when closing the last window', function () {
describe('on win32', function () {
it('quits the application', async function () {
const atomApplication = buildAtomApplication()
Object.defineProperty(process, 'platform', {get: () => 'win32'})
const window = atomApplication.launch(parseCommandLine([path.join(makeTempDir("a"), 'file-a')]))
await focusWindow(window)
window.close()
await window.closedPromise
assert(electron.app.hasQuitted())
})
})
describe('on linux', function () {
it('quits the application', async function () {
const atomApplication = buildAtomApplication()
Object.defineProperty(process, 'platform', {get: () => 'linux'})
const window = atomApplication.launch(parseCommandLine([path.join(makeTempDir("a"), 'file-a')]))
await focusWindow(window)
window.close()
await window.closedPromise
assert(electron.app.hasQuitted())
})
})
describe('on darwin', function () {
it('leaves the application open', async function () {
const atomApplication = buildAtomApplication()
Object.defineProperty(process, 'platform', {get: () => 'darwin'})
const window = atomApplication.launch(parseCommandLine([path.join(makeTempDir("a"), 'file-a')]))
await focusWindow(window)
window.close()
await window.closedPromise
assert(!electron.app.hasQuitted())
})
})
})
})
describe('before quitting', function () {
it('waits until all the windows have saved their state and then quits', async function () {
mockElectronAppQuit()
const dirAPath = makeTempDir("a")
const dirBPath = makeTempDir("b")
const atomApplication = buildAtomApplication()

View File

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