const { BrowserWindow, screen } = require('electron'); const path = require('path'); const HUD_URL = process.env.FOX_HUD_URL || 'https://fox.pxo.at/hud'; let hudWindow = null; let hudLoaded = false; let pendingShow = false; let hudActive = false; function createHud() { const { width, height } = screen.getPrimaryDisplay().workAreaSize; hudWindow = new BrowserWindow({ width, height, x: 0, y: 0, frame: false, transparent: true, backgroundColor: '#00000000', alwaysOnTop: false, show: false, skipTaskbar: true, hasShadow: false, webPreferences: { preload: path.join(__dirname, 'preload.js'), contextIsolation: true, nodeIntegration: false, webSecurity: false, allowRunningInsecureContent: true, }, }); // Unsichtbar und click-through bis aktiv hudWindow.setIgnoreMouseEvents(true); hudWindow.webContents.once('did-finish-load', () => { hudLoaded = true; if (pendingShow) { pendingShow = false; _activateHud(); } }); hudWindow.loadURL(HUD_URL); hudWindow.on('closed', () => { hudWindow = null; hudLoaded = false; pendingShow = false; hudActive = false; }); return hudWindow; } function _activateHud() { hudActive = true; hudWindow.setIgnoreMouseEvents(false); hudWindow.setAlwaysOnTop(true, 'screen-saver'); hudWindow.webContents.send('hud-show'); } function showHud() { if (!hudWindow) createHud(); hudWindow.show(); hudWindow.focus(); if (hudLoaded) { _activateHud(); } else { pendingShow = true; } } function hideHud() { if (!hudWindow || !hudActive) return; hudActive = false; hudWindow.setAlwaysOnTop(false); hudWindow.setIgnoreMouseEvents(true); hudWindow.webContents.send('hud-hide'); setTimeout(() => { if (hudWindow) hudWindow.hide(); }, 600); } function toggleHud() { if (hudActive) { hideHud(); } else { showHud(); } } module.exports = { createHud, showHud, hideHud, toggleHud };