Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shortcuts in Electron on Mac

Well, I have quite a simple task, which can't be really hard. I have an app, which uses the electron framework to use the application on Windows and Mac machines. I notices that I am able to use Ctrl+c/Ctrl+v on Windows without any problems, but I am not able to use Cmd+c/Cmd+v on Mac after I used the electron-packager.

I found solutions like this (CMD + C / CMD + V not working), but I have a custom menue and I don't want to define and use the one in electron itself. So I found this (global accelerators without menue, but the issue is still open and there seems to be no solution. Solutions like this (Local-Shortcut) are also not usable, as they don't get the selected text (e.g. from a textbox) as a parameter.

I think using Cmd+c / Cmd+v shouldn't be a real issue, since it is a common action in every application, but I don't see a usable solution at the moment. This also effects all other shortcuts like Cmd+a to select everything.

like image 433
thardes2 Avatar asked Jun 28 '17 08:06

thardes2


People also ask

How do you do hotkeys on a Mac?

To use a keyboard shortcut, press and hold one or more modifier keys and then press the last key of the shortcut. For example, to use Command-C (copy), press and hold the Command key, then the C key, then release both keys.

What is Ctrl E in Mac?

Control-E: Move to the end of a line or paragraph. Control-F: Move one character forward. Control-B: Move one character backward. Control-L: Center the cursor or selection in the visible area.


1 Answers

There seems to be no way of doing it if you really want to hide these shortcuts from the menu.

At the moment, the best workaround is to display the shortcuts menu on MacOS only:

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

like image 108
Yann Bertrand Avatar answered Nov 11 '22 09:11

Yann Bertrand