Void (main window is managed by Electron).
function createWindow() {
return withGroup(`[Main] Create Main Window`, () => {
console.info("[Main] 🪟 Creating main application window...");
const preload = path.join(__dirname, "preload.js");
const mainWindow = new BrowserWindow({
width: 1200,
height: 800,
show: false, // Don't show until ready
webPreferences: {
sandbox: true,
devTools: inDevelopment || enableDevTools,
contextIsolation: true,
nodeIntegration: false,
nodeIntegrationInSubFrames: false,
preload: preload,
},
titleBarStyle: "hidden",
});
console.debug("[Main] 🔍 Registering IPC listeners...");
registerListeners(mainWindow);
// Track if content loaded successfully
let contentLoaded = false;
// Handle successful load
mainWindow.webContents.on("did-finish-load", () => {
console.info("[Main] ✅ Main window content loaded successfully");
contentLoaded = true;
});
// Handle load failures
mainWindow.webContents.on(
"did-fail-load",
(_event, errorCode, errorDescription, validatedURL) => {
console.error(
`[Main] ❌ Main window failed to load (${errorCode}): ${errorDescription}`,
);
console.error(`[Main] ❌ Failed URL: ${validatedURL}`);
contentLoaded = false;
},
);
// Load content from dev server (development) or bundled file (production)
if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {
console.debug(
`[Main] 🔍 Loading dev server: ${MAIN_WINDOW_VITE_DEV_SERVER_URL}`,
);
mainWindow.loadURL(MAIN_WINDOW_VITE_DEV_SERVER_URL);
} else {
const filePath = path.join(
__dirname,
`../renderer/${MAIN_WINDOW_VITE_NAME}/index.html`,
);
console.debug(`[Main] 🔍 Loading file: ${filePath}`);
console.debug(`[Main] 🔍 __dirname: ${__dirname}`);
console.debug(
`[Main] 🔍 MAIN_WINDOW_VITE_NAME: ${MAIN_WINDOW_VITE_NAME}`,
);
console.debug(`[Main] 🔍 app.isPackaged: ${app.isPackaged}`);
console.debug(
`[Main] 🔍 process.resourcesPath: ${process.resourcesPath}`,
);
mainWindow.loadFile(filePath).catch((err) => {
console.error(`[Main] ❌ Failed to load main window file:`, err);
});
}
// Auto-open DevTools if explicitly enabled via env var
if (enableDevTools) {
console.info("[Main] 🔧 DevTools enabled via ENABLE_DEVTOOLS env var");
mainWindow.webContents.openDevTools({ mode: "right" });
}
// Show main window and close splash when ready
mainWindow.once("ready-to-show", () => {
console.info("[Main] ✅ Main window ready-to-show event fired");
// Add a small delay to ensure smooth transition
setTimeout(() => {
if (contentLoaded) {
closeSplashScreen();
mainWindow.show();
console.info("[Main] ✅ Main window displayed");
} else {
console.error(
"[Main] ❌ Main window content not loaded, keeping splash visible",
);
}
}, 1500);
});
console.info("[Main] ✅ Main window created successfully");
});
}
Creates the main application window. Sets up the BrowserWindow, registers IPC listeners, handles content loading, and manages the transition from splash screen to main window.