electron/lib/browser/default-menu.ts

55 lines
1.5 KiB
TypeScript
Raw Normal View History

import { Menu } from 'electron/main';
import { shell } from 'electron/common';
const v8Util = process._linkedBinding('electron_common_v8_util');
2020-03-20 20:28:31 +00:00
const isMac = process.platform === 'darwin';
export const setDefaultApplicationMenu = () => {
2020-03-20 20:28:31 +00:00
if (v8Util.getHiddenValue<boolean>(global, 'applicationMenuSet')) return;
const helpMenu: Electron.MenuItemConstructorOptions = {
role: 'help',
submenu: [
{
label: 'Learn More',
click: async () => {
2020-03-20 20:28:31 +00:00
await shell.openExternal('https://electronjs.org');
}
},
{
label: 'Documentation',
click: async () => {
2020-03-20 20:28:31 +00:00
const version = process.versions.electron;
await shell.openExternal(`https://github.com/electron/electron/tree/v${version}/docs#readme`);
}
},
{
label: 'Community Discussions',
click: async () => {
2020-03-20 20:28:31 +00:00
await shell.openExternal('https://discuss.atom.io/c/electron');
}
},
{
label: 'Search Issues',
click: async () => {
2020-03-20 20:28:31 +00:00
await shell.openExternal('https://github.com/electron/electron/issues');
}
}
]
2020-03-20 20:28:31 +00:00
};
2020-03-20 20:28:31 +00:00
const macAppMenu: Electron.MenuItemConstructorOptions = { role: 'appMenu' };
const template: Electron.MenuItemConstructorOptions[] = [
...(isMac ? [macAppMenu] : []),
{ role: 'fileMenu' },
{ role: 'editMenu' },
{ role: 'viewMenu' },
{ role: 'windowMenu' },
helpMenu
2020-03-20 20:28:31 +00:00
];
2020-03-20 20:28:31 +00:00
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
};