2022-02-17 18:09:57 +01:00
|
|
|
import { app, Tray, Menu } from "electron";
|
|
|
|
import * as 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() {
|
2022-02-18 23:03:05 +01:00
|
|
|
return tray;
|
2022-02-17 18:09:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function createTray() {
|
2022-02-18 23:03:05 +01:00
|
|
|
tray = new Tray(path.join(assetsDirectory, "icons", "logo.png"));
|
2022-02-17 18:09:57 +01:00
|
|
|
|
2022-02-18 23:03:05 +01:00
|
|
|
const trayContextMenu = Menu.buildFromTemplate([
|
|
|
|
{
|
|
|
|
id: "open",
|
|
|
|
label: "Show / Hide",
|
|
|
|
click() {
|
|
|
|
const mainWindow = getWindow();
|
|
|
|
if (!mainWindow) {
|
|
|
|
throw new Error("Main window not found");
|
|
|
|
}
|
2022-02-17 18:09:57 +01:00
|
|
|
|
2022-02-18 23:03:05 +01:00
|
|
|
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(__dirname, "..", "assets", "icons", "logo.png"),
|
|
|
|
copyright: "Copyright © WorkAdventure",
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Quit",
|
|
|
|
click() {
|
|
|
|
// app.confirmedExitPrompt = true;
|
|
|
|
app.quit();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]);
|
2022-02-17 18:09:57 +01:00
|
|
|
|
2022-02-18 23:03:05 +01:00
|
|
|
tray.setContextMenu(trayContextMenu);
|
2022-02-17 18:09:57 +01:00
|
|
|
|
2022-02-18 23:03:05 +01:00
|
|
|
tray.on("double-click", () => {
|
|
|
|
const mainWindow = getWindow();
|
|
|
|
if (!mainWindow) {
|
|
|
|
throw new Error("Main window not found");
|
|
|
|
}
|
2022-02-17 18:09:57 +01:00
|
|
|
|
2022-02-18 23:03:05 +01:00
|
|
|
mainWindow.show();
|
|
|
|
});
|
2022-02-17 18:09:57 +01:00
|
|
|
|
2022-02-18 23:03:05 +01:00
|
|
|
return tray;
|
2022-02-17 18:09:57 +01:00
|
|
|
}
|