Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Invalid Menu #47

Open
GitFlip opened this issue Oct 11, 2017 · 2 comments
Open

TypeError: Invalid Menu #47

GitFlip opened this issue Oct 11, 2017 · 2 comments

Comments

@GitFlip
Copy link

GitFlip commented Oct 11, 2017

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'
        }
      ]
    }
  });
@shibacomputer
Copy link
Contributor

shibacomputer commented Feb 24, 2018

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.

@MarcKarasek
Copy link

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')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants