2021-06-17 20:37:14 +02:00
|
|
|
const { Tray, app } = require("electron");
|
|
|
|
const { Menu } = require("electron");
|
|
|
|
const { getMenu, mainMenu } = require("./menu");
|
|
|
|
const { store, settings } = require("./settings");
|
2019-10-30 21:43:52 +01:00
|
|
|
const trayModule = {};
|
|
|
|
let tray;
|
|
|
|
|
2020-10-07 20:10:31 +02:00
|
|
|
trayModule.addTray = function (options = { icon: "" }) {
|
2019-10-30 21:43:52 +01:00
|
|
|
tray = new Tray(options.icon);
|
|
|
|
};
|
|
|
|
|
2021-06-17 20:37:14 +02:00
|
|
|
trayModule.refreshTray = function (mainWindow) {
|
2020-10-07 20:10:31 +02:00
|
|
|
if (!tray) {
|
|
|
|
trayModule.addTray();
|
|
|
|
}
|
2021-06-17 20:37:14 +02:00
|
|
|
|
2020-10-07 20:10:31 +02:00
|
|
|
tray.on("click", function (e) {
|
2021-06-17 20:37:14 +02:00
|
|
|
if (mainWindow) {
|
|
|
|
mainWindow.show();
|
|
|
|
}
|
2019-11-03 20:22:59 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
tray.setToolTip("Tidal-hifi");
|
2021-06-17 20:44:30 +02:00
|
|
|
|
2021-06-17 20:37:14 +02:00
|
|
|
if (mainWindow && store.get(settings.minimizeOnClose)) {
|
|
|
|
tray.setContextMenu(
|
|
|
|
Menu.buildFromTemplate([
|
|
|
|
{
|
|
|
|
label: "Toggle Window",
|
|
|
|
click: function () {
|
|
|
|
mainWindow.isVisible() ? mainWindow.hide() : mainWindow.show();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Quit",
|
|
|
|
click: function () {
|
|
|
|
mainWindow.destroy();
|
|
|
|
app.quit();
|
|
|
|
},
|
2021-06-17 20:44:30 +02:00
|
|
|
},
|
2021-06-17 20:37:14 +02:00
|
|
|
...mainMenu, //we add menu items from the other context
|
|
|
|
])
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
tray.setContextMenu(getMenu());
|
|
|
|
}
|
2019-10-30 21:43:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = trayModule;
|