partey_workadventure/desktop/electron/src/tray.ts
2022-02-22 10:41:55 +01:00

78 lines
1.9 KiB
TypeScript

import { app, Tray, Menu } from "electron";
import path from "path";
import { showAboutWindow } from "electron-util";
import * as autoUpdater from "./auto-updater";
import * as log from "./log";
import { getWindow } from "./window";
let tray: Tray | undefined;
const assetsDirectory = path.join(__dirname, "..", "assets");
export function getTray() {
return tray;
}
export function createTray() {
tray = new Tray(path.join(assetsDirectory, "icons", "logo.png"));
const trayContextMenu = Menu.buildFromTemplate([
{
id: "open",
label: "Show / Hide",
click() {
const mainWindow = getWindow();
if (!mainWindow) {
throw new Error("Main window not found");
}
if (mainWindow.isVisible()) {
mainWindow.hide();
} else {
mainWindow.show();
}
},
},
{
label: "Check for updates",
async click() {
await autoUpdater.manualRequestUpdateCheck();
},
},
{
label: "Open Logs",
click() {
log.openLog();
},
},
{
label: "About",
click() {
showAboutWindow({
icon: path.join(assetsDirectory, "icons", "logo.png"),
copyright: "Copyright © WorkAdventure",
});
},
},
{
label: "Quit",
click() {
// app.confirmedExitPrompt = true;
app.quit();
},
},
]);
tray.setContextMenu(trayContextMenu);
tray.on("double-click", () => {
const mainWindow = getWindow();
if (!mainWindow) {
throw new Error("Main window not found");
}
mainWindow.show();
});
}