Now that the minimal system tray menu is up and running, let's provide keyboard support. You can use any key combination of your choice; for example, try Cmd + Alt + Shift + S for macOS or Ctrl + Alt + Shift + S for Linux and Windows. Let's get started:
- First, import globalShortcut from the Electron framework, as shown in the following code:
const { app, BrowserWindow, Menu, Tray,
globalShortcut } = require('electron');
- As you already know, you can provide and render keyboard combinations by utilizing the accelerator property of the menu item:
function createTray() {
const iconPath = path.join(__dirname, 'assets/icon.png');
tray = new Tray(iconPath);
const contextMenu = Menu.buildFromTemplate([
{
label: 'Show',
type...