electron-default-menu
electron-default-menu copied to clipboard
Results in completely blank menu.
Why I try to use this, the menu is completely blank:
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.
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);