2020-07-13 19:58:49 +03:00
|
|
|
import { shell } from 'electron/common';
|
2024-10-03 05:10:44 +03:00
|
|
|
import { app, Menu } from 'electron/main';
|
2019-01-10 22:54:34 +03:00
|
|
|
|
2019-01-10 16:32:03 +03:00
|
|
|
const isMac = process.platform === 'darwin';
|
|
|
|
|
2021-06-03 08:59:56 +03:00
|
|
|
let applicationMenuWasSet = false;
|
|
|
|
|
|
|
|
export const setApplicationMenuWasSet = () => {
|
|
|
|
applicationMenuWasSet = true;
|
|
|
|
};
|
|
|
|
|
2019-02-12 17:22:33 +03:00
|
|
|
export const setDefaultApplicationMenu = () => {
|
2021-06-03 08:59:56 +03:00
|
|
|
if (applicationMenuWasSet) return;
|
2018-09-21 08:24:42 +03:00
|
|
|
|
2019-02-12 17:22:33 +03:00
|
|
|
const helpMenu: Electron.MenuItemConstructorOptions = {
|
2019-01-10 16:32:03 +03:00
|
|
|
role: 'help',
|
2024-09-26 10:12:11 +03:00
|
|
|
submenu: app.isPackaged
|
|
|
|
? []
|
|
|
|
: [
|
|
|
|
{
|
|
|
|
label: 'Learn More',
|
|
|
|
click: async () => {
|
|
|
|
await shell.openExternal('https://electronjs.org');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Documentation',
|
|
|
|
click: async () => {
|
|
|
|
const version = process.versions.electron;
|
|
|
|
await shell.openExternal(`https://github.com/electron/electron/tree/v${version}/docs#readme`);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Community Discussions',
|
|
|
|
click: async () => {
|
|
|
|
await shell.openExternal('https://discord.gg/electronjs');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Search Issues',
|
|
|
|
click: async () => {
|
|
|
|
await shell.openExternal('https://github.com/electron/electron/issues');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2018-09-21 08:24:42 +03:00
|
|
|
};
|
|
|
|
|
2019-02-12 17:22:33 +03:00
|
|
|
const macAppMenu: Electron.MenuItemConstructorOptions = { role: 'appMenu' };
|
|
|
|
const template: Electron.MenuItemConstructorOptions[] = [
|
|
|
|
...(isMac ? [macAppMenu] : []),
|
2019-01-10 16:32:03 +03:00
|
|
|
{ role: 'fileMenu' },
|
|
|
|
{ role: 'editMenu' },
|
|
|
|
{ role: 'viewMenu' },
|
|
|
|
{ role: 'windowMenu' },
|
|
|
|
helpMenu
|
|
|
|
];
|
|
|
|
|
2018-09-21 08:24:42 +03:00
|
|
|
const menu = Menu.buildFromTemplate(template);
|
|
|
|
Menu.setApplicationMenu(menu);
|
|
|
|
};
|