4

Goal

I'm trying to remove the Help menu from Electron app's menu.

I don't want to setApplicationMenu of my own because it's fine to use the default menu except for the help, which points to Electron's own help pages.

Attempts

I've tried the following ways and failed in each case:

Remove the tail item, i.e., the Help

var menu = Menu.getApplicationMenu();
menu.items.pop();

Make it invisible

var menu = Menu.getApplicationMenu();
for(var i=0; i<menu.items.length; i++) {
    if (menu.items[i].role == 'help') {
       menu.items[i].visible = false;
       break;
    }
}

Remove the menu

mainWindow.removeMenu();

This just doesn't work on macOS with my electron version: 10.1.0.

Question

What's wrong? Should I create a template instead?

kakyo
  • 10,460
  • 14
  • 76
  • 140

2 Answers2

5

You must use Menu.setApplicationMenu after you modify the default menu

const menu = Menu.getApplicationMenu(); // get default menu

menu.items.find((item) => item.role === "help").visible = false; // modify it

Menu.setApplicationMenu(menu); // set the modified menu

Note: From my experience, Menu.getApplicationMenu() will return null if it's called before the app ready event

aabuhijleh
  • 2,214
  • 9
  • 25
5

menuItem.visible does not work in Electron 13. Instead, I build a new menu without the Help item.

  const menu = Menu.getApplicationMenu()
  const items = menu?.items.filter((item) => item.role !== 'help')
  Menu.setApplicationMenu(Menu.buildFromTemplate(items))
Hung Tran
  • 1,595
  • 2
  • 17
  • 17