I want to force the user only be allowed to quit the app from the Menu or Tray icon. I have those configured and working, but every time I hit Cmd+W or Cmd+Q it exits the app...
I tried catching it with:
app.on('quit', e => e.preventDefault())
app.on('window-all-closed', e => e.preventDefault())
...but it doesn't seem to have any effect.
You can use Menu module to override the shortcut as below:
const { Menu, MenuItem } = require('electron')
const menu = new Menu()
menu.append(new MenuItem({
label: 'Quit',
accelerator: 'CmdOrCtrl+Q',
click: () => { console.log('Cmd + Q is pressed') }
}));
It's up to you to hide or show this menu item because 'Quit' suppose to exit the application
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With