I would like to add a quit submenu item under the File menu item in my Electron JS app, but only on Windows and Linux. On Mac, I already have set up a Quit submenu item under the app name menu item. Currently, this is my code:
function createMenu(){
const isMac = process.platform === 'darwin';
const menu = [
{
label: "File",
submenu: [
{
label: 'Add expense',
},
!isMac && {
label: 'Quit',
click(){
app.quit()
},
accelerator: 'Ctrl+Q'
}
]
},
{
label: "Menu2",
submenu: [{label: 'Ok'}]
}
];
// Mac First Item in Template refers to app name (won't be able to override unless you package application)
isMac && menu.unshift({
label: app.name,
submenu: [
{
label: 'About',
click(){
open('https://www.google.com') // Using the open package
}
},
{
label: 'Quit',
click(){
app.quit()
},
accelerator: 'Cmd+Q'
}
]
})
return menu;
}
When I run this, however, I get an error saying
TypeError: Invalid template for MenuItem: must have at least one of label, role or type
How should I go about doing this?
Thank you!