const { app, BrowserWindow, session, shell, desktopCapturer, autoUpdater, dialog, ipcMain, Notification } = require('electron'); const path = require('path'); const fs = require('fs'); const os = require('os'); const { setupAdBlocker } = require('./ad-blocker'); // Handle Squirrel events (Windows installer) try { if (require('electron-squirrel-startup')) app.quit(); } catch { // electron-squirrel-startup not installed, skip } const HUB_URL = process.env.GAMING_HUB_URL || 'https://hub.daddelolymp.de'; const APP_VERSION = app.getVersion(); // Sync IPC: preload reads app version from package.json ipcMain.on('get-app-version', (event) => { event.returnValue = APP_VERSION; }); function setupAutoUpdater() { if (process.platform !== 'win32') return; // Squirrel.Windows appends /RELEASES to the feed URL, // so point to /downloads where RELEASES + nupkg files live const updateURL = `${HUB_URL}/downloads`; try { autoUpdater.setFeedURL({ url: updateURL }); } catch (e) { console.error('[AutoUpdater] setFeedURL failed:', e.message); return; } autoUpdater.on('update-available', () => { console.log('[AutoUpdater] Update available, downloading...'); if (mainWindow) mainWindow.webContents.send('update-available'); }); autoUpdater.on('update-downloaded', (_event, releaseNotes, releaseName) => { console.log('[AutoUpdater] Update downloaded:', releaseName || 'new version'); if (mainWindow) mainWindow.webContents.send('update-ready'); }); // Handle install-update request from renderer ipcMain.on('install-update', () => { autoUpdater.quitAndInstall(); }); autoUpdater.on('update-not-available', () => { console.log('[AutoUpdater] App is up to date.'); if (mainWindow) mainWindow.webContents.send('update-not-available'); }); // Manual check from renderer ipcMain.on('check-for-updates', () => { try { autoUpdater.checkForUpdates(); } catch (e) { console.error('[AutoUpdater]', e.message); } }); autoUpdater.on('error', (err) => { console.error('[AutoUpdater] Error:', err.message); if (mainWindow) mainWindow.webContents.send('update-error', err.message); }); // Check for updates after 5 seconds, then every 30 minutes setTimeout(() => { try { autoUpdater.checkForUpdates(); } catch (e) { console.error('[AutoUpdater]', e.message); } }, 5000); setInterval(() => { try { autoUpdater.checkForUpdates(); } catch (e) { console.error('[AutoUpdater]', e.message); } }, 30 * 60 * 1000); } let mainWindow; function createWindow() { mainWindow = new BrowserWindow({ width: 1400, height: 900, minWidth: 900, minHeight: 600, title: 'Gaming Hub', icon: path.join(__dirname, 'assets', 'icon.png'), webPreferences: { preload: path.join(__dirname, 'preload.js'), contextIsolation: true, nodeIntegration: false, }, backgroundColor: '#1a1b1e', autoHideMenuBar: true, }); // Setup ad blocker BEFORE loading URL setupAdBlocker(session.defaultSession); // Enable screen capture (getDisplayMedia) in Electron — always show picker // IPC channel for picker result const PICKER_CHANNEL = 'screen-picker-result'; session.defaultSession.setDisplayMediaRequestHandler(async (_request, callback) => { const sources = await desktopCapturer.getSources({ types: ['screen', 'window'], thumbnailSize: { width: 320, height: 180 } }); if (sources.length === 0) { callback({}); return; } const sourceData = sources.map(s => ({ id: s.id, name: s.name, thumbnail: s.thumbnail.toDataURL(), })); // Write picker HTML to a temp file (data: URLs are blocked in Electron) const pickerHtml = `