2020-07-13 16:58:49 +00:00
|
|
|
import { Menu } from 'electron/main';
|
|
|
|
import { shell } from 'electron/common';
|
2019-01-10 19:54:34 +00:00
|
|
|
|
2020-06-23 03:32:45 +00:00
|
|
|
const v8Util = process._linkedBinding('electron_common_v8_util');
|
2018-09-21 05:24:42 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const isMac = process.platform === 'darwin';
|
2019-01-10 13:32:03 +00:00
|
|
|
|
2019-02-12 14:22:33 +00:00
|
|
|
export const setDefaultApplicationMenu = () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
if (v8Util.getHiddenValue<boolean>(global, 'applicationMenuSet')) return;
|
2018-09-21 05:24:42 +00:00
|
|
|
|
2019-02-12 14:22:33 +00:00
|
|
|
const helpMenu: Electron.MenuItemConstructorOptions = {
|
2019-01-10 13:32:03 +00:00
|
|
|
role: 'help',
|
|
|
|
submenu: [
|
|
|
|
{
|
|
|
|
label: 'Learn More',
|
2019-05-03 20:53:45 +00:00
|
|
|
click: async () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
await shell.openExternal('https://electronjs.org');
|
2018-09-21 05:24:42 +00:00
|
|
|
}
|
2019-01-10 13:32:03 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Documentation',
|
2019-05-03 20:53:45 +00:00
|
|
|
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`);
|
2018-09-21 05:24:42 +00:00
|
|
|
}
|
2019-01-10 13:32:03 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Community Discussions',
|
2019-05-03 20:53:45 +00:00
|
|
|
click: async () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
await shell.openExternal('https://discuss.atom.io/c/electron');
|
2018-09-21 05:24:42 +00:00
|
|
|
}
|
2019-01-10 13:32:03 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Search Issues',
|
2019-05-03 20:53:45 +00:00
|
|
|
click: async () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
await shell.openExternal('https://github.com/electron/electron/issues');
|
2018-09-21 05:24:42 +00:00
|
|
|
}
|
2019-01-10 13:32:03 +00:00
|
|
|
}
|
|
|
|
]
|
2020-03-20 20:28:31 +00:00
|
|
|
};
|
2018-09-21 05:24:42 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const macAppMenu: Electron.MenuItemConstructorOptions = { role: 'appMenu' };
|
2019-02-12 14:22:33 +00:00
|
|
|
const template: Electron.MenuItemConstructorOptions[] = [
|
|
|
|
...(isMac ? [macAppMenu] : []),
|
2019-01-10 13:32:03 +00:00
|
|
|
{ role: 'fileMenu' },
|
|
|
|
{ role: 'editMenu' },
|
|
|
|
{ role: 'viewMenu' },
|
|
|
|
{ role: 'windowMenu' },
|
|
|
|
helpMenu
|
2020-03-20 20:28:31 +00:00
|
|
|
];
|
2019-01-10 13:32:03 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const menu = Menu.buildFromTemplate(template);
|
|
|
|
Menu.setApplicationMenu(menu);
|
|
|
|
};
|