Make callback work for old-style Menu.popup call

While the old-style Menu.popup has been deprecated, it is still being
used widely in apps and even in Electron itself.
This commit is contained in:
Cheng Zhao 2018-01-01 17:17:01 +09:00
parent 2ec3b8ce76
commit 73d78d345a
2 changed files with 10 additions and 0 deletions

View file

@ -56,6 +56,11 @@ Menu.prototype.popup = function (window, x, y, positioningItem) {
[newPosition, newY, newX, newWindow] = [y, x, window, null] [newPosition, newY, newX, newWindow] = [y, x, window, null]
} }
// menu.popup([w], x, y, callback)
if (typeof newPosition === 'function') {
callback = newPosition
}
// menu.popup({}) // menu.popup({})
if (window != null && window.constructor === Object) { if (window != null && window.constructor === Object) {
opts = window opts = window

View file

@ -328,6 +328,11 @@ describe('Menu module', () => {
menu.popup({}, () => done()) menu.popup({}, () => done())
menu.closePopup() menu.closePopup()
}) })
it('works with old style', (done) => {
menu.popup(w, 100, 101, () => done())
menu.closePopup()
})
}) })
describe('Menu.closePopup()', () => { describe('Menu.closePopup()', () => {