Change your own menu on an electronic application

the electronic application is open with the same default menu that appears in the application of the example of quick launch of e-mail, and I do not know how to change it. I also tried the example menu in the docs , but nothing has changed. when I hide the menu with mainWindow.setMenu(null); , the menu is gone, but I still can not start a new menu

any ideas?

Platform

: windows 7

electron ver: 0.36.4

ref files:

package.json:

 { "name": "electric_timer", "version": "0.1.0", "description": "a Time sheet & project managment", "main": "app.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", "url": "none" }, "author": "Eyal Ron", "license": "MIT" } 

app.js:

 var app = require('app'); var BrowserWindow = require('browser-window'); app.on('ready', function (){ var mainWindow = new BrowserWindow({ width: 800, height: 600 }); mainWindow.setMenu(null); mainWindow.loadUrl('file://' + __dirname + '/main.html'); }); 

main.js:

 var remote = require('remote'); var Menu = remote.require('menu'); var menu = Menu.buildFromTemplate([ { label: 'Electron', submenu: [ { label: 'Prefs', click: function(){ alert('hello menu'); } } ] } ]); Menu.setApplicationMenu(menu); 

main.html:

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>electron test</title> </head> <body> <h1>hello world</h1> <script>requier('./main.js')</script> </body> </html> 
+7
menu electron
source share
1 answer

Electron 'default_app' sets the menu ; if you want to avoid this, you need Electron to run your application directly not through the default application (note: if you run your application with something like electron . , you really will start the application by default).

The electron searches in its folder for resources for applications, appasas or default_app applications, so in order to start directly from your application, you need to either copy it or copy it to the Electron resources folder.

No matter how you start your application, you can customize your menu using Menu.setApplicationMenu - you can do this in the main process, you do not need to do this in Renderer, as in your example. By the way, there is a typo in your main.html (required, not required), therefore, if your actual code indicates that your main.js is not starting at all.

+7
source share

All Articles