Shortcuts in Electron on Mac

Well, I have a pretty simple task that cannot be very difficult. I have an application that uses electronic infrastructure to use the application on Windows and Mac computers. I notice that I can use Ctrl + c / Ctrl + v for Windows without any problems, but I cannot use Cmd + c / Cmd + v on a Mac after I used electron-packager .

I found solutions like this (CMD + C / CMD + V does not work) , but I have a custom menu, and I don’t want to define and use it in the element itself. So I found this (global accelerators without menue ), but the problem is still open and there seems to be no solution. Solutions such as this one (Local-Shortcut) are also unusable because they do not receive the selected text (for example, from a text field) as a parameter.

I think that using Cmd + c / Cmd + v should not be a real problem, since this is a common action in every application, but at the moment I do not see a useful solution. It also affects all other shortcuts, such as Cmd + a, to select everything.

+6
source share
1 answer

There seems to be no way to do this if you really want to hide these shortcuts from the menu.

Currently, the best solution is to display the shortcut menu only on MacOS:

const { Menu } = require('electron')

const menuTemplate = [...];

if (process.platform === 'darwin') {
  menuTemplate.push({
    label: 'Edit',
    submenu: [
      {role: 'undo'},
      {role: 'redo'},
      {type: 'separator'},
      {role: 'cut'},
      {role: 'copy'},
      {role: 'paste'},
      {role: 'pasteandmatchstyle'},
      {role: 'delete'},
      {role: 'selectall'}
    ]
  })
}

const applicationMenu = Menu.buildFromTemplate(menuTemplate)
Menu.setApplicationMenu(applicationMenu)

https://blog.avocode.com/blog/4-must-know-tips-for-building-cross-platform-electron-apps

+1
source

All Articles