import { app, BrowserWindow, ipcMain, session } from 'electron'; import { ipcMainHandle, ipcMainOn, isDev } from './util.js'; import { getStaticData, pollResources } from './resourceManager.js'; import { getPreloadPath, getUIPath } from './pathResolver.js'; import "./ipc/ipcHandler.js"; import { registerIPCHandlers } from './ipc/ipcHandler.js'; let mainWindow:any = null; app.on('certificate-error', (event, webContents, url, error, certificate, callback) => { // Prevent the default behavior of showing a certificate error dialog event.preventDefault(); // Allow the certificate, effectively ignoring the error callback(true); }); app.on('ready', async () => { console.log("ready"); mainWindow = new BrowserWindow({ width: 500, // fixed width height: 600, // fixed height resizable: false, // prevents resizing fullscreenable: false, // disables fullscreen toggle (F11 or double-click title bar) minimizable: false, // disables minimize button maximizable: false, // prevents maximize closable: true, alwaysOnTop: true, autoHideMenuBar: true, frame: process.platform === 'darwin' ? false : true, webPreferences: { preload: getPreloadPath(), }, }); session.defaultSession.webRequest.onBeforeRequest((details, callback) => { console.log('🌐 Request:', details.method, details.url); callback({ cancel: false }); }); if (isDev()) { mainWindow.loadURL('http://localhost:5123'); mainWindow.webContents.openDevTools(); } else { mainWindow.loadFile(getUIPath()); } // pollResources(mainWindow); // 🔹 Register all IPC handlers (includes polling) registerIPCHandlers(mainWindow); pollResources(mainWindow); // IPC handlers // ipcMainHandle('getStaticData', () => getStaticData()); // ipcMainOn('sendFrameAction', (payload) => { // switch (payload) { // case 'CLOSE': // mainWindow.close(); // break; // case 'MAXIMIZE': // // prevent maximize // break; // case 'MINIMIZE': // mainWindow.minimize(); // break; // } // }); handleCloseEvents(mainWindow); }); function handleCloseEvents(mainWindow: BrowserWindow) { let willClose = false; mainWindow.on('close', (e) => { if (willClose) return; e.preventDefault(); mainWindow.hide(); if (app.dock) { app.dock.hide(); } }); app.on('before-quit', () => { willClose = true; }); mainWindow.on('show', () => { willClose = false; }); } export function getMainWindow() { return mainWindow; }