🔧 Always find a window (or error)
This commit is contained in:
parent
4f901c6d24
commit
9e660b1d32
1 changed files with 14 additions and 1 deletions
|
@ -63,10 +63,23 @@ Menu.prototype.popup = function (window, x, y, positioningItem) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// set defaults
|
// set defaults
|
||||||
if (!window) newWindow = BrowserWindow.getFocusedWindow()
|
|
||||||
if (typeof newX !== 'number') newX = -1
|
if (typeof newX !== 'number') newX = -1
|
||||||
if (typeof newY !== 'number') newY = -1
|
if (typeof newY !== 'number') newY = -1
|
||||||
if (typeof newPosition !== 'number') newPosition = -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`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.popupAt(newWindow, newX, newY, newPosition)
|
this.popupAt(newWindow, newX, newY, newPosition)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue