diff --git a/lib/browser/api/menu-item-roles.js b/lib/browser/api/menu-item-roles.js index 249e5f4b720f..6487911764e1 100644 --- a/lib/browser/api/menu-item-roles.js +++ b/lib/browser/api/menu-item-roles.js @@ -115,7 +115,7 @@ exports.getDefaultAccelerator = (role) => { if (roles.hasOwnProperty(role)) return roles[role].accelerator } -exports.execute = (role, focusedWindow) => { +exports.execute = (role, focusedWindow, focusedWebContents) => { if (!roles.hasOwnProperty(role)) return false if (process.platform === 'darwin') return false @@ -135,15 +135,8 @@ exports.execute = (role, focusedWindow) => { return true } - if (webContentsMethod && focusedWindow != null) { - const {webContents} = focusedWindow - if (webContents) { - if (webContents.isDevToolsFocused()) { - webContents.devToolsWebContents[webContentsMethod]() - } else { - webContents[webContentsMethod]() - } - } + if (webContentsMethod && focusedWebContents != null) { + focusedWebContents[webContentsMethod]() return true } diff --git a/lib/browser/api/menu-item.js b/lib/browser/api/menu-item.js index d34cf3e3d105..a9949aa195c1 100644 --- a/lib/browser/api/menu-item.js +++ b/lib/browser/api/menu-item.js @@ -48,13 +48,13 @@ const MenuItem = function (options) { this.overrideReadOnlyProperty('commandId', ++nextCommandId) const click = options.click - this.click = (event, focusedWindow) => { + this.click = (event, focusedWindow, focusedWebContents) => { // Manually flip the checked flags when clicked. if (this.type === 'checkbox' || this.type === 'radio') { this.checked = !this.checked } - if (!roles.execute(this.role, focusedWindow)) { + if (!roles.execute(this.role, focusedWindow, focusedWebContents)) { if (typeof click === 'function') { click(this, focusedWindow, event) } else if (typeof this.selector === 'string' && process.platform === 'darwin') { diff --git a/lib/browser/api/menu.js b/lib/browser/api/menu.js index 467cca6d09e2..64397ce6a8ee 100644 --- a/lib/browser/api/menu.js +++ b/lib/browser/api/menu.js @@ -1,7 +1,6 @@ 'use strict' -const BrowserWindow = require('electron').BrowserWindow -const MenuItem = require('electron').MenuItem +const {BrowserWindow, MenuItem, webContents} = require('electron') const EventEmitter = require('events').EventEmitter const v8Util = process.atomBinding('v8_util') const bindings = process.atomBinding('menu') @@ -117,8 +116,10 @@ Menu.prototype._init = function () { return command != null ? command.icon : undefined }, executeCommand: (event, commandId) => { - var command = this.commandsMap[commandId] - return command != null ? command.click(event, BrowserWindow.getFocusedWindow()) : undefined + const command = this.commandsMap[commandId] + if (command == null) return + + command.click(event, BrowserWindow.getFocusedWindow(), webContents.getFocusedWebContents()) }, menuWillShow: () => { // Make sure radio groups have at least one menu item seleted.