Files
TrueGrowth/vendor/aigcpanel/electron/config/tray.ts
Jammy 52636c91ae
Some checks failed
CI / main (push) Has been cancelled
CI / release-e2e (push) Has been cancelled
Track bundled vendor runtime sources
2026-07-07 10:05:50 +08:00

76 lines
1.4 KiB
TypeScript

import { app, Menu, Tray } from "electron";
import { AppConfig } from "../../src/config";
import { isMac, isWin } from "../lib/env";
import { AppRuntime } from "../mapi/env";
import { trayPath } from "./icon";
import { t } from "./lang";
let tray = null;
const showApp = () => {
if (isMac) {
app.dock.show();
}
AppRuntime.mainWindow.show();
};
const hideApp = () => {
if (isMac) {
app.dock.hide();
}
AppRuntime.mainWindow.hide();
};
const quitApp = () => {
// @ts-ignore
app.quitForce = true;
app.quit();
};
const ready = () => {
tray = new Tray(trayPath);
tray.setToolTip(AppConfig.title);
if (isWin) {
tray.on("click", () => {
showApp();
});
}
const contextMenu = Menu.buildFromTemplate([
{
label: t("tray.showMain"),
click: () => {
showApp();
},
},
{
label: t("tray.restart"),
click: () => {
app.relaunch();
quitApp();
},
},
{
label: t("menu.quit"),
click: () => {
quitApp();
},
},
]);
tray.setContextMenu(contextMenu);
};
const show = () => {
if (tray) {
tray.destroy();
tray = null;
}
};
export const ConfigTray = {
ready,
};