Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions src/hooks/useScreenRecorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -974,20 +974,12 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
if (!isCountdownRunActive(countdownRunToken)) {
return true;
}
if (webcamStream.current) {
nativeWebcamRecorder = createRecorderHandle(webcamStream.current, {
mimeType: selectMimeType(),
videoBitsPerSecond: BITRATE_BASE,
});
} else {
if (!webcamStream.current) {
webcamAcquireId.current++;
setWebcamEnabledState(false);
}
}
if (!isCountdownRunActive(countdownRunToken)) {
if (nativeWebcamRecorder && nativeWebcamRecorder.recorder.state !== "inactive") {
nativeWebcamRecorder.recorder.stop();
}
return true;
}
const request: NativeMacRecordingRequest = {
Expand Down Expand Up @@ -1034,19 +1026,33 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
};
const result = await window.electronAPI.startNativeMacRecording(request);
if (!result.success || !result.recordingId) {
if (nativeWebcamRecorder && nativeWebcamRecorder.recorder.state !== "inactive") {
nativeWebcamRecorder.recorder.stop();
}
throw new Error(result.error ?? "Native macOS capture failed.");
}
if (!isCountdownRunActive(countdownRunToken)) {
if (nativeWebcamRecorder && nativeWebcamRecorder.recorder.state !== "inactive") {
nativeWebcamRecorder.recorder.stop();
}
await window.electronAPI.stopNativeMacRecording(true);
return true;
}

// Start the webcam recorder only after the helper has emitted
// recording-started (startNativeMacRecording resolves on that event).
// Starting it earlier bakes the helper's capture startup latency
// (~1s of pre-roll) into the webcam file, desyncing it from the
// screen/mic recording that the editor and exporter align at t=0.
if (webcamEnabled && webcamStream.current) {
try {
nativeWebcamRecorder = createRecorderHandle(webcamStream.current, {
mimeType: selectMimeType(),
videoBitsPerSecond: BITRATE_BASE,
});
} catch (webcamError) {
// The native helper is already recording at this point; stop it before
// surfacing the error so we don't leave it running with no handle to
// finalize it (this creation moved after startNativeMacRecording).
await window.electronAPI.stopNativeMacRecording(true);
Comment thread
EtienneLescot marked this conversation as resolved.
throw webcamError;
}
}

recordingId.current = result.recordingId;
nativeMacRecording.current = {
recordingId: result.recordingId,
Expand Down
Loading