fix(desktop): use get-port-please for dynamic port selection

This commit is contained in:
CREDO23 2026-03-18 19:38:47 +02:00
parent b07a64fd27
commit c6f3218085
3 changed files with 15 additions and 2 deletions

View file

@ -1,10 +1,11 @@
import { app, BrowserWindow, shell, ipcMain, session } from 'electron';
import path from 'path';
import { getPort } from 'get-port-please';
const isDev = !app.isPackaged;
let mainWindow: BrowserWindow | null = null;
let deepLinkUrl: string | null = null;
let serverPort: number = 3000;
let serverPort: number = 3000; // overwritten at startup with a free port
const PROTOCOL = 'surfsense';
// Injected at compile time from .env.desktop via esbuild define
@ -33,6 +34,9 @@ async function waitForServer(url: string, maxRetries = 60): Promise<boolean> {
async function startNextServer(): Promise<void> {
if (isDev) return;
serverPort = await getPort({ port: 3000, portRange: [30_011, 50_000] });
console.log(`Selected port ${serverPort}`);
const standalonePath = getStandalonePath();
const serverScript = path.join(standalonePath, 'server.js');