Add callback parameter to Menu.popup

This commit is contained in:
Cheng Zhao 2018-01-01 16:26:19 +09:00
parent 2e3d940749
commit 7b01a8b860
6 changed files with 31 additions and 16 deletions

View file

@ -49,6 +49,7 @@ Menu.prototype._init = function () {
Menu.prototype.popup = function (window, x, y, positioningItem) {
let [newX, newY, newPosition, newWindow] = [x, y, positioningItem, window]
let opts
let callback
// menu.popup(x, y, positioningItem)
if (window != null && !(window instanceof BrowserWindow)) {
@ -58,9 +59,11 @@ Menu.prototype.popup = function (window, x, y, positioningItem) {
// menu.popup({})
if (window != null && window.constructor === Object) {
opts = window
callback = arguments[1]
// menu.popup(window, {})
} else if (x && typeof x === 'object') {
opts = x
callback = arguments[2]
}
if (opts) {
@ -68,6 +71,9 @@ Menu.prototype.popup = function (window, x, y, positioningItem) {
newY = opts.y
newPosition = opts.positioningItem
}
if (typeof callback !== 'function') {
callback = () => {}
}
// set defaults
if (typeof newX !== 'number') newX = -1
@ -88,7 +94,7 @@ Menu.prototype.popup = function (window, x, y, positioningItem) {
}
}
this.popupAt(newWindow, newX, newY, newPosition)
this.popupAt(newWindow, newX, newY, newPosition, callback)
return { browserWindow: newWindow, x: newX, y: newY, position: newPosition }
}