2022-04-21 17:46:49 +02:00
|
|
|
const { Menu, app } = require("electron");
|
2019-11-03 20:22:59 +01:00
|
|
|
const { showSettingsWindow } = require("./settings");
|
|
|
|
const isMac = process.platform === "darwin";
|
2022-08-07 16:05:48 +02:00
|
|
|
const { name } = require("./../constants/values");
|
2019-11-03 20:22:59 +01:00
|
|
|
|
|
|
|
const settingsMenuEntry = {
|
|
|
|
label: "Settings",
|
|
|
|
click() {
|
|
|
|
showSettingsWindow();
|
|
|
|
},
|
2023-01-20 21:57:41 +01:00
|
|
|
accelerator: "Control+=",
|
2019-11-03 20:22:59 +01:00
|
|
|
};
|
|
|
|
|
2022-04-21 17:46:49 +02:00
|
|
|
const quitMenuEntry = {
|
|
|
|
label: "Quit",
|
|
|
|
click() {
|
|
|
|
app.exit(0);
|
|
|
|
},
|
2022-08-07 16:05:48 +02:00
|
|
|
accelerator: "Control+Q",
|
2022-04-21 17:46:49 +02:00
|
|
|
};
|
|
|
|
|
2022-08-07 16:05:48 +02:00
|
|
|
const menuModule = {};
|
|
|
|
|
|
|
|
menuModule.getMenu = function (mainWindow) {
|
|
|
|
const toggleWindow = {
|
|
|
|
label: "Toggle Window",
|
|
|
|
click: function () {
|
|
|
|
mainWindow.isVisible() ? mainWindow.hide() : mainWindow.show();
|
2019-11-03 20:22:59 +01:00
|
|
|
},
|
2022-08-07 16:05:48 +02:00
|
|
|
};
|
2019-11-03 20:22:59 +01:00
|
|
|
|
2022-08-07 16:05:48 +02:00
|
|
|
const mainMenu = [
|
|
|
|
...(isMac
|
|
|
|
? [
|
|
|
|
{
|
|
|
|
label: name,
|
|
|
|
submenu: [
|
|
|
|
{ role: "about" },
|
|
|
|
settingsMenuEntry,
|
|
|
|
{ type: "separator" },
|
|
|
|
{ role: "services" },
|
|
|
|
{ type: "separator" },
|
|
|
|
{ role: "hide" },
|
|
|
|
{ role: "hideothers" },
|
|
|
|
{ role: "unhide" },
|
|
|
|
{ type: "separator" },
|
|
|
|
quitMenuEntry,
|
|
|
|
],
|
|
|
|
},
|
|
|
|
]
|
|
|
|
: []),
|
|
|
|
{
|
|
|
|
label: "File",
|
|
|
|
submenu: [settingsMenuEntry, isMac ? { role: "close" } : quitMenuEntry],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Edit",
|
|
|
|
submenu: [
|
|
|
|
{ role: "undo" },
|
|
|
|
{ role: "redo" },
|
|
|
|
{ type: "separator" },
|
|
|
|
{ role: "cut" },
|
|
|
|
{ role: "copy" },
|
|
|
|
{ role: "paste" },
|
|
|
|
...(isMac
|
|
|
|
? [
|
|
|
|
{ role: "pasteAndMatchStyle" },
|
|
|
|
{ role: "delete" },
|
|
|
|
{ role: "selectAll" },
|
|
|
|
{ type: "separator" },
|
|
|
|
{
|
|
|
|
label: "Speech",
|
|
|
|
submenu: [{ role: "startspeaking" }, { role: "stopspeaking" }],
|
|
|
|
},
|
|
|
|
]
|
|
|
|
: [{ role: "delete" }, { type: "separator" }, { role: "selectAll" }]),
|
|
|
|
{ type: "separator" },
|
|
|
|
settingsMenuEntry,
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "View",
|
|
|
|
submenu: [
|
|
|
|
{ role: "reload" },
|
|
|
|
{ role: "forcereload" },
|
|
|
|
{ type: "separator" },
|
|
|
|
{ role: "resetzoom" },
|
|
|
|
{ role: "zoomin" },
|
|
|
|
{ role: "zoomout" },
|
|
|
|
{ type: "separator" },
|
|
|
|
{ role: "togglefullscreen" },
|
|
|
|
{ role: "toggledevtools" },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Window",
|
|
|
|
submenu: [
|
|
|
|
{ role: "minimize" },
|
|
|
|
toggleWindow,
|
|
|
|
...(isMac
|
|
|
|
? [{ type: "separator" }, { role: "front" }, { type: "separator" }, { role: "window" }]
|
|
|
|
: [{ role: "close" }]),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
settingsMenuEntry,
|
|
|
|
{
|
|
|
|
label: "About",
|
|
|
|
click() {
|
|
|
|
showSettingsWindow("about");
|
|
|
|
},
|
|
|
|
},
|
|
|
|
toggleWindow,
|
2023-01-20 22:18:25 +01:00
|
|
|
quitMenuEntry,
|
2022-08-07 16:05:48 +02:00
|
|
|
];
|
2019-11-03 20:22:59 +01:00
|
|
|
|
|
|
|
return Menu.buildFromTemplate(mainMenu);
|
|
|
|
};
|
|
|
|
|
2022-08-23 21:20:46 +02:00
|
|
|
menuModule.addMenu = function (mainWindow) {
|
|
|
|
Menu.setApplicationMenu(menuModule.getMenu(mainWindow));
|
2019-11-03 20:22:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = menuModule;
|