import { app, BrowserWindow, Menu } from "electron";
import { fileURLToPath } from "node:url";
import path from "node:path";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
function createMainWindow() {
    const window = new BrowserWindow({
        width: 1240,
        height: 780,
        minWidth: 980,
        minHeight: 640,
        title: "蜂聊",
        backgroundColor: "#f5f5f5",
        trafficLightPosition: { x: 16, y: 16 },
        webPreferences: {
            preload: path.join(__dirname, "../preload/index.js"),
            contextIsolation: true,
            nodeIntegration: false,
            sandbox: false,
        },
    });
    const devServerUrl = process.env.VITE_DEV_SERVER_URL;
    if (devServerUrl) {
        void window.loadURL(devServerUrl);
        window.webContents.openDevTools({ mode: "detach" });
    }
    else {
        void window.loadFile(path.join(__dirname, "../../dist/index.html"));
    }
    return window;
}
app.whenReady().then(() => {
    Menu.setApplicationMenu(null);
    createMainWindow();
    app.on("activate", () => {
        if (BrowserWindow.getAllWindows().length === 0)
            createMainWindow();
    });
});
app.on("window-all-closed", () => {
    if (process.platform !== "darwin")
        app.quit();
});
