tidal-hifi/src/scripts/tray.ts
2023-05-01 23:23:56 +02:00

34 lines
716 B
TypeScript

import { BrowserWindow, Tray } from "electron";
const { getMenu } = require("./menu");
let tray: Tray;
export const addTray = function (mainWindow: BrowserWindow, options = { icon: "" }) {
tray = new Tray(options.icon);
tray.setIgnoreDoubleClickEvents(true);
tray.setToolTip("Tidal-hifi");
const menu = getMenu(mainWindow);
tray.setContextMenu(menu);
tray.on("click", function () {
if (mainWindow.isVisible()) {
if (!mainWindow.isFocused()) {
mainWindow.focus();
} else {
mainWindow.hide();
}
} else {
mainWindow.show();
}
});
};
export const refreshTray = function (mainWindow: BrowserWindow) {
if (!tray) {
addTray(mainWindow);
}
};