From 55312f2f8925258d7dab5233ff4e18d406bef129 Mon Sep 17 00:00:00 2001 From: webadderall <131426131+webadderall@users.noreply.github.com> Date: Mon, 20 Apr 2026 22:07:03 +1000 Subject: [PATCH] fix: wrap native recording IPC calls in try/catch for resilient error handling stopNativeScreenRecording and muxNativeWindowsRecording can reject if IPC fails or the bridge is disposed. Without try/catch, setRecordingState(false) is never called, the finalization toast stays up indefinitely, and no failure UI is shown to the user. Now exceptions are caught and routed through the existing diagnostics/recovery paths. --- .../useScreenRecorder/recordingStopHelpers.ts | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/hooks/useScreenRecorder/recordingStopHelpers.ts b/src/hooks/useScreenRecorder/recordingStopHelpers.ts index 8285fbb5..15b96fe0 100644 --- a/src/hooks/useScreenRecorder/recordingStopHelpers.ts +++ b/src/hooks/useScreenRecorder/recordingStopHelpers.ts @@ -32,8 +32,18 @@ export async function stopNativeRecordingSession(options: StopRecordingOptions) const pauseSegments = options.refs.pauseSegmentsRef.current.slice(); options.refs.nativeWindowsRecording.current = false; - const result = await window.electronAPI.stopNativeScreenRecording(); - await window.electronAPI?.setRecordingState(false); + let result: Awaited>; + try { + result = await window.electronAPI.stopNativeScreenRecording(); + } catch (error) { + console.error("stopNativeScreenRecording threw:", error); + result = { success: false, error: String(error) }; + } + try { + await window.electronAPI?.setRecordingState(false); + } catch (error) { + console.warn("setRecordingState(false) failed:", error); + } if (!result.success || !result.path) { console.error("Failed to stop native screen recording:", result.error ?? result.message); @@ -59,8 +69,14 @@ export async function stopNativeRecordingSession(options: StopRecordingOptions) let finalPath = result.path; if (isNativeWindows) { - const muxResult = await window.electronAPI.muxNativeWindowsRecording(pauseSegments); - if (!muxResult?.success) { + let muxResult: Awaited> | undefined; + try { + muxResult = await window.electronAPI.muxNativeWindowsRecording(pauseSegments); + } catch (error) { + console.error("muxNativeWindowsRecording threw:", error); + await options.logNativeCaptureDiagnostics("mux-native-windows-recording"); + } + if (muxResult && !muxResult.success) { await options.logNativeCaptureDiagnostics("mux-native-windows-recording"); } finalPath = muxResult?.path ?? result.path;