Max P
Max P

Reputation: 1459

How to add menuItem from renderer process (browser window)

I'm try out to do this with remote, but can't understand how it works =(

What I need to do: 1) ajax call to server (ok) 2) server response with 'issue123' (ok) 3) add 'issue123' in OS X standard menubar (how ?)

I create menuItem - Issues, and it's work correctly on loading app, but how I can push 'issue123' to this menu?

Upvotes: 1

Views: 666

Answers (2)

Max P
Max P

Reputation: 1459

Ohhh... it's not easy for first time ;)

For example: ...

const trackerMenu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(trackerMenu);

const issuesMenu = trackerMenu.items[4]; //save your submenu item

...

success: function(data) { //my ajax callback

   let menuItem = new MenuItem({
     label: data,
     click: function(item, focusedWindow) {
       console.log(item)
     }
   })

   issuesMenu.submenu.insert(0, menuItem);
   Menu.setApplicationMenu(trackerMenu);
}

Upvotes: 0

Vadim Macagon
Vadim Macagon

Reputation: 14837

After you add or remove a menu item in your menu you need to call Menu.setApplicationMenu() or BrowserWindow.setMenu() again to rebuild the native menu. However, there is no need to call the aforementioned methods again if you modify the enabled, visible, or checked properties on a menu item.

Sources:

Upvotes: 3

Related Questions