YesPlayMusic/src/electron/tray.js
njzy b394ec0899
refactor: hide window when close app (#78)
fix: window can't be close by shortcutkey

fix: tray does not show in Windows
2020-12-09 19:50:50 +08:00

35 lines
690 B
JavaScript

/* global __static */
import path from "path";
import { app, nativeImage, Tray, Menu } from "electron";
export function createTray(win) {
let icon = nativeImage
.createFromPath(path.join(__static, "img/icons/menu@88.png"))
.resize({
height: 20,
width: 20,
});
let tray = new Tray(icon);
tray.on("click", () => {
if (win && win.isVisible()) {
win.hide();
} else {
win.show();
}
});
tray.on("right-click", () => {
const contextMenu = Menu.buildFromTemplate([
{
label: "Quit",
click: () => {
app.exit();
},
},
]);
tray.popUpContextMenu(contextMenu);
});
return tray;
}