|
Size: 636
Comment:
|
Size: 1060
Comment:
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 43: | Line 43: |
| For a platform-specific conditional menu, try: {{{ const { app, BrowserWindow, menu } = require("electron"); const isMac = process.platform === 'darwin'; const template = [ ...(isMac ? [{ label: app.name, submenu: [ { role: 'about' }, { role: 'quit' } ] }] : []), { label: 'File', submenu: [ isMac ? { role: 'close' } : { role: 'quit' } ] } ]; }}} |
Electron Menu
Contents
Usage
const { app, BrowserWindow, menu, shell } = require("electron");
const template = [
{
label: 'File',
submenu: [
{
label: 'Exit',
click() {
app.quit()
}
}
]
},
{
label: 'Help',
submenu: [
{
label: 'Learn More',
click: async () => {
await shell.openExternal('https://example.org');
}
}
]
}
];
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);For a platform-specific conditional menu, try:
const { app, BrowserWindow, menu } = require("electron");
const isMac = process.platform === 'darwin';
const template = [
...(isMac ? [{
label: app.name,
submenu: [
{ role: 'about' },
{ role: 'quit' }
]
}] : []),
{
label: 'File',
submenu: [
isMac ? { role: 'close' } : { role: 'quit' }
]
}
];