From d04bab732bac5bb41f5764acc077d4ba03d12eff Mon Sep 17 00:00:00 2001 From: Galactic99 Date: Thu, 16 Apr 2026 19:44:51 +0530 Subject: [PATCH] prioritize recording stop over countdown cancel --- src/hooks/useScreenRecorder.ts | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/hooks/useScreenRecorder.ts b/src/hooks/useScreenRecorder.ts index 51c57dd..44dece0 100644 --- a/src/hooks/useScreenRecorder.ts +++ b/src/hooks/useScreenRecorder.ts @@ -759,12 +759,17 @@ export function useScreenRecorder(): UseScreenRecorderReturn { }; const toggleRecording = () => { + if (recording) { + stopRecording.current(); + return; + } + if (countdownActive) { cancelCountdown(); return; } - recording ? stopRecording.current() : void startRecordCountdown(); + void startRecordCountdown(); }; const restartRecording = async () => { @@ -827,19 +832,23 @@ export function useScreenRecorder(): UseScreenRecorderReturn { }, [getRecordingDurationMs, paused, recording]); const cancelRecording = () => { + const activeScreenRecorder = screenRecorder.current; + if ( + activeScreenRecorder?.recorder.state === "recording" || + activeScreenRecorder?.recorder.state === "paused" + ) { + const activeRecordingId = recordingId.current; + discardRecordingId.current = activeRecordingId; + allowAutoFinalize.current = false; + + stopRecording.current(); + return; + } + if (countdownActive) { cancelCountdown(); return; } - - const activeScreenRecorder = screenRecorder.current; - if (!activeScreenRecorder || activeScreenRecorder.recorder.state !== "recording") return; - - const activeRecordingId = recordingId.current; - discardRecordingId.current = activeRecordingId; - allowAutoFinalize.current = false; - - stopRecording.current(); }; return {