🔧 Always find a window (or error)

This commit is contained in:
Felix Rieseberg 2017-12-08 14:36:52 -08:00
parent 4f901c6d24
commit 9e660b1d32

View file

@ -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)
} }