Skip to content

Commit 45fefed

Browse files
committed
Fix screen capture restart logic and refactor path usage
1 parent 2225a86 commit 45fefed

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

apps/desktop/src-tauri/src/recording.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use std::{
2929
any::Any,
3030
collections::{HashMap, VecDeque},
3131
panic::AssertUnwindSafe,
32-
path::PathBuf,
32+
path::{Path, PathBuf},
3333
str::FromStr,
3434
sync::Arc,
3535
time::Duration,
@@ -647,13 +647,15 @@ pub async fn start_recording(
647647
Ok(Ok(rx)) => rx,
648648
Ok(Err(err)) => {
649649
let message = format!("{err:#}");
650-
handle_spawn_failure(&app, &state_mtx, &recording_dir, message.clone()).await?;
650+
handle_spawn_failure(&app, &state_mtx, recording_dir.as_path(), message.clone())
651+
.await?;
651652
return Err(message);
652653
}
653654
Err(panic) => {
654655
let panic_msg = panic_message(panic);
655656
let message = format!("Failed to spawn recording actor: {panic_msg}");
656-
handle_spawn_failure(&app, &state_mtx, &recording_dir, message.clone()).await?;
657+
handle_spawn_failure(&app, &state_mtx, recording_dir.as_path(), message.clone())
658+
.await?;
657659
return Err(message);
658660
}
659661
};
@@ -736,7 +738,7 @@ pub async fn resume_recording(state: MutableState<'_, App>) -> Result<(), String
736738
async fn handle_spawn_failure(
737739
app: &AppHandle,
738740
state_mtx: &MutableState<'_, App>,
739-
recording_dir: &PathBuf,
741+
recording_dir: &Path,
740742
message: String,
741743
) -> Result<(), String> {
742744
let _ = RecordingEvent::Failed {
@@ -758,8 +760,13 @@ async fn handle_spawn_failure(
758760
dialog.blocking_show();
759761

760762
let mut state = state_mtx.write().await;
761-
let _ =
762-
handle_recording_end(app.clone(), Err(message), &mut state, recording_dir.clone()).await;
763+
let _ = handle_recording_end(
764+
app.clone(),
765+
Err(message),
766+
&mut state,
767+
recording_dir.to_path_buf(),
768+
)
769+
.await;
763770

764771
Ok(())
765772
}

crates/recording/src/sources/screen_capture/macos.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,9 @@ impl output_pipeline::VideoSource for VideoSource {
386386

387387
if is_system_stop_error(err.as_ref()) {
388388
warn!("Screen capture stream stopped by the system; attempting restart");
389+
if monitor_cancel.is_cancelled() {
390+
break Ok(());
391+
}
389392
monitor_capturer.mark_stopped();
390393
if let Err(restart_err) = monitor_capturer.start().await {
391394
return Err(anyhow!(format!(

0 commit comments

Comments
 (0)