diff --git a/lib/browser/api/menu.js b/lib/browser/api/menu.js index 41244c69afb..c1ba85b522d 100644 --- a/lib/browser/api/menu.js +++ b/lib/browser/api/menu.js @@ -53,15 +53,14 @@ Menu.prototype.popup = function (options) { if (typeof x !== 'number') x = -1 if (typeof y !== 'number') y = -1 if (typeof positioningItem !== 'number') positioningItem = -1 - if (!window || (window && window.constructor !== BrowserWindow)) { - window = BrowserWindow.getFocusedWindow() - // No window focused? - if (!window) { - const wins = BrowserWindow.getAllWindows() - if (wins && wins.length > 0) { - window = wins[0] - } else { + // find which window to use + const wins = BrowserWindow.getAllWindows() + if (!wins || wins.indexOf(window) === -1) { + window = BrowserWindow.getFocusedWindow() + if (!window && wins && wins.length > 0) { + window = wins[0] + if (!window) { throw new Error(`Cannot open Menu without a BrowserWindow present`) } } diff --git a/spec/api-menu-spec.js b/spec/api-menu-spec.js index 27a26e9a4a6..560f16d7b8e 100644 --- a/spec/api-menu-spec.js +++ b/spec/api-menu-spec.js @@ -344,15 +344,11 @@ describe('Menu module', () => { }) it('returns immediately', () => { - const { browserWindow, x, y } = menu.popup({ - window: w, - x: 100, - y: 101 - }) - - assert.equal(browserWindow, w) - assert.equal(x, 100) - assert.equal(y, 101) + const input = {window: w, x: 100, y: 101} + const output = menu.popup(input) + assert.equal(output.x, input.x) + assert.equal(output.y, input.y) + assert.equal(output.browserWindow, input.window) }) it('works without a given BrowserWindow and options', () => {