mirror of
https://github.com/Mastermindzh/tidal-hifi.git
synced 2025-08-03 11:31:20 +02:00
added a custom menu and enabled the menu by default
This commit is contained in:
107
src/scripts/menu.js
Normal file
107
src/scripts/menu.js
Normal file
@@ -0,0 +1,107 @@
|
||||
const { Menu } = require("electron");
|
||||
const { showSettingsWindow } = require("./settings");
|
||||
const isMac = process.platform === "darwin";
|
||||
|
||||
const settingsMenuEntry = {
|
||||
label: "Settings",
|
||||
click() {
|
||||
showSettingsWindow();
|
||||
},
|
||||
accelerator: "Control+/",
|
||||
};
|
||||
|
||||
const mainMenu = [
|
||||
...(isMac
|
||||
? [
|
||||
{
|
||||
label: app.name,
|
||||
submenu: [
|
||||
{ role: "about" },
|
||||
settingsMenuEntry,
|
||||
{ type: "separator" },
|
||||
{ role: "services" },
|
||||
{ type: "separator" },
|
||||
{ role: "hide" },
|
||||
{ role: "hideothers" },
|
||||
{ role: "unhide" },
|
||||
{ type: "separator" },
|
||||
{ role: "quit" },
|
||||
],
|
||||
},
|
||||
]
|
||||
: []),
|
||||
// { role: 'fileMenu' }
|
||||
{
|
||||
label: "File",
|
||||
submenu: [settingsMenuEntry, isMac ? { role: "close" } : { role: "quit" }],
|
||||
},
|
||||
// { role: 'editMenu' }
|
||||
{
|
||||
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,
|
||||
],
|
||||
},
|
||||
// { role: 'viewMenu' }
|
||||
{
|
||||
label: "View",
|
||||
submenu: [
|
||||
{ role: "reload" },
|
||||
{ role: "forcereload" },
|
||||
{ type: "separator" },
|
||||
{ role: "resetzoom" },
|
||||
{ role: "zoomin" },
|
||||
{ role: "zoomout" },
|
||||
{ type: "separator" },
|
||||
{ role: "togglefullscreen" },
|
||||
],
|
||||
},
|
||||
// { role: 'windowMenu' }
|
||||
{
|
||||
label: "Window",
|
||||
submenu: [
|
||||
{ role: "minimize" },
|
||||
...(isMac
|
||||
? [{ type: "separator" }, { role: "front" }, { type: "separator" }, { role: "window" }]
|
||||
: [{ role: "close" }]),
|
||||
],
|
||||
},
|
||||
settingsMenuEntry,
|
||||
{
|
||||
label: "About",
|
||||
click() {
|
||||
showSettingsWindow("tab3");
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const menuModule = { mainMenu };
|
||||
|
||||
menuModule.getMenu = function() {
|
||||
return Menu.buildFromTemplate(mainMenu);
|
||||
};
|
||||
|
||||
menuModule.addMenu = function() {
|
||||
Menu.setApplicationMenu(menuModule.getMenu());
|
||||
};
|
||||
|
||||
module.exports = menuModule;
|
@@ -10,7 +10,7 @@ const store = new Store({
|
||||
notifications: true,
|
||||
api: true,
|
||||
playBackControl: true,
|
||||
menuBar: false,
|
||||
menuBar: true,
|
||||
apiSettings: {
|
||||
port: 47836,
|
||||
},
|
||||
@@ -52,7 +52,9 @@ settingsModule.createSettingsWindow = function() {
|
||||
settingsModule.settingsWindow = settingsWindow;
|
||||
};
|
||||
|
||||
settingsModule.showSettingsWindow = function() {
|
||||
settingsModule.showSettingsWindow = function(tab = "tab1") {
|
||||
settingsWindow.webContents.send("goToTab", tab);
|
||||
|
||||
// refresh data just before showing the window
|
||||
settingsWindow.webContents.send("refreshData");
|
||||
settingsWindow.show();
|
||||
|
@@ -1,4 +1,5 @@
|
||||
const { Tray, Menu } = require("electron");
|
||||
const { Tray } = require("electron");
|
||||
const { getMenu } = require("./menu");
|
||||
const trayModule = {};
|
||||
let tray;
|
||||
|
||||
@@ -7,14 +8,12 @@ trayModule.addTray = function(options = { icon: "" }) {
|
||||
};
|
||||
|
||||
trayModule.refreshTray = function() {
|
||||
const contextMenu = Menu.buildFromTemplate([
|
||||
{ label: "Item1", type: "radio" },
|
||||
{ label: "Item2", type: "radio" },
|
||||
{ label: "Item3", type: "radio", checked: true },
|
||||
{ label: "Item4", type: "radio" },
|
||||
]);
|
||||
tray.setToolTip("This is my application.");
|
||||
tray.setContextMenu(contextMenu);
|
||||
tray.on("click", function(e) {
|
||||
// do nothing on click
|
||||
});
|
||||
|
||||
tray.setToolTip("Tidal-hifi");
|
||||
tray.setContextMenu(getMenu());
|
||||
};
|
||||
|
||||
module.exports = trayModule;
|
||||
|
Reference in New Issue
Block a user