BrowserWindow::send = -> @webContents.send.apply @webContents, arguments
# Be compatible with old API.
+BrowserWindow::undo = -> @webContents.undo()
+BrowserWindow::redo = -> @webContents.redo()
+BrowserWindow::cut = -> @webContents.cut()
+BrowserWindow::copy = -> @webContents.copy()
+BrowserWindow::paste = -> @webContents.paste()
+BrowserWindow::selectAll = -> @webContents.selectAll()
BrowserWindow::restart = -> @webContents.reload()
BrowserWindow::getUrl = -> @webContents.getUrl()
BrowserWindow::reload = -> @webContents.reload.apply @webContents, arguments
nextCommandId = 0
+# Maps role to methods of webContents
+rolesMap =
+ undo: 'undo'
+ redo: 'redo'
+ cut: 'cut'
+ copy: 'copy'
+ paste: 'paste'
+ selectall: 'selectAll'
+ minimize: 'minimize'
+ close: 'close'
+
class MenuItem
@types = ['normal', 'separator', 'submenu', 'checkbox', 'radio']
throw new Error("Unknown menu type #{@type}") if MenuItem.types.indexOf(@type) is -1
@commandId = ++nextCommandId
- @click = =>
+ @click = (focusedWindow) =>
# Manually flip the checked flags when clicked.
@checked = !@checked if @type in ['checkbox', 'radio']
- if typeof click is 'function'
- click this, BrowserWindow.getFocusedWindow()
+ if @role and rolesMap[@role] and process.platform isnt 'darwin'
+ focusedWindow?[rolesMap[@role]]()
+ else if typeof click is 'function'
+ click this, focusedWindow
else if typeof @selector is 'string'
Menu.sendActionToFirstResponder @selector
isCommandIdVisible: (commandId) => @commandsMap[commandId]?.visible
getAcceleratorForCommandId: (commandId) => @commandsMap[commandId]?.accelerator
getIconForCommandId: (commandId) => @commandsMap[commandId]?.icon
- executeCommand: (commandId) => @commandsMap[commandId]?.click()
+ executeCommand: (commandId) =>
+ @commandsMap[commandId]?.click BrowserWindow.getFocusedWindow()
menuWillShow: =>
# Make sure radio groups have at least one menu item seleted.
for id, group of @groupsMap