electron-default-menu icon indicating copy to clipboard operation
electron-default-menu copied to clipboard

Results in completely blank menu.

Open trusktr opened this issue 7 years ago • 1 comments

Why I try to use this, the menu is completely blank:

screen shot 2018-06-27 at 1 46 46 pm

I am doin it like this:

app.on( 'ready', () => {

	// Set a default menu, see https://github.com/carter-thaxton/electron-default-menu
	const menu = defaultMenu(app, shell);
	Menu.setApplicationMenu(Menu.buildFromTemplate(menu));

} )

The only menu option when I try this is Electron > quit and nothing else.

I'm on Electron 1.7.11.

trusktr avatar Jun 27 '18 20:06 trusktr

I had the same result the first time I tried to add a custom menu to Electron and for the life of me could not figure out what was causing the problem. Eventually, I got it working and here is the how it is set up and working for me now.

import { app, BrowserWindow, Menu, shell, dialog } from 'electron'
import defaultMenu from 'electron-default-menu';

function createWindow() {
  // Get template for default menu
  /**
   * Initial window options
   */
  mainWindow = new BrowserWindow({
    height: 563,
    useContentSize: true,
    width: 1000,
  });

  mainWindow.loadURL(winURL);

  mainWindow.on('closed', () => {
    mainWindow = null;
  });

  const menu = defaultMenu(app, shell);

  // Add custom menu
  menu.splice(4, 0, {
    label: 'Custom Menu',
    submenu: [
      {
        label: 'Custom Action',
        click: () => {
          dialog.showMessageBox({
            message: 'You just performed a custom action',
            buttons: ['OK'],
          });
        },
      },
    ],
  });

  // Set top-level application menu, using modified template
  Menu.setApplicationMenu(Menu.buildFromTemplate(menu));
}

app.on('ready', createWindow);

agirorn avatar Apr 22 '19 15:04 agirorn