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:
parent
e2ae624690
commit
7bebb7db9a
3 changed files with 20 additions and 17 deletions
|
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,4 +6,5 @@ contextBridge.exposeInMainWorld('electronAPI', {
|
|||
onUpdateAvailable: (callback) => ipcRenderer.on('update-available', callback),
|
||||
onUpdateReady: (callback) => ipcRenderer.on('update-ready', callback),
|
||||
installUpdate: () => ipcRenderer.send('install-update'),
|
||||
setStreaming: (active) => ipcRenderer.send('streaming-status', active),
|
||||
});
|
||||
|
|
|
|||
|
|
@ -79,6 +79,11 @@ export default function StreamingTab({ data }: { data: any }) {
|
|||
useEffect(() => { isBroadcastingRef.current = isBroadcasting; }, [isBroadcasting]);
|
||||
useEffect(() => { viewingRef.current = viewing; }, [viewing]);
|
||||
|
||||
// Notify Electron about streaming status for close-warning
|
||||
useEffect(() => {
|
||||
(window as any).electronAPI?.setStreaming(isBroadcasting || viewing !== null);
|
||||
}, [isBroadcasting, viewing]);
|
||||
|
||||
// ── Elapsed time ticker ──
|
||||
useEffect(() => {
|
||||
const hasActive = streams.length > 0 || isBroadcasting;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue