import { join } from 'node:path'; import { BrowserWindow, shell } from 'electron'; /** * The launcher's single window: a fixed size without the system frame, like the game's own * launcher. The window draws its title bar and asks for minimize and close over IPC. */ /** The layout is drawn for exactly this content size. */ const CONTENT_WIDTH = 1120; const CONTENT_HEIGHT = 720; /** The window background before the page paints (--bg in the window's styles). */ const BACKGROUND = '#13191b'; let mainWindow: BrowserWindow | null = null; export function createMainWindow(): BrowserWindow { const window = new BrowserWindow({ width: CONTENT_WIDTH, height: CONTENT_HEIGHT, useContentSize: true, resizable: false, maximizable: false, fullscreenable: false, frame: false, backgroundColor: BACKGROUND, show: false, webPreferences: { preload: join(import.meta.dirname, '../preload/index.cjs'), sandbox: true, contextIsolation: true, nodeIntegration: false, }, }); window.once('ready-to-show', () => window.show()); // Links leave the launcher for the player's browser; the window itself never navigates away. window.webContents.setWindowOpenHandler(({ url }) => { if (/^https?:\/\//.test(url)) void shell.openExternal(url); return { action: 'deny' }; }); window.webContents.on('will-navigate', (event) => event.preventDefault()); window.on('closed', () => { if (mainWindow === window) mainWindow = null; }); const devServer = process.env['ELECTRON_RENDERER_URL']; if (devServer) void window.loadURL(devServer); else void window.loadFile(join(import.meta.dirname, '../renderer/index.html')); mainWindow = window; return window; } /** Brings the window forward, building it again if it was closed. */ export function showMainWindow(): void { const window = mainWindow ?? createMainWindow(); if (window.isMinimized()) window.restore(); window.focus(); }