tidal-hifi/src/scripts/tray.ts

34 lines
716 B
TypeScript
Raw Normal View History

2023-05-01 23:23:43 +02:00
import { BrowserWindow, Tray } from "electron";
const { getMenu } = require("./menu");
2023-05-01 23:23:43 +02:00
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 () {
2023-04-22 20:51:20 +02:00
if (mainWindow.isVisible()) {
if (!mainWindow.isFocused()) {
mainWindow.focus();
} else {
mainWindow.hide();
}
} else {
mainWindow.show();
}
});
};
2023-05-01 23:23:43 +02:00
export const refreshTray = function (mainWindow: BrowserWindow) {
if (!tray) {
2023-05-01 23:23:43 +02:00
addTray(mainWindow);
}
};