2022-02-17 18:09:57 +01:00
|
|
|
import { app, Tray, Menu } from "electron";
|
2022-02-19 01:48:56 +01:00
|
|
|
import path from "path";
|
2022-02-17 18:09:57 +01:00
|
|
|
import { showAboutWindow } from "electron-util";
|
|
|
|
|
|
|
|
import * as autoUpdater from "./auto-updater";
|
|
|
|
import * as log from "./log";
|
2022-02-22 19:01:26 +01:00
|
|
|
import { getAppView, getWindow } from "./window";
|
2022-02-17 18:09:57 +01:00
|
|
|
|
|
|
|
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();
|
|
|
|
},
|
|
|
|
},
|
2022-02-22 19:01:26 +01:00
|
|
|
{
|
|
|
|
label: "Open DevTools",
|
|
|
|
click() {
|
|
|
|
getWindow()?.webContents.openDevTools({ mode: "detach" });
|
|
|
|
getAppView()?.webContents.openDevTools({ mode: "detach" });
|
|
|
|
},
|
|
|
|
},
|
2022-02-18 23:03:05 +01:00
|
|
|
{
|
|
|
|
label: "About",
|
|
|
|
click() {
|
|
|
|
showAboutWindow({
|
2022-02-19 01:48:56 +01:00
|
|
|
icon: path.join(assetsDirectory, "icons", "logo.png"),
|
2022-02-18 23:03:05 +01:00
|
|
|
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
|
|
|
}
|