Add "app.whenReady()" (#12652)

* Make "chai-as-promised" avaialble in tests

* Add "app.whenReady()"

Closes #9561.
This commit is contained in:
Alexey Kuzmin 2018-04-20 09:09:23 +02:00 committed by Samuel Attard
parent c7a0b419a9
commit fcc82ebd35
4 changed files with 41 additions and 0 deletions

View file

@ -11,12 +11,30 @@ const {deprecate, Menu} = electron
const {EventEmitter} = require('events')
let dockMenu = null
let readyPromise = null
// App is an EventEmitter.
Object.setPrototypeOf(App.prototype, EventEmitter.prototype)
EventEmitter.call(app)
Object.assign(app, {
whenReady () {
if (readyPromise !== null) {
return readyPromise
}
if (app.isReady()) {
readyPromise = Promise.resolve()
} else {
readyPromise = new Promise(resolve => {
// XXX(alexeykuzmin): Explicitly ignore any data
// passed to the event handler to avoid memory leaks.
app.once('ready', () => resolve())
})
}
return readyPromise
},
setApplicationMenu (menu) {
return Menu.setApplicationMenu(menu)
},