Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up application menu in electron?

Tags:

electron

menu

if i start the electron-quick-start application, i get a full OSX menu:

enter image description here

I then add this code, mostly copied from docs, to my main.js:

const Menu = require('menu');                                                                                                                                                                            
const MenuItem = require('menu-item');
var mainmenu = new Menu();
mainmenu.append(new MenuItem({ label: 'MenuItem1', click: function() { console.log('item 1 clicked'); } }));
Menu.setApplicationMenu(mainmenu);

I also tried to use menu template code from the electron menu docs, with the exact same disappointing result:

enter image description here

I also tried to add the code above to index.html, literally copying the code on Menu's doc. Same thing.

Any idea what is wrong?

like image 778
gcb Avatar asked Mar 21 '16 05:03

gcb


1 Answers

electron-prebuilt that it's used on the electron-quick-start example has it's own app name (Electron).

To change this you need to rebuild/package your app and it will use the "name" or "productName" from your package.json.

Also there is method to set/get the app name but you have to package your app to see that change on the main menu:

const electron = require('electron');
const app = electron.app;

app.setName('APPNAME');
like image 50
Philip Avatar answered Sep 28 '22 03:09

Philip