Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Electron Browser Window Prevent Control+W closing window

I have an electron js app with Angular 8. If the user performs the command control+w, it automatically closes the window. I try looking through the BrowserWindow Api, however, I couldn't find a flag or handler to prevent this behavior from happening.

like image 691
Monkeyonawall Avatar asked May 10 '26 07:05

Monkeyonawall


1 Answers

You need to change or remove the default application menu which has this shortcut Window -> Close Ctrl+W by default

Menu.setApplicationMenu(null) // remove default application menu

// or

browserWindow.setMenu(null) // just remove default menu of a specific window and not all windows

This should do the trick

Relevant docs:

  • Menu.setApplicationMenu(menu)
  • win.setMenu(menu)
like image 91
aabuhijleh Avatar answered May 13 '26 01:05

aabuhijleh