How to configure the application menu in electronic?

if I run the electron-quick-start application, I get the full OSX menu:

enter image description here

Then I add this code, mostly copied from documents, 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 using the menu template code from the electronic menus , with the same disappointing result:

enter image description here

I also tried adding the code above to index.html, literally copying the code to the doc menu. Same.

Any idea what is wrong?

+5
source share
1 answer

electron-prebuilt , which he used in the electron-quick-start example, has its own application name (Electron).

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

There is also a method for installing / getting the name of the application, but you need to pack the application to see this change in the main menu:

 const electron = require('electron'); const app = electron.app; app.setName('APPNAME'); 
+2
source

Source: https://habr.com/ru/post/1245455/


All Articles