Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(desktop): stop losing recording-start clicks and surface start failures
Richie McIlroyad711f7e5303
diff --git a/apps/desktop/src-tauri/src/recording.rs b/apps/desktop/src-tauri/src/recording.rsindex 8a803c220..86ff90f49 100644--- a/apps/desktop/src-tauri/src/recording.rs+++ b/apps/desktop/src-tauri/src/recording.rs@@ -1127,12 +1127,28 @@ pub enum RecordingEvent {Paused,Resumed,Failed { error: String },+ // Emitted when start_recording aborts before any recording exists. Distinct from+ // `Failed` because the in-progress window treats `Failed` as "the active recording+ // died", which would misreport a healthy recording when a second start is refused.+ StartFailed { error: String },InputLost { input: RecordingInputKind },InputRestored { input: RecordingInputKind },Degraded { reason: String },Recovered,}+/// Every abort path out of `start_recording` must be observable: in the log, and as an+/// event the main window surfaces to the user. The picker overlay that invoked the+/// command is often already closed (or being torn down) when the error comes back, so+/// an error returned to the caller alone can vanish without a trace.+fn notify_recording_start_failed(app: &AppHandle, error: &str) {+ error!(%error, "Recording failed to start");+ let _ = RecordingEvent::StartFailed {+ error: error.to_string(),+ }+ .emit(app);+}+#[derive(Serialize, Type)]pub enum RecordingAction {Started,@@ -1480,7 +1496,15 @@ pub async fn start_recording({let mut app_state = state_mtx.write().await;- app_state.set_pending_recording(inputs.mode, inputs.capture_target.clone())?;+ if let Err(error) =+ app_state.set_pending_recording(inputs.mode, inputs.capture_target.clone())+ {+ drop(app_state);+ // Deliberately no clear_pending_recording: the pending/active state that+ // caused the refusal belongs to another recording and must survive.+ notify_recording_start_failed(&app, &error);+ return Err(error);+ }if is_camera_only {app_state.was_camera_only_recording = true;}@@ -1491,8 +1515,10 @@ pub async fn start_recording(match $expr {Ok(value) => value,Err(err) => {+ let error = ($map_err)(err);state_mtx.write().await.clear_pending_recording();- return Err(($map_err)(err));+ notify_recording_start_failed(&app, &error);+ return Err(error);}}};@@ -1502,8 +1528,10 @@ pub async fn start_recording(let operation_lock = app.state::<CameraWindowOperationLock>();let _operation_guard = operation_lock.lock().await;if let Err(err) = (ShowCapWindow::Camera { centered: true }).show(&app).await {+ let error = format!("Failed to show centered camera window: {err}");state_mtx.write().await.clear_pending_recording();- return Err(format!("Failed to show centered camera window: {err}"));+ notify_recording_start_failed(&app, &error);+ return Err(error);}}@@ -1537,16 +1565,18 @@ pub async fn start_recording(Ok(bytes) => {if bytes <= cap_utils::disk_space::LOW_DISK_STOP_BYTES {let gb = bytes as f64 / 1_073_741_824.0;+ let error = format!(+ "Not enough disk space to start recording ({:.2} GB free). Free up at least {} MB and try again.",+ gb,+ (cap_utils::disk_space::LOW_DISK_STOP_BYTES / (1024 * 1024))+ );error!(bytes_remaining = bytes,"Refusing to start recording: disk full");state_mtx.write().await.clear_pending_recording();- return Err(format!(- "Not enough disk space to start recording ({:.2} GB free). Free up at least {} MB and try again.",- gb,- (cap_utils::disk_space::LOW_DISK_STOP_BYTES / (1024 * 1024))- ));+ notify_recording_start_failed(&app, &error);+ return Err(error);}if bytes <= cap_utils::disk_space::LOW_DISK_WARN_BYTES {let gb = bytes as f64 / 1_073_741_824.0;@@ -1591,8 +1621,10 @@ pub async fn start_recording(let (video_upload_info, instant_mode_max_resolution) = match inputs.mode {RecordingMode::Instant => {let Some(auth) = AuthStore::get(&app).ok().flatten() else {+ let error = "Please sign in to use instant recording".to_string();state_mtx.write().await.clear_pending_recording();- return Err("Please sign in to use instant recording".to_string());+ notify_recording_start_failed(&app, &error);+ return Err(error);};let instant_mode_max_resolution = if auth.is_upgraded() {general_settings@@ -1622,16 +1654,27 @@ pub async fn start_recording(Ok(meta) => meta,Err(AuthedApiError::InvalidAuthentication) => {state_mtx.write().await.clear_pending_recording();+ // Returned as an action rather than an error, but the picker that+ // invoked us may already be gone — surface it as a start failure too.+ notify_recording_start_failed(+ &app,+ "Your session has expired. Please sign in again to use instant recording.",+ );return Ok(RecordingAction::InvalidAuthentication);}Err(AuthedApiError::UpgradeRequired) => {state_mtx.write().await.clear_pending_recording();+ notify_recording_start_failed(+ &app,+ "Instant recording requires an upgraded plan.",+ );return Ok(RecordingAction::UpgradeRequired);}Err(err) => {- error!("Error creating instant mode video: {err}");+ let error = format!("Could not create the shareable link: {err}");state_mtx.write().await.clear_pending_recording();- return Err(err.to_string());+ notify_recording_start_failed(&app, &error);+ return Err(error);}};@@ -1649,8 +1692,10 @@ pub async fn start_recording(}RecordingMode::Studio => (None, cap_recording::PRO_INSTANT_MODE_MAX_RESOLUTION),RecordingMode::Screenshot => {+ let error = "Use take_screenshot for screenshots".to_string();state_mtx.write().await.clear_pending_recording();- return Err("Use take_screenshot for screenshots".to_string());+ notify_recording_start_failed(&app, &error);+ return Err(error);}};diff --git a/apps/desktop/src/routes/(window-chrome)/new-main/index.tsx b/apps/desktop/src/routes/(window-chrome)/new-main/index.tsxindex ec6c7a63c..2d0edfb7d 100644--- a/apps/desktop/src/routes/(window-chrome)/new-main/index.tsx+++ b/apps/desktop/src/routes/(window-chrome)/new-main/index.tsx@@ -31,6 +31,7 @@ import {} from "solid-js";import { createStore, produce, reconcile } from "solid-js/store";import { Transition } from "solid-transition-group";+import toast from "solid-toast";import Mode from "~/components/Mode";import { RecoveryToast } from "~/components/RecoveryToast";import Tooltip from "~/components/Tooltip";@@ -1920,6 +1921,19 @@ function Page() {events.recordingStopped,refetchRecordingsUnlessEditorRecording,);+ // Start failures happen before the in-progress window exists, and the picker+ // overlay that invoked start_recording may already be dismissed — this window+ // is the only reliable surface for telling the user why nothing started. The+ // picker flow also hides this window, so reveal it first or the toast lands+ // in a hidden webview and the failure is invisible again.+ createTauriEventListener(events.recordingEvent, (payload) => {+ if (payload.variant === "StartFailed") {+ const currentWindow = getCurrentWindow();+ void currentWindow.show();+ void currentWindow.setFocus();+ toast.error(payload.error);+ }+ });const handleReupload = async (path: string) => {setReuploadingPaths((prev) => new Set([...prev, path]));diff --git a/apps/desktop/src/routes/target-select-overlay.tsx b/apps/desktop/src/routes/target-select-overlay.tsxindex aec0b4d02..925707752 100644--- a/apps/desktop/src/routes/target-select-overlay.tsx+++ b/apps/desktop/src/routes/target-select-overlay.tsx@@ -335,7 +335,19 @@ function Inner() {} else {setOptions({ targetMode: null, targetModeDismissal });}- commands.closeTargetSelectOverlays();+ // Hide rather than close: startRecording is invoked from THIS webview right+ // after dismissal, and closing destroys the webview before the invoke is+ // dispatched — the recording then silently never starts. The backend closes+ // these windows itself once the recording is underway, and the start handler+ // closes them if the command fails.+ void WebviewWindow.getAll().then((all) => {+ for (const win of all) {+ if (win.label.startsWith("target-select-overlay-")) {+ void win.setIgnoreCursorEvents(true);+ void win.hide();+ }+ }+ });};// This prevents browser keyboard shortcuts from firing.@@ -1804,8 +1816,19 @@ function RecordingControls(props: {mode: rawOptions.mode,capture_system_audio: rawOptions.captureSystemAudio,})+ .then((action) => {+ // On success the backend closes the overlay windows; the+ // non-Started actions leave our hidden windows behind.+ // User-facing feedback for them arrives via the backend's+ // StartFailed event in the main window.+ if (action !== "Started")+ void commands.closeTargetSelectOverlays();+ }).catch((e: unknown) => {const msg = e instanceof Error ? e.message : String(e);+ // This webview is hidden by now, so the toast is a+ // best-effort extra — the visible feedback comes from the+ // backend's StartFailed event toasted in the main window.if (msg.includes("no longer available") ||msg.includes("DeviceNotFound")@@ -1816,6 +1839,14 @@ function RecordingControls(props: {} else {toast.error(`Failed to start recording: ${msg}`);}+ // An IPC-level rejection never reaches the backend, so no+ // StartFailed event fires; the picker flow hid the main+ // window and dismissal closed the overlays — without this,+ // the whole app visually vanishes with no recording.+ void commands.showWindow({+ Main: { init_target_mode: null },+ });+ void commands.closeTargetSelectOverlays();});}}>diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.tsindex 5bd24af2e..d0daef9d8 100644--- a/apps/desktop/src/utils/tauri.ts+++ b/apps/desktop/src/utils/tauri.ts@@ -837,7 +837,7 @@ textSizeVersion?: number }export type ProjectRecordingsMeta = { segments: SegmentRecordings[] }export type RecordingAction = "Started" | "InvalidAuthentication" | "UpgradeRequired"export type RecordingDeleted = { path: string }-export type RecordingEvent = { variant: "Countdown"; value: number } | { variant: "Started" } | { variant: "Stopped" } | { variant: "Paused" } | { variant: "Resumed" } | { variant: "Failed"; error: string } | { variant: "InputLost"; input: RecordingInputKind } | { variant: "InputRestored"; input: RecordingInputKind } | { variant: "Degraded"; reason: string } | { variant: "Recovered" }+export type RecordingEvent = { variant: "Countdown"; value: number } | { variant: "Started" } | { variant: "Stopped" } | { variant: "Paused" } | { variant: "Resumed" } | { variant: "Failed"; error: string } | { variant: "StartFailed"; error: string } | { variant: "InputLost"; input: RecordingInputKind } | { variant: "InputRestored"; input: RecordingInputKind } | { variant: "Degraded"; reason: string } | { variant: "Recovered" }export type RecordingInputKind = "microphone" | "camera"export type RecordingMeta = (StudioRecordingMeta | InstantRecordingMeta) & { platform?: Platform | null; pretty_name: string; sharing?: SharingMeta | null; upload?: UploadMeta | null }export type RecordingMetaWithMetadata = ((StudioRecordingMeta | InstantRecordingMeta) & { platform?: Platform | null; pretty_name: string; sharing?: SharingMeta | null; upload?: UploadMeta | null }) & { mode: RecordingMode; status: StudioRecordingStatus; clip_count: number }