mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-14 11:51:47 +00:00
Parameter in menu builder for tray
This commit is contained in:
121
menu.js
121
menu.js
@ -20,7 +20,12 @@ const pluginEnabledMenu = (plugin, label = "") => ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const mainMenuTemplate = (win, withRoles = true, clickCb = () => {}) => [
|
const mainMenuTemplate = (
|
||||||
|
win,
|
||||||
|
withRoles = true,
|
||||||
|
isTray = false,
|
||||||
|
clickCb = () => {}
|
||||||
|
) => [
|
||||||
{
|
{
|
||||||
label: "Plugins",
|
label: "Plugins",
|
||||||
submenu: [
|
submenu: [
|
||||||
@ -200,51 +205,59 @@ const mainMenuTemplate = (win, withRoles = true, clickCb = () => {}) => [
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
...(!isTray
|
||||||
label: "View",
|
? [
|
||||||
submenu: withRoles
|
{
|
||||||
? [
|
label: "View",
|
||||||
{ role: "reload" },
|
submenu: withRoles
|
||||||
{ role: "forceReload" },
|
? [
|
||||||
{ type: "separator" },
|
{ role: "reload" },
|
||||||
{ role: "zoomIn" },
|
{ role: "forceReload" },
|
||||||
{ role: "zoomOut" },
|
{ type: "separator" },
|
||||||
{ role: "resetZoom" },
|
{ role: "zoomIn" },
|
||||||
]
|
{ role: "zoomOut" },
|
||||||
: [
|
{ role: "resetZoom" },
|
||||||
{
|
]
|
||||||
label: "Reload",
|
: [
|
||||||
click: () => {
|
{
|
||||||
win.webContents.reload();
|
label: "Reload",
|
||||||
},
|
click: () => {
|
||||||
},
|
win.webContents.reload();
|
||||||
{
|
},
|
||||||
label: "Force Reload",
|
},
|
||||||
click: () => {
|
{
|
||||||
win.webContents.reloadIgnoringCache();
|
label: "Force Reload",
|
||||||
},
|
click: () => {
|
||||||
},
|
win.webContents.reloadIgnoringCache();
|
||||||
{ type: "separator" },
|
},
|
||||||
{
|
},
|
||||||
label: "Zoom In",
|
{ type: "separator" },
|
||||||
click: () => {
|
{
|
||||||
win.webContents.setZoomLevel(win.webContents.getZoomLevel() + 1);
|
label: "Zoom In",
|
||||||
},
|
click: () => {
|
||||||
},
|
win.webContents.setZoomLevel(
|
||||||
{
|
win.webContents.getZoomLevel() + 1
|
||||||
label: "Zoom Out",
|
);
|
||||||
click: () => {
|
},
|
||||||
win.webContents.setZoomLevel(win.webContents.getZoomLevel() - 1);
|
},
|
||||||
},
|
{
|
||||||
},
|
label: "Zoom Out",
|
||||||
{
|
click: () => {
|
||||||
label: "Reset Zoom",
|
win.webContents.setZoomLevel(
|
||||||
click: () => {
|
win.webContents.getZoomLevel() - 1
|
||||||
win.webContents.setZoomLevel(0);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
{
|
||||||
},
|
label: "Reset Zoom",
|
||||||
|
click: () => {
|
||||||
|
win.webContents.setZoomLevel(0);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: []),
|
||||||
{
|
{
|
||||||
label: "Navigation",
|
label: "Navigation",
|
||||||
submenu: [
|
submenu: [
|
||||||
@ -271,12 +284,16 @@ const mainMenuTemplate = (win, withRoles = true, clickCb = () => {}) => [
|
|||||||
app.quit();
|
app.quit();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
...(!isTray
|
||||||
label: "Quit App",
|
? [
|
||||||
click: () => {
|
{
|
||||||
app.quit();
|
label: "Quit App",
|
||||||
},
|
click: () => {
|
||||||
},
|
app.quit();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: []),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@ -20,7 +20,7 @@ module.exports = (win) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
done = true;
|
done = true;
|
||||||
let template = mainMenuTemplate(win, false, (item) => {
|
let template = mainMenuTemplate(win, false, false, (item) => {
|
||||||
checkCheckbox(win, item);
|
checkCheckbox(win, item);
|
||||||
});
|
});
|
||||||
let menu = Menu.buildFromTemplate(template);
|
let menu = Menu.buildFromTemplate(template);
|
||||||
|
|||||||
14
tray.js
14
tray.js
@ -57,7 +57,7 @@ module.exports.setUpTray = (app, win) => {
|
|||||||
win.show();
|
win.show();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
...mainMenuTemplate(win),
|
...mainMenuTemplate(win, true, true),
|
||||||
{
|
{
|
||||||
label: "Quit",
|
label: "Quit",
|
||||||
click: () => {
|
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);
|
const trayMenu = Menu.buildFromTemplate(template);
|
||||||
tray.setContextMenu(trayMenu);
|
tray.setContextMenu(trayMenu);
|
||||||
};
|
};
|
||||||
|
|
||||||
function getIndex(arr,label) {
|
|
||||||
return arr.findIndex(item => item.label === label)
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user