From 2537952a940ccd2baa05f25e086f3f0b1ac23e59 Mon Sep 17 00:00:00 2001 From: Alan Trebugeais Date: Sun, 10 May 2026 13:18:26 +0200 Subject: [PATCH] fix: editor loads instantly --- electron/ipc/register/recording.ts | 6 +++ src/hooks/useScreenRecorder.ts | 81 +++++++++++++++--------------- 2 files changed, 46 insertions(+), 41 deletions(-) diff --git a/electron/ipc/register/recording.ts b/electron/ipc/register/recording.ts index b2e9c9eb..15e2e95d 100644 --- a/electron/ipc/register/recording.ts +++ b/electron/ipc/register/recording.ts @@ -20,6 +20,7 @@ import { startNativeCursorMonitor, stopNativeCursorMonitor } from "../cursor/mon import { normalizeCursorTelemetrySamples, pauseCursorCaptureAtBoundary, + persistPendingCursorTelemetry, resetCursorCaptureClock, resumeCursorCapture, sampleCursorPoint, @@ -876,6 +877,11 @@ export function registerRecordingHandlers( durationSeconds: validation.durationSeconds, }, }); + + // Persist cursor telemetry before returning so the editor can find it immediately + snapshotCursorTelemetryForPersistence(); + await persistPendingCursorTelemetry(finalVideoPath); + return { success: true, path: finalVideoPath }; } catch (error) { console.error("Failed to stop native Windows capture:", error); diff --git a/src/hooks/useScreenRecorder.ts b/src/hooks/useScreenRecorder.ts index 0fd2f1df..de05f21e 100644 --- a/src/hooks/useScreenRecorder.ts +++ b/src/hooks/useScreenRecorder.ts @@ -38,7 +38,6 @@ const WEBCAM_WIDTH = 1280; const WEBCAM_HEIGHT = 720; const WEBCAM_FRAME_RATE = 30; const WEBCAM_SUFFIX = "-webcam"; -const SOURCE_AUDIO_MUX_TOAST_ID = "recording-audio-mux-warning"; const MICROPHONE_FALLBACK_ERROR_TOAST_ID = "recording-microphone-fallback-error"; const MICROPHONE_SIDECAR_ERROR_TOAST_ID = "recording-microphone-sidecar-error"; export type BrowserMicrophoneProfile = @@ -1063,51 +1062,51 @@ export function useScreenRecorder(): UseScreenRecorderReturn { return; } - let finalPath = result.path; + const finalPath = result.path; - if (isNativeWindows) { - const ipcMuxStart = performance.now(); - console.log("[PERF:RENDERER] IPC: muxNativeWindowsRecording: STARTED"); - const muxResult = - await window.electronAPI.muxNativeWindowsRecording(expectedDurationMs); - console.log( - `[PERF:RENDERER] IPC: muxNativeWindowsRecording: COMPLETED in ${(performance.now() - ipcMuxStart).toFixed(2)}ms`, - ); - - if (!muxResult?.success || !muxResult.path) { - void logNativeCaptureDiagnostics("mux-native-windows-recording"); - const fallbackPath = muxResult?.path ?? finalPath; - const warningMessage = - muxResult?.error || - muxResult?.message || - "Failed to finish the native Windows audio mux"; - toast.warning( - `${warningMessage}. Recording was saved, but audio playback or export may be incomplete.`, - { id: SOURCE_AUDIO_MUX_TOAST_ID, duration: 10000 }, - ); - finalPath = fallbackPath; - } else { - finalPath = muxResult.path; - } + // 1. Immediately inform the Main process about the provisional path + const shouldHideOverlayCursor = hideEditorOverlayCursorByDefault.current; + if (webcamPath) { + await window.electronAPI.setCurrentRecordingSession({ + videoPath: finalPath, + webcamPath, + timeOffsetMs: webcamTimeOffsetMs.current, + hideOverlayCursorByDefault: shouldHideOverlayCursor, + }); + } else { + await window.electronAPI.setCurrentVideoPath(finalPath, { + hideOverlayCursorByDefault: shouldHideOverlayCursor, + }); } - const sidecarStart = performance.now(); - console.log("[PERF:RENDERER] Store Sidecar: STARTED"); - await storeMicrophoneSidecar( - micFallbackBlobPromise, - finalPath, - fallbackStartDelayMs, - fallbackTrackSettings, - ); - console.log( - `[PERF:RENDERER] Store Sidecar: COMPLETED in ${(performance.now() - sidecarStart).toFixed(2)}ms`, - ); + // 2. Open the editor window immediately (Optimistic UI) + setFinalizing(false); + void window.electronAPI.switchToEditor(); - await finalizeRecordingSession(finalPath, webcamPath); + // 3. Perform background finalization (muxing, sidecars) + // We don't await this to keep the UI responsive + void (async () => { + try { + // Store sidecars + await storeMicrophoneSidecar( + micFallbackBlobPromise, + finalPath, + fallbackStartDelayMs, + fallbackTrackSettings, + ); - console.log( - `[PERF:RENDERER] Total Stop Sequence: COMPLETED in ${(performance.now() - stopStart).toFixed(2)}ms`, - ); + // Perform muxing/renaming if on Windows + if (isNativeWindows) { + await window.electronAPI.muxNativeWindowsRecording(expectedDurationMs); + } + + console.log( + `[PERF:RENDERER] Background Stop Sequence: COMPLETED in ${(performance.now() - stopStart).toFixed(2)}ms`, + ); + } catch (bgError) { + console.error("Error in background finalization:", bgError); + } + })(); })(); return; }