2026-03-07 13:17:32 +01:00
|
|
|
const { app, BrowserWindow, session, shell, desktopCapturer } = require('electron');
|
2026-03-07 02:40:59 +01:00
|
|
|
const path = require('path');
|
|
|
|
|
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';
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2026-03-07 13:17:32 +01:00
|
|
|
// Enable screen capture (getDisplayMedia) in Electron
|
|
|
|
|
session.defaultSession.setDisplayMediaRequestHandler((_request, callback) => {
|
|
|
|
|
desktopCapturer.getSources({ types: ['screen', 'window'] }).then((sources) => {
|
|
|
|
|
callback({ video: sources[0], audio: 'loopback' });
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2026-03-07 02:40:59 +01:00
|
|
|
// Custom User-Agent to identify Electron app
|
|
|
|
|
const currentUA = mainWindow.webContents.getUserAgent();
|
2026-03-07 12:38:51 +01:00
|
|
|
mainWindow.webContents.setUserAgent(currentUA + ' GamingHubDesktop/1.5.0');
|
2026-03-07 02:40:59 +01:00
|
|
|
|
|
|
|
|
mainWindow.loadURL(HUB_URL);
|
|
|
|
|
|
|
|
|
|
// Open external links in default browser
|
|
|
|
|
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
|
|
|
|
|
if (!url.startsWith(HUB_URL)) {
|
|
|
|
|
shell.openExternal(url);
|
|
|
|
|
return { action: 'deny' };
|
|
|
|
|
}
|
|
|
|
|
return { action: 'allow' };
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Handle navigation to external URLs
|
|
|
|
|
mainWindow.webContents.on('will-navigate', (event, url) => {
|
|
|
|
|
if (!url.startsWith(HUB_URL)) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
shell.openExternal(url);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.whenReady().then(createWindow);
|
|
|
|
|
|
|
|
|
|
app.on('window-all-closed', () => {
|
|
|
|
|
if (process.platform !== 'darwin') app.quit();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.on('activate', () => {
|
|
|
|
|
if (BrowserWindow.getAllWindows().length === 0) createWindow();
|
|
|
|
|
});
|