Menu.prototype.popup = function (options = {}) { if (options == null || typeof options !== 'object') { throw new TypeError('Options must be an object') } let { window, x, y, positioningItem, callback } = options // no callback passed if (!callback || typeof callback !== 'function') callback = () => {} // set defaults if (typeof x !== 'number') x = -1 if (typeof y !== 'number') y = -1 if (typeof positioningItem !== 'number') positioningItem = -1 // find which window to use const wins = TopLevelWindow.getAllWindows() if (!wins || wins.indexOf(window) === -1) { window = TopLevelWindow.getFocusedWindow() if (!window && wins && wins.length > 0) { window = wins[0] } if (!window) { throw new Error(`Cannot open Menu without a TopLevelWindow present`) } } this.popupAt(window, x, y, positioningItem, callback) return { browserWindow: window, x, y, position: positioningItem } }
Menu.setApplicationMenu = function (menu) { if (menu && menu.constructor !== Menu) { throw new TypeError('Invalid menu') } applicationMenu = menu if (process.platform === 'darwin') { if (!menu) return menu._callMenuWillShow() bindings.setApplicationMenu(menu) } else { const windows = TopLevelWindow.getAllWindows() return windows.map(w => w.setMenu(menu)) } }
executeCommand: (menu, event, id) => { const command = menu.commandsMap[id] if (!command) return command.click(event, TopLevelWindow.getFocusedWindow(), webContents.getFocusedWebContents()) },