58 lines
1.3 KiB
TypeScript
58 lines
1.3 KiB
TypeScript
import { Menu, Tray, nativeImage } from "electron";
|
|
|
|
import trayIconAsset from "../../assets/desktop/icon.png?asset";
|
|
import { version } from "../../package.json";
|
|
|
|
import { mainWindow, quitApp } from "./window";
|
|
|
|
// internal tray state
|
|
let tray: Tray = null;
|
|
|
|
// load the tray icon
|
|
const trayIcon = nativeImage.createFromDataURL(trayIconAsset);
|
|
|
|
// trayIcon.setTemplateImage(true);
|
|
|
|
export function initTray() {
|
|
tray = new Tray(trayIcon);
|
|
updateTrayMenu();
|
|
tray.setToolTip("Stoat for Desktop");
|
|
tray.setImage(trayIcon);
|
|
}
|
|
|
|
export function updateTrayMenu() {
|
|
tray.setContextMenu(
|
|
Menu.buildFromTemplate([
|
|
{ label: "Stoat for Desktop", type: "normal", enabled: false },
|
|
{
|
|
label: "Version",
|
|
type: "submenu",
|
|
submenu: Menu.buildFromTemplate([
|
|
{
|
|
label: version,
|
|
type: "normal",
|
|
enabled: false,
|
|
},
|
|
]),
|
|
},
|
|
{ type: "separator" },
|
|
{
|
|
label: mainWindow.isVisible() ? "Hide App" : "Show App",
|
|
type: "normal",
|
|
click() {
|
|
if (mainWindow.isVisible()) {
|
|
mainWindow.hide();
|
|
} else {
|
|
mainWindow.show();
|
|
}
|
|
},
|
|
},
|
|
{
|
|
label: "Quit App",
|
|
type: "normal",
|
|
click: quitApp,
|
|
},
|
|
]),
|
|
);
|
|
}
|