Reputation: 1792
I am using the custom-electron-titlebar
module in order to create a customized titlebar. I am trying to change the items in the menu as shown in the documentation:
However, when i try to mimic the code shown above, it throws me an error while running the app:
Error :
Uncaught TypeError: Menu is not a constructor
Here is my code :
const { customTitlebar, Menu, Titlebar, Color, MenuItem } = require('custom-electron-titlebar');
titleBar = new Titlebar({
backgroundColor: Color.fromHex('#282a36'),
minimizable: false,
itemBackgroundColor: Color.fromHex('#44475a'),
})
const menu = new Menu();
menu.append(new MenuItem({
label: 'Item 1',
submenu: [
{
label: 'Subitem 1',
click: () => console.log('Click on subitem 1')
},
{
type: 'separator'
}
]
}));
console.log(menu)
titleBar.updateMenu(menu)
How do I fix this issue? I want to have customised menu-bar instead of the default ones!
Thanks a lot for you help!
Upvotes: 3
Views: 1526
Reputation: 3517
You're trying to import Menu
and MenuItem
from the module custom-electron-titlebar
, but the package documentation says one should use remote.Menu
and remote.MenuItem
.
The reason why you're getting this exact error message is that in your code, Menu
is undefined
, because the package does not provide it. Consequently, trying to use it as a constructor fails.
To use the remote
module in the renderer process, you'll need to set enableRemoteModule
when creating the corresponding BrowserWindow
.
const { remote } = require('electron')
const { Menu, MenuItem } = remote
If you're working on the menus in the main process, it is easier:
const { Menu, MenuItem } = require('electron');
Upvotes: 2