Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

electron-default-menu

1.0.1 • Public • Published

electron-default-menu

A simple module that returns a default Electron menu template, similar to the one you'll get if you don't use Menu.setApplicationMenu() at all. You can modify the returned template before creating the application menu.

Based on the sample code supplied in the Electron menu documentation

Like the sample code, it checks the environment, and returns appropriate additional menus for Mac OS X, and sets the role for each menu accordingly.

Must be used from the Electron environment.

Example usage:

import electron from 'electron';
const defaultMenu = require('electron-default-menu');
const { Menu, app, shell } = electron;
const dialog = require('dialog');
 
app.on('ready', () => {
 
  // Get template for default menu
  const menu = defaultMenu(app, shell);
 
  // Add custom menu
  menu.splice(4, 0, {
    label: 'Custom',
    submenu: [
      {
        label: 'Do something',
        click: (item, focusedWindow) => {
          dialog.showMessageBox({message: 'Do something', buttons: ['OK'] })
        }
      }
    ]
  })
 
  // Set top-level application menu, using modified template
  Menu.setApplicationMenu(Menu.buildFromTemplate(menu));
})
 

Keywords

Install

npm i electron-default-menu

DownloadsWeekly Downloads

1,300

Version

1.0.1

License

ISC

Last publish

Collaborators

  • avatar