Fix: Stream-close-warning via IPC statt async executeJavaScript

- Renderer meldet Streaming-Status synchron per IPC
- main.js prueft Status synchron im close-Handler
- Kein async Race mehr, Dialog erscheint zuverlaessig
This commit is contained in:
Daniel 2026-03-07 14:14:51 +01:00
parent e2ae624690
commit 7bebb7db9a
3 changed files with 20 additions and 17 deletions

View file

@ -106,25 +106,22 @@ function createWindow() {
}
});
// Track streaming status from renderer (synchronous — no async race)
let isStreaming = false;
ipcMain.on('streaming-status', (_event, active) => { isStreaming = active; });
// Warn before closing if a stream is active
let forceClose = false;
mainWindow.on('close', (event) => {
if (forceClose) return;
event.preventDefault();
mainWindow.webContents.executeJavaScript(
`Array.from(document.querySelectorAll('video')).some(v => v.srcObject?.active)`
).then((isStreaming) => {
if (!isStreaming) { forceClose = true; mainWindow.close(); return; }
const result = dialog.showMessageBoxSync(mainWindow, {
type: 'warning',
buttons: ['Beenden', 'Abbrechen'],
defaultId: 1,
cancelId: 1,
title: 'Stream laeuft noch!',
message: 'Ein Stream ist noch aktiv.\nBeim Beenden wird der Stream gestoppt.',
});
if (result === 0) { forceClose = true; mainWindow.close(); }
}).catch(() => { forceClose = true; mainWindow.close(); });
if (!isStreaming) return;
const result = dialog.showMessageBoxSync(mainWindow, {
type: 'warning',
buttons: ['Beenden', 'Abbrechen'],
defaultId: 1,
cancelId: 1,
title: 'Stream laeuft noch!',
message: 'Ein Stream ist noch aktiv.\nBeim Beenden wird der Stream gestoppt.',
});
if (result !== 0) event.preventDefault();
});
}