Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(desktop): add pipeline health monitoring and degraded state events

Richie McIlroyb911055cd21f
diff --git a/apps/desktop/src-tauri/src/recording.rs b/apps/desktop/src-tauri/src/recording.rs
index 281a0529c..c35bf7fec 100644
--- a/apps/desktop/src-tauri/src/recording.rs
+++ b/apps/desktop/src-tauri/src/recording.rs
@@ -220,6 +220,13 @@ impl InProgressRecording {
}
}
+ pub fn take_health_rx(&mut self) -> Option<cap_recording::HealthReceiver> {
+ match self {
+ Self::Instant { handle, .. } => handle.take_health_rx(),
+ Self::Studio { .. } => None,
+ }
+ }
+
pub async fn cancel(self) -> anyhow::Result<()> {
match self {
Self::Instant { handle, .. } => handle.cancel().await,
@@ -439,6 +446,8 @@ pub enum RecordingEvent {
Failed { error: String },
InputLost { input: RecordingInputKind },
InputRestored { input: RecordingInputKind },
+ Degraded { reason: String },
+ Recovered,
}
#[derive(Serialize, Type)]
@@ -848,7 +857,7 @@ pub async fn start_recording(
let mut mic_restart_attempts = 0;
- let done_fut = loop {
+ let (done_fut, health_rx) = loop {
let mic_feed = match state.mic_feed.ask(microphone::Lock).await {
Ok(lock) => Some(Arc::new(lock)),
Err(SendError::HandlerError(microphone::LockFeedError::NoInput)) => None,
@@ -974,10 +983,11 @@ pub async fn start_recording(
.await;
match actor_result {
- Ok(actor) => {
+ Ok(mut actor) => {
let done_fut = actor.done_fut();
+ let health_rx = actor.take_health_rx();
state.set_current_recording(actor);
- break done_fut;
+ break (done_fut, health_rx);
}
#[cfg(target_os = "macos")]
Err(err) if is_shareable_content_error(&err) => {
@@ -998,14 +1008,14 @@ pub async fn start_recording(
}
};
- Ok::<_, anyhow::Error>(done_fut)
+ Ok::<_, anyhow::Error>((done_fut, health_rx))
}
};
let actor_task_res = AssertUnwindSafe(actor_task).catch_unwind().await;
- let actor_done_fut = match actor_task_res {
- Ok(Ok(rx)) => rx,
+ let (actor_done_fut, health_rx) = match actor_task_res {
+ Ok(Ok(v)) => v,
Ok(Err(err)) => {
let message = format!("{err:#}");
handle_spawn_failure(
@@ -1067,7 +1077,6 @@ pub async fn start_recording(
dialog.blocking_show();
- // this clears the current recording for us
handle_recording_end(app, Err(e.to_string()), &mut state, project_file_path)
.await
.ok();
@@ -1076,6 +1085,41 @@ pub async fn start_recording(
}
});
+ if let Some(mut health_rx) = health_rx {
+ spawn_actor({
+ let app = app.clone();
+ async move {
+ let mut is_degraded = false;
+ while let Some(event) = health_rx.recv().await {
+ let reason = match &event {
+ cap_recording::PipelineHealthEvent::FrameDropRateHigh { rate_pct } => {
+ Some(format!("High frame drop rate: {rate_pct:.0}%"))
+ }
+ cap_recording::PipelineHealthEvent::AudioGapDetected { gap_ms } => {
+ Some(format!("Audio gap detected: {gap_ms}ms"))
+ }
+ cap_recording::PipelineHealthEvent::SourceRestarting => {
+ Some("Capture source restarting".to_string())
+ }
+ cap_recording::PipelineHealthEvent::SourceRestarted => None,
+ };
+
+ if let Some(reason) = reason {
+ if !is_degraded {
+ is_degraded = true;
+ RecordingEvent::Degraded { reason }.emit(&app).ok();
+ }
+ } else if matches!(event, cap_recording::PipelineHealthEvent::SourceRestarted)
+ && is_degraded
+ {
+ is_degraded = false;
+ RecordingEvent::Recovered.emit(&app).ok();
+ }
+ }
+ }
+ });
+ }
+
AppSounds::StartRecording.play();
Ok(RecordingAction::Started)