2016-11-29 22:06:22 +03:00
|
|
|
const assert = require('assert')
|
|
|
|
const {BrowserWindow} = require('electron').remote
|
|
|
|
|
|
|
|
exports.closeWindow = (window, {assertSingleWindow} = {assertSingleWindow: true}) => {
|
2016-08-03 22:47:53 +03:00
|
|
|
if (window == null || window.isDestroyed()) {
|
2016-11-29 22:06:22 +03:00
|
|
|
if (assertSingleWindow) {
|
|
|
|
assert.equal(BrowserWindow.getAllWindows().length, 1)
|
|
|
|
}
|
2016-08-03 22:47:53 +03:00
|
|
|
return Promise.resolve()
|
|
|
|
} else {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
window.once('closed', () => {
|
2016-11-29 22:06:22 +03:00
|
|
|
if (assertSingleWindow) {
|
|
|
|
assert.equal(BrowserWindow.getAllWindows().length, 1)
|
|
|
|
}
|
2016-08-03 22:47:53 +03:00
|
|
|
resolve()
|
|
|
|
})
|
|
|
|
window.setClosable(true)
|
|
|
|
window.close()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|