AlexTorresDev / custom-electron-titlebar

Custom electon title bar inpire on VS Code title bar
MIT License
868 stars 149 forks source link

Menubar without menu throws error on ALT button #109

Closed Christilut closed 3 years ago

Christilut commented 4 years ago

Describe the bug Pressing the ALT button without a menu throws an error:

event.js:469 TypeError: Cannot read property 'buttonElement' of undefined
    at Menubar.set focusState [as focusState] (menubar.js:319)
    at Menubar.onModifierKeyToggled (menubar.js:450)
    at ModifierKeyEmitter.fire (event.js:465)
    at menubar.js:568
    at Emitter.fire (event.js:462)
    at HTMLBodyElement.fn (event.js:10)

To Reproduce This is my menubar, basically empty:

const { Menu, app } = require('electron').remote

const menu = Menu.buildFromTemplate([
  ...(isMac
    ? [
        {
          label: app.getName(),
          submenu: [{ role: 'hide', label: 'Hide' }, { role: 'hideothers' }, { role: 'unhide' }, { type: 'separator' }, { role: 'quit', label: 'Quit' }]
        }
      ]
    : [])
])

const titlebar = new Titlebar({ // eslint-disable-line
  backgroundColor: Color.fromHex('#363636'),
  closeable: true,
  menu
})

Then press ALT anywhere in the app to throw an error in the console.

Desktop (please complete the following information): Windows 10 "custom-electron-titlebar": "^3.2.5" "electron": "10.1.5"

AlexTorresDev commented 3 years ago

You should set menu like:

const titlebar = new Titlebar({ // eslint-disable-line
  backgroundColor: Color.fromHex('#363636'),
  closeable: true,
  menu: menu // or menu: null
})

this is a title bar without menu and doesn't show error.

Christilut commented 3 years ago

Thanks!