Use async/await in before-quit handler

This commit is contained in:
Max Brunsfeld
2018-01-05 12:10:39 -08:00
parent 1de37810f0
commit 9d30003e58

View File

@@ -396,22 +396,19 @@ class AtomApplication extends EventEmitter {
this.openPathOnEvent('application:open-your-stylesheet', 'atom://.atom/stylesheet')
this.openPathOnEvent('application:open-license', path.join(process.resourcesPath, 'LICENSE.md'))
this.disposable.add(ipcHelpers.on(app, 'before-quit', event => {
this.disposable.add(ipcHelpers.on(app, 'before-quit', async event => {
let resolveBeforeQuitPromise
this.lastBeforeQuitPromise = new Promise(resolve => {
resolveBeforeQuitPromise = resolve
})
this.lastBeforeQuitPromise = new Promise(resolve => { resolveBeforeQuitPromise = resolve })
if (this.quitting) return resolveBeforeQuitPromise()
if (!this.quitting) {
this.quitting = true
event.preventDefault()
const windowUnloadPromises = this.getAllWindows().map(window => window.prepareToUnload())
const windowUnloadedResults = await Promise.all(windowUnloadPromises)
if (windowUnloadedResults.every(Boolean)) app.quit()
}
this.quitting = true
event.preventDefault()
const windowUnloadPromises = this.getAllWindows().map(window => window.prepareToUnload())
return Promise.all(windowUnloadPromises).then(windowUnloadedResults => {
const didUnloadAllWindows = windowUnloadedResults.every(Boolean)
if (didUnloadAllWindows) app.quit()
resolveBeforeQuitPromise()
})
resolveBeforeQuitPromise()
}))
this.disposable.add(ipcHelpers.on(app, 'will-quit', () => {