electron-window-manager
electron-window-manager copied to clipboard
TypeError: Invalid Menu
I cannot seem to create a new menu. I'm getting this error:
Exception has occurred: TypeError
TypeError: Invalid Menu
at Window.create (/home/username/projects/test-app/node_modules/electron-window-manager/index.js:193:25)
at Window.open (/home/username/projects/test-app/node_modules/electron-window-manager/index.js:230:14)
at Object.open (/home/username/projects/test-app/node_modules/electron-window-manager/index.js:877:31)
at App.onReady (/home/username/projects/test-app/src/index.js:18:17)
at emitTwo (events.js:111:20)
at App.emit (events.js:194:7)
The Test App will work if I remove the menu...
Code:
windowManager.open('index', 'Test App', `file://${__dirname}/index.html`, false, {
'width': 600,
'height': 350,
'resizable': false,
'showDevTools': false,
'title': 'Test App',
'menu': {
label: 'File',
submenu: [
{
label: 'Quit',
accelerator: 'CmdOrCtrl+Q',
click: function(){app.quit();}
}
],
label: 'Developer Tools',
submenu: [
{
label: 'Toggle DevTools',
accelerator: 'CmdOrCtrl+I',
click: function(item, focusedWindow){focusedWindow.toggleDevTools();}
},
{
role: 'reload'
}
]
}
});
The issue is that electron-window-manager
passes your menu to the browser window using setMenu
. This allows you to set different menus to different windows but it is only available on Windows and Linux.
An immediate fix is to set the menu directly yourself, using something like:
const { Menu } = require('electron')
var thisWindow = winManager.createNew(win, 'Window', index.html`, win)
var template = [ ... ] // Standard electron menu setup
const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
Hope that helps.
Edit: See #60 for a possible fix.
Am having the same issue on Linux: I am trying to create a new menu for a new window.
Tried the fix above but it did not work.
error-utils.ts:14 Uncaught Error: Could not call remote method 'open'. Check that the method signature is correct. Underlying error: Invalid Menu Underlying stack: TypeError: Invalid Menu
windowManager.templates.set('read', {
'width': 800,
'height': 600,
'position': 'topLeft',
'showDevTools': false,
'resizable': true,
'title': 'Load',
'menu': {
label: 'Read',
submenu: [
{ role: 'quit' }
]
},
'webPreferences': {
// preload: path.join(__dirname, 'preload.js'),
'nodeIntegration': true
},
readwin = windowManager.createNew('readwin', 'Read eeprom', path.join('file://', __dirname, '/read.html'), 'read')