window-helpers.js 638 B

1234567891011121314151617181920212223
  1. const assert = require('assert')
  2. const {BrowserWindow} = require('electron').remote
  3. exports.closeWindow = (window, {assertSingleWindow} = {assertSingleWindow: true}) => {
  4. if (window == null || window.isDestroyed()) {
  5. if (assertSingleWindow) {
  6. assert.equal(BrowserWindow.getAllWindows().length, 1)
  7. }
  8. return Promise.resolve()
  9. } else {
  10. return new Promise((resolve, reject) => {
  11. window.once('closed', () => {
  12. if (assertSingleWindow) {
  13. assert.equal(BrowserWindow.getAllWindows().length, 1)
  14. }
  15. resolve()
  16. })
  17. window.setClosable(true)
  18. window.close()
  19. })
  20. }
  21. }