question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Menu problem in MAC OS [FIXED]

See original GitHub issue

EDIT :: OK I fixed the problem, but it is really not clear in Electron doc, so I let the solution here (there are comments in stackoverflow’s post https://stackoverflow.com/questions/40440666/native-menus-not-showing-os-x-electron)

See edit. Tried that originally, still no app menu. – thephpdev Nov 6 '16 at 10:44
1
@thephpdev You have to call Menu.setApplicationMenu() after the app is ready, so move that call into createWindow(). – Vadim Macagon Nov 6 '16 at 10:53
I see. I feel a bit thick now, I thought I'd tried that, but I realise now that I called mainWindow.setMenu(). I'm new to electron, this is my first electron app, in case you're interested. github.com/CaelanStewart/Mathulator – thephpdev Nov 6 '16 at 11:34
Totally worked. – meriadec Apr 11 '17 at 21:20

Hello Everybody

I can’t have the menu I want. I’m creating a new project from scratch. I just adding to src/main/index.js the code from the official electron site :

const {app, Menu} = require('electron')
  
  const template = [
    {
      label: 'Edit',
      submenu: [
        {role: 'undo'},
        {role: 'redo'},
        {type: 'separator'},
        {role: 'cut'},
        {role: 'copy'},
        {role: 'paste'},
        {role: 'pasteandmatchstyle'},
        {role: 'delete'},
        {role: 'selectall'}
      ]
    },
    {
      label: 'View',
      submenu: [
        {role: 'reload'},
        {role: 'forcereload'},
        {role: 'toggledevtools'},
        {type: 'separator'},
        {role: 'resetzoom'},
        {role: 'zoomin'},
        {role: 'zoomout'},
        {type: 'separator'},
        {role: 'togglefullscreen'}
      ]
    },
    {
      role: 'window',
      submenu: [
        {role: 'minimize'},
        {role: 'close'}
      ]
    },
    {
      role: 'help',
      submenu: [
        {
          label: 'Learn More',
          click () { require('electron').shell.openExternal('https://electronjs.org') }
        }
      ]
    }
  ]
  
  if (process.platform === 'darwin') {
    template.unshift({
      label: app.getName(),
      submenu: [
        {role: 'about'},
        {type: 'separator'},
        {role: 'services', submenu: []},
        {type: 'separator'},
        {role: 'hide'},
        {role: 'hideothers'},
        {role: 'unhide'},
        {type: 'separator'},
        {role: 'quit'}
      ]
    })
  
    // Edit menu
    template[1].submenu.push(
      {type: 'separator'},
      {
        label: 'Speech',
        submenu: [
          {role: 'startspeaking'},
          {role: 'stopspeaking'}
        ]
      }
    )
  
    // Window menu
    template[3].submenu = [
      {role: 'close'},
      {role: 'minimize'},
      {role: 'zoom'},
      {type: 'separator'},
      {role: 'front'}
    ]
  }
  
  const menu = Menu.buildFromTemplate(template)
  Menu.setApplicationMenu(menu)

And I clearly dont have it :

screen shot 2018-03-31 at 12 57 31 pm

The menu is working for linux. Is this a bug or am I doing something wrong ??

Thank you

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:9

github_iconTop GitHub Comments

8reactions
bchellingworthcommented, May 1, 2019

So after some research it seems that on mac, the name of the first menu is the name of the application, since the application you are using (at least to start with) is simply ‘Electron’ thats what the first menu items gets called (this is the OS doing this).

Once you package your project for distribution and give it a name, e.g. ‘myApp’ you will see this menu item change to ‘myApp’

It would seem you cannot have the first item being ‘File’ or whatever on mac. Once I read this it became quite obvious since every other application in mac OS behaves the same.

3reactions
cjstagecommented, May 1, 2019

This does work, yet its not adding an edit menu. But i adds all to main app menu.

Try adding to the template object array like this:

Menu.setApplicationMenu(Menu.buildFromTemplate([
    {
      label: app.getName(),
      submenu: [
        { role: 'about' },
        { type: 'separator' },
        { role: 'services' },
        { type: 'separator' },
        { role: 'hide' },
        { role: 'hideothers' },
        { role: 'unhide' },
        { type: 'separator' },
        { role: 'quit' }
      ]
    },
    {
      label: 'Edit',
      submenu: [
        { role: 'undo' },
        { role: 'redo' },
        { type: 'separator' },
        { role: 'cut' },
        { role: 'copy' },
        { role: 'paste' },
        { role: 'pasteandmatchstyle' },
        { role: 'delete' },
        { role: 'selectall' },
        { type: 'separator' },
        { role: 'reload' },
        { role: 'toggleFullScreen' },
        { role: 'toggleDevTools' },
        { type: 'separator' },
        { role: 'quit' }
      ]
    }
  ]));
`
This worked in my project.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Does anyone know how to fix the menu bar - Apple Discussions
Does anyone know how to fix the menu bar being halfway on the screen? My menu bar is halfway off my screen and...
Read more >
How to Fix 'Application menu bar not responding' Problem on ...
1. Restart your Mac · 2. Roll Back to Default Resolution · 3. Force Quit Application · 4. SystemUIServer Restart · 5. Remove...
Read more >
How to Fix a Disappearing Menu Bar on a Mac - Macdentro.com
Here is a simple way to enable or disable the “Automatically hide and show the menu bar” option. Press Control+ F2 key together...
Read more >
Top Menu Bar Does Not Show Up on Mac Monterey, How to ...
Fix 1: Disable Automatically hide and show the menu bar · Click the Apple logo, from the drop-down menu, and select System Preferences....
Read more >
How to troubleshoot a frozen menu bar - Macworld
To do so, open the Activity Monitor utility, choose All Processes from the View menu, and then select the SystemUIServer process and click...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found