Call role method on focused web contents
This commit is contained in:
parent
06e595e7cc
commit
f9a8bd3ea5
3 changed files with 10 additions and 16 deletions
|
@ -115,7 +115,7 @@ exports.getDefaultAccelerator = (role) => {
|
||||||
if (roles.hasOwnProperty(role)) return roles[role].accelerator
|
if (roles.hasOwnProperty(role)) return roles[role].accelerator
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.execute = (role, focusedWindow) => {
|
exports.execute = (role, focusedWindow, focusedWebContents) => {
|
||||||
if (!roles.hasOwnProperty(role)) return false
|
if (!roles.hasOwnProperty(role)) return false
|
||||||
if (process.platform === 'darwin') return false
|
if (process.platform === 'darwin') return false
|
||||||
|
|
||||||
|
@ -135,15 +135,8 @@ exports.execute = (role, focusedWindow) => {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (webContentsMethod && focusedWindow != null) {
|
if (webContentsMethod && focusedWebContents != null) {
|
||||||
const {webContents} = focusedWindow
|
focusedWebContents[webContentsMethod]()
|
||||||
if (webContents) {
|
|
||||||
if (webContents.isDevToolsFocused()) {
|
|
||||||
webContents.devToolsWebContents[webContentsMethod]()
|
|
||||||
} else {
|
|
||||||
webContents[webContentsMethod]()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,13 +48,13 @@ const MenuItem = function (options) {
|
||||||
this.overrideReadOnlyProperty('commandId', ++nextCommandId)
|
this.overrideReadOnlyProperty('commandId', ++nextCommandId)
|
||||||
|
|
||||||
const click = options.click
|
const click = options.click
|
||||||
this.click = (event, focusedWindow) => {
|
this.click = (event, focusedWindow, focusedWebContents) => {
|
||||||
// Manually flip the checked flags when clicked.
|
// Manually flip the checked flags when clicked.
|
||||||
if (this.type === 'checkbox' || this.type === 'radio') {
|
if (this.type === 'checkbox' || this.type === 'radio') {
|
||||||
this.checked = !this.checked
|
this.checked = !this.checked
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!roles.execute(this.role, focusedWindow)) {
|
if (!roles.execute(this.role, focusedWindow, focusedWebContents)) {
|
||||||
if (typeof click === 'function') {
|
if (typeof click === 'function') {
|
||||||
click(this, focusedWindow, event)
|
click(this, focusedWindow, event)
|
||||||
} else if (typeof this.selector === 'string' && process.platform === 'darwin') {
|
} else if (typeof this.selector === 'string' && process.platform === 'darwin') {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const BrowserWindow = require('electron').BrowserWindow
|
const {BrowserWindow, MenuItem, webContents} = require('electron')
|
||||||
const MenuItem = require('electron').MenuItem
|
|
||||||
const EventEmitter = require('events').EventEmitter
|
const EventEmitter = require('events').EventEmitter
|
||||||
const v8Util = process.atomBinding('v8_util')
|
const v8Util = process.atomBinding('v8_util')
|
||||||
const bindings = process.atomBinding('menu')
|
const bindings = process.atomBinding('menu')
|
||||||
|
@ -117,8 +116,10 @@ Menu.prototype._init = function () {
|
||||||
return command != null ? command.icon : undefined
|
return command != null ? command.icon : undefined
|
||||||
},
|
},
|
||||||
executeCommand: (event, commandId) => {
|
executeCommand: (event, commandId) => {
|
||||||
var command = this.commandsMap[commandId]
|
const command = this.commandsMap[commandId]
|
||||||
return command != null ? command.click(event, BrowserWindow.getFocusedWindow()) : undefined
|
if (command == null) return
|
||||||
|
|
||||||
|
command.click(event, BrowserWindow.getFocusedWindow(), webContents.getFocusedWebContents())
|
||||||
},
|
},
|
||||||
menuWillShow: () => {
|
menuWillShow: () => {
|
||||||
// Make sure radio groups have at least one menu item seleted.
|
// Make sure radio groups have at least one menu item seleted.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue