Parameter in menu builder for tray

This commit is contained in:
TC
2021-03-31 22:35:01 +02:00
parent 3fe793cd4d
commit be651ebb4b
3 changed files with 71 additions and 66 deletions

23
menu.js
View File

@ -20,7 +20,12 @@ const pluginEnabledMenu = (plugin, label = "") => ({
},
});
const mainMenuTemplate = (win, withRoles = true, clickCb = () => {}) => [
const mainMenuTemplate = (
win,
withRoles = true,
isTray = false,
clickCb = () => {}
) => [
{
label: "Plugins",
submenu: [
@ -200,6 +205,8 @@ const mainMenuTemplate = (win, withRoles = true, clickCb = () => {}) => [
},
],
},
...(!isTray
? [
{
label: "View",
submenu: withRoles
@ -228,13 +235,17 @@ const mainMenuTemplate = (win, withRoles = true, clickCb = () => {}) => [
{
label: "Zoom In",
click: () => {
win.webContents.setZoomLevel(win.webContents.getZoomLevel() + 1);
win.webContents.setZoomLevel(
win.webContents.getZoomLevel() + 1
);
},
},
{
label: "Zoom Out",
click: () => {
win.webContents.setZoomLevel(win.webContents.getZoomLevel() - 1);
win.webContents.setZoomLevel(
win.webContents.getZoomLevel() - 1
);
},
},
{
@ -245,6 +256,8 @@ const mainMenuTemplate = (win, withRoles = true, clickCb = () => {}) => [
},
],
},
]
: []),
{
label: "Navigation",
submenu: [
@ -271,12 +284,16 @@ const mainMenuTemplate = (win, withRoles = true, clickCb = () => {}) => [
app.quit();
},
},
...(!isTray
? [
{
label: "Quit App",
click: () => {
app.quit();
},
},
]
: []),
],
},
];

View File

@ -20,7 +20,7 @@ module.exports = (win) => {
return;
}
done = true;
let template = mainMenuTemplate(win, false, (item) => {
let template = mainMenuTemplate(win, false, false, (item) => {
checkCheckbox(win, item);
});
let menu = Menu.buildFromTemplate(template);

14
tray.js
View File

@ -57,7 +57,7 @@ module.exports.setUpTray = (app, win) => {
win.show();
},
},
...mainMenuTemplate(win),
...mainMenuTemplate(win, true, true),
{
label: "Quit",
click: () => {
@ -66,18 +66,6 @@ module.exports.setUpTray = (app, win) => {
},
];
// delete quit button from navigation submenu
let navigation = getIndex(template,'Navigation');
let quit = getIndex(template[navigation].submenu,'Quit App');
delete template[navigation].submenu[quit];
// delete View submenu (all buttons are useless in tray)
delete template[getIndex(template, 'View')];
const trayMenu = Menu.buildFromTemplate(template);
tray.setContextMenu(trayMenu);
};
function getIndex(arr,label) {
return arr.findIndex(item => item.label === label)
}