diff --git a/main.js b/main.js index 197f5ef..454cd3a 100644 --- a/main.js +++ b/main.js @@ -21,6 +21,8 @@ let uploadManager = null; let folderMonitor = new FolderMonitor(); let remoteServer = null; let captureWindow = null; +let captureWindowReady = false; +let signalingQueue = []; const HEALTH_CHECK_TIMEOUT = 25000; // --- Debug logging (writes to upload-debug.log next to the app) --- @@ -918,6 +920,7 @@ function generateToken() { function createCaptureWindow() { if (captureWindow && !captureWindow.isDestroyed()) return; + captureWindowReady = false; captureWindow = new BrowserWindow({ show: false, webPreferences: { @@ -928,9 +931,21 @@ function createCaptureWindow() { }); captureWindow.loadFile(path.join(__dirname, 'lib', 'remote-capture.html')); + // Wait for window to be fully loaded before sending signaling messages + captureWindow.webContents.on('dom-ready', () => { + debugLog('remote: capture window ready, draining', signalingQueue.length, 'queued messages'); + captureWindowReady = true; + for (const msg of signalingQueue) { + captureWindow.webContents.send('remote:signaling-to-capture', msg); + } + signalingQueue = []; + }); + // Crash recovery: if hidden window closes unexpectedly while clients connected, recreate it captureWindow.on('closed', () => { captureWindow = null; + captureWindowReady = false; + signalingQueue = []; if (remoteServer && remoteServer.getClientCount() > 0) { debugLog('remote: capture window crashed, recreating...'); createCaptureWindow(); @@ -969,8 +984,15 @@ async function startRemoteServer() { allowInput: remote.allowInput !== false, mainWindow, onSignalingToCapture: (data) => { - if (captureWindow && !captureWindow.isDestroyed()) { + if (!captureWindow || captureWindow.isDestroyed()) { + debugLog('remote: signaling dropped, no capture window'); + return; + } + if (captureWindowReady) { captureWindow.webContents.send('remote:signaling-to-capture', data); + } else { + debugLog('remote: capture window not ready, queuing', data.type, 'message'); + signalingQueue.push(data); } }, onCreateCaptureWindow: () => createCaptureWindow(), diff --git a/package.json b/package.json index afb0859..cd58bfd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "multi-hoster-uploader", - "version": "2.1.1", + "version": "2.1.2", "description": "Upload files to doodstream, voe, vidmoly, byse simultaneously", "main": "main.js", "scripts": {