I'm banging my head against the wall on this one. I'm trying to override the name of a demo electron app to give it a custom name instead of just Electron
. I created a module for doing this:
const {app, Menu} = require('electron')
const template = [
{
label: 'New Name',
submenu:[
{
label: 'Test',
click: (menuItem, browserWindow, event) => {
console.log('menu item clicked')
}
},
{role: 'quit'}
]
},
{
label: 'test test',
submenu:[
{
label: 'Test',
click: (menuItem, browserWindow, event) => {
console.log('menu item clicked')
}
},
{role: 'quit'}
]
}
]
installApplicationMenu = function (){
const menu = Menu.buildFromTemplate(template)
let result = Menu.setApplicationMenu(menu)
}
module.exports = {
installApplicationMenu
}
And I'm invoking this module after creating my window:
const {app, BrowserWindow} = require('electron')
const path = require('path')
const url = require('url')
const {installApplicationMenu} = require('./MenuInstaller')
require('electron-reload')(__dirname,{
electron: path.join(__dirname, 'node_modules', '.bin', 'electron')
})
let win
function createWindow(){
win = new BrowserWindow({
width: 800,
height: 600
})
win.loadURL(
url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
})
)
win.on('closed', () => {
win = null
})
}
app.on('ready', function (){
createWindow()
installApplicationMenu()
})
app.on('activate', () => {
if(win === null) createWindow()
})
When I do this the second menu set gets it's custom name of test test
but the main menu name is still Electron
:
I've been comparing the code to a different app I created where I was able to override the default name and I can't spot what's keeping the override from working in this case.
Any ideas?