|
@@ -45,49 +45,30 @@ Menu.prototype._init = function () {
|
|
|
|
|
|
Menu.prototype.popup = function (window, x, y, positioningItem) {
|
|
|
let [newX, newY, newPosition, newWindow] = [x, y, positioningItem, window]
|
|
|
- let opts
|
|
|
|
|
|
// menu.popup(x, y, positioningItem)
|
|
|
- if (window != null && !(window instanceof BrowserWindow)) {
|
|
|
- [newPosition, newY, newX, newWindow] = [y, x, window, null]
|
|
|
+ if (!window) {
|
|
|
+ // shift over values
|
|
|
+ if (typeof window !== 'object' || window.constructor !== BrowserWindow) {
|
|
|
+ [newPosition, newY, newX, newWindow] = [y, x, window, null]
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- // menu.popup({})
|
|
|
- if (window != null && window.constructor === Object) {
|
|
|
- opts = window
|
|
|
// menu.popup(window, {})
|
|
|
- } else if (x && typeof x === 'object') {
|
|
|
- opts = x
|
|
|
- }
|
|
|
-
|
|
|
- if (opts) {
|
|
|
+ if (x && typeof x === 'object') {
|
|
|
+ const opts = x
|
|
|
newX = opts.x
|
|
|
newY = opts.y
|
|
|
newPosition = opts.positioningItem
|
|
|
}
|
|
|
|
|
|
// set defaults
|
|
|
- if (typeof newX !== 'number') newX = -1
|
|
|
- if (typeof newY !== 'number') newY = -1
|
|
|
- if (typeof newPosition !== 'number') newPosition = -1
|
|
|
- if (!newWindow || (newWindow && newWindow.constructor !== BrowserWindow)) {
|
|
|
- newWindow = BrowserWindow.getFocusedWindow()
|
|
|
-
|
|
|
- // No window focused?
|
|
|
- if (!newWindow) {
|
|
|
- const browserWindows = BrowserWindow.getAllWindows()
|
|
|
-
|
|
|
- if (browserWindows && browserWindows.length > 0) {
|
|
|
- newWindow = browserWindows[0]
|
|
|
- } else {
|
|
|
- throw new Error(`Cannot open Menu without a BrowserWindow present`)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ if (typeof x !== 'number') newX = -1
|
|
|
+ if (typeof y !== 'number') newY = -1
|
|
|
+ if (typeof positioningItem !== 'number') newPosition = -1
|
|
|
+ if (!window) newWindow = BrowserWindow.getFocusedWindow()
|
|
|
|
|
|
this.popupAt(newWindow, newX, newY, newPosition)
|
|
|
-
|
|
|
- return { browserWindow: newWindow, x: newX, y: newY, position: newPosition }
|
|
|
}
|
|
|
|
|
|
Menu.prototype.closePopup = function (window) {
|