clean up popup

This commit is contained in:
Shelley Vohr 2017-10-23 00:47:02 -04:00
parent f9c3123f5f
commit 61a93c711c
No known key found for this signature in database
GPG key ID: F13993A75599653C

View file

@ -132,40 +132,31 @@ Menu.prototype._init = function () {
} }
Menu.prototype.popup = function (window, x, y, positioningItem) { Menu.prototype.popup = function (window, x, y, positioningItem) {
let [newX, newY, newPositioningItem] = [x, y, positioningItem]
let asyncPopup let asyncPopup
// menu.popup(x, y, positioningItem) // menu.popup(x, y, positioningItem)
if (window != null && (typeof window !== 'object' || window.constructor !== BrowserWindow)) { if (window != null) {
// Shift. if (typeof window !== 'object' || window.constructor !== BrowserWindow) {
positioningItem = y [newPositioningItem, newY, newX] = [y, x, window]
y = x window = null
x = window }
window = null
} }
// menu.popup(window, {}) // menu.popup(window, {})
if (x != null && typeof x === 'object') { if (x != null && typeof x === 'object') {
const options = x [newX, newY, newPositioningItem] = [x.x, x.y, x.positioningItem]
x = options.x asyncPopup = x.async
y = options.y
positioningItem = options.positioningItem
asyncPopup = options.async
} }
// Default to showing in focused window. // set up defaults
if (window == null) window = BrowserWindow.getFocusedWindow() if (window == null) window = BrowserWindow.getFocusedWindow()
if (typeof x !== 'number') newX = -1
// Default to showing under mouse location. if (typeof y !== 'number') newY = -1
if (typeof x !== 'number') x = -1 if (typeof positioningItem !== 'number') newPositioningItem = -1
if (typeof y !== 'number') y = -1
// Default to not highlighting any item.
if (typeof positioningItem !== 'number') positioningItem = -1
// Default to synchronous for backwards compatibility.
if (typeof asyncPopup !== 'boolean') asyncPopup = false if (typeof asyncPopup !== 'boolean') asyncPopup = false
this.popupAt(window, x, y, positioningItem, asyncPopup) this.popupAt(window, newX, newY, newPositioningItem, asyncPopup)
} }
Menu.prototype.closePopup = function (window) { Menu.prototype.closePopup = function (window) {