project-client/src/main/mainWindow.ts

55 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-04-04 07:41:52 +09:00
import { BrowserWindow, Menu, Tray, app } from "electron";
2023-03-30 08:02:30 +09:00
import { join } from "path";
export function createMainWindow() {
2023-04-04 07:41:52 +09:00
let isQuitting = false;
2023-03-30 08:02:30 +09:00
const win = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: false,
sandbox: false,
2023-03-30 08:02:30 +09:00
contextIsolation: true,
devTools: true,
preload: join(__dirname, "preload.js")
2023-04-04 07:41:52 +09:00
},
icon: join(__dirname, "..", "..", "static", "icon.ico")
});
app.on("before-quit", () => {
isQuitting = true;
});
win.on("close", e => {
if (isQuitting) return;
e.preventDefault();
win.hide();
return false;
2023-03-30 08:02:30 +09:00
});
2023-04-04 07:41:52 +09:00
const tray = new Tray(join(__dirname, "..", "..", "static", "icon.ico"));
tray.setToolTip("Vencord Desktop");
tray.setContextMenu(Menu.buildFromTemplate([
{
label: "Open",
click() {
win.show();
}
},
{
label: "Quit",
click() {
isQuitting = true;
app.quit();
}
}
]));
tray.on("click", () => win.show());
2023-03-30 08:02:30 +09:00
win.loadURL("https://discord.com/app");
return win;
}