"use strict"; const { app, BrowserWindow } = require("electron"); const path = require("path"); const ProxyServer = require("../server/proxy"); let mainWindow; let proxyServer; function createWindow() { mainWindow = new BrowserWindow({ width: 1400, height: 900, webPreferences: { nodeIntegration: true, contextIsolation: false, webviewTag: true }, backgroundColor: "#1e1e1e", title: "Hydra Browser" }); mainWindow.loadFile(path.join(__dirname, "../renderer/index.html")); if (process.argv.includes("--dev")) { mainWindow.webContents.openDevTools(); } mainWindow.on("closed", () => { mainWindow = null; }); } async function initializeApp() { proxyServer = new ProxyServer(3001); try { await proxyServer.start(); console.log("Proxy server started successfully"); } catch (error) { console.error("Failed to start proxy server:", error); app.quit(); return; } createWindow(); } app.whenReady().then(initializeApp); app.on("window-all-closed", () => { if (process.platform !== "darwin") { app.quit(); } }); app.on("activate", () => { if (BrowserWindow.getAllWindows().length === 0) { createWindow(); } }); app.on("before-quit", async () => { if (proxyServer) { await proxyServer.stop(); } }); process.on("uncaughtException", (error) => { console.error("Uncaught exception:", error); }); process.on("unhandledRejection", (reason, promise) => { console.error("Unhandled rejection at:", promise, "reason:", reason); });