Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
Simplify export flow and remove no-progress APIs
Richie McIlroyb7f28169fd2b
diff --git a/apps/desktop/src-tauri/src/export.rs b/apps/desktop/src-tauri/src/export.rsindex e3fc3b30e..82914df8b 100644--- a/apps/desktop/src-tauri/src/export.rs+++ b/apps/desktop/src-tauri/src/export.rs@@ -97,21 +97,11 @@ impl ExportWorkerMode {}#[derive(Clone)]-enum ExportProgress {- Channel(tauri::ipc::Channel<FramesRendered>),- Disabled,-}+struct ExportProgress(tauri::ipc::Channel<FramesRendered>);impl ExportProgress {fn send(&self, progress: FramesRendered) -> bool {- match self {- Self::Channel(channel) => channel.send(progress).is_ok(),- Self::Disabled => true,- }- }-- fn enabled(&self) -> bool {- matches!(self, Self::Channel(_))+ self.0.send(progress).is_ok()}}@@ -128,15 +118,7 @@ impl ExportProgressForwarder {}}- fn enabled(&self) -> bool {- self.progress.enabled()- }-fn send(&mut self, rendered_count: u32, total_frames: u32) -> bool {- if !self.progress.enabled() {- return true;- }-let now = std::time::Instant::now();let should_emit = rendered_count == 0|| rendered_count >= total_frames@@ -191,18 +173,6 @@ pub fn export_session_active() -> bool {ACTIVE_EXPORT_SESSIONS.load(Ordering::Acquire) > 0}-#[tauri::command]-#[specta::specta]-pub fn begin_export_session() {- retain_export_session();-}--#[tauri::command]-#[specta::specta]-pub fn end_export_session() {- release_export_session();-}-struct ExportSessionGuard;impl ExportSessionGuard {@@ -295,11 +265,7 @@ async fn run_out_of_process_export_attempt(.stdout(Stdio::piped()).stderr(Stdio::piped());- if progress_forwarder.enabled() {- command.arg("--progress-json");- } else {- command.arg("--completion-json");- }+ command.arg("--progress-json");if force_ffmpeg_decoder {command.arg("--force-ffmpeg-decoder");@@ -429,15 +395,6 @@ fn resolve_exporter_binary() -> Result<PathBuf, String> {let exe = std::env::current_exe().map_err(|e| format!("current_exe: {e}"))?;if let Some(dir) = exe.parent() {- // In dev, `cap.exe` is the binary Cargo rebuilds; stale `cap-exporter.exe` copies were- // the reason desktop exports lagged behind the fast CLI path during this fix.- if cfg!(debug_assertions) {- let candidate = dir.join(cli_bin_name());- if candidate.exists() {- return Ok(candidate);- }- }-let candidate = dir.join(exporter_bin_name());if candidate.exists() {return Ok(candidate);@@ -467,8 +424,6 @@ fn resolve_exporter_binary() -> Result<PathBuf, String> {fn exporter_binary_candidates(root: &Path) -> Vec<PathBuf> {let mut candidates = vec![- root.join("target").join("debug").join(cli_bin_name()),- root.join("target").join("release").join(cli_bin_name()),root.join("apps").join("desktop").join("src-tauri")@@ -478,14 +433,6 @@ fn exporter_binary_candidates(root: &Path) -> Vec<PathBuf> {if let Some(target_triple) = current_target_triple() {candidates.extend([- root.join("target")- .join(target_triple)- .join("debug")- .join(cli_bin_name()),- root.join("target")- .join(target_triple)- .join("release")- .join(cli_bin_name()),root.join("apps").join("desktop").join("src-tauri")@@ -494,9 +441,22 @@ fn exporter_binary_candidates(root: &Path) -> Vec<PathBuf> {"cap-exporter-{target_triple}{}",std::env::consts::EXE_SUFFIX)),+ root.join("target")+ .join(target_triple)+ .join("release")+ .join(cli_bin_name()),+ root.join("target")+ .join(target_triple)+ .join("debug")+ .join(cli_bin_name()),]);}+ candidates.extend([+ root.join("target").join("release").join(cli_bin_name()),+ root.join("target").join("debug").join(cli_bin_name()),+ ]);+candidates}@@ -675,18 +635,10 @@ fn should_force_ffmpeg_export(_project_path: &Path, settings: &ExportSettings) -settings.force_ffmpeg_decoder()}-fn should_force_ffmpeg_preview() -> bool {- should_use_windows_release_ffmpeg_workaround()-}-fn should_use_out_of_process_export() -> bool {cfg!(any(target_os = "macos", target_os = "windows"))}-fn should_use_windows_release_ffmpeg_workaround() -> bool {- cfg!(all(target_os = "windows", not(debug_assertions)))-}-#[tauri::command]#[specta::specta]#[instrument(skip(progress, editor))]@@ -696,46 +648,7 @@ pub async fn export_video(settings: ExportSettings,editor: OptionalWindowEditorInstance,) -> Result<PathBuf, String> {- export_video_inner(- project_path,- settings,- editor,- ExportProgress::Channel(progress),- )- .await-}--#[tauri::command]-#[specta::specta]-#[instrument(skip(editor))]-pub async fn export_video_no_progress(- project_path: PathBuf,- settings: ExportSettings,- editor: OptionalWindowEditorInstance,-) -> Result<PathBuf, String> {- export_video_inner(project_path, settings, editor, ExportProgress::Disabled).await-}--#[tauri::command]-#[specta::specta]-#[instrument(skip(settings_json))]-pub async fn export_video_no_progress_detached(- project_path: PathBuf,- settings_json: String,-) -> Result<PathBuf, String> {- info!(- project_path = %project_path.display(),- "Starting detached no-progress export command"- );- let settings = serde_json::from_str::<ExportSettings>(&settings_json)- .map_err(|e| format!("Invalid export settings JSON: {e}"))?;- export_video_inner(- project_path,- settings,- OptionalWindowEditorInstance(None),- ExportProgress::Disabled,- )- .await+ export_video_inner(project_path, settings, editor, ExportProgress(progress)).await}async fn export_video_inner(@@ -749,7 +662,6 @@ async fn export_video_inner(info!(project_path = %project_path.display(),force_ffmpeg,- progress = progress.enabled(),settings = ?settings,"Starting export");@@ -993,7 +905,7 @@ async fn generate_export_preview_inner(.map_err(|e| format!("Failed to create render constants: {e}"))?,);- let force_ffmpeg = should_force_ffmpeg_preview();+ let force_ffmpeg = false;info!(project_path = %project_path.display(),force_ffmpeg,@@ -1207,7 +1119,7 @@ mod tests {#[cfg(target_os = "windows")]#[test]- fn windows_exports_force_ffmpeg_in_release_builds_without_explicit_setting() {+ fn windows_exports_do_not_force_ffmpeg_without_explicit_setting() {let dir = tempdir().unwrap();let gif_settings = ExportSettings::Gif(cap_export::gif::GifExportSettings {@@ -1216,10 +1128,7 @@ mod tests {quality: None,});- assert_eq!(- should_force_ffmpeg_export(dir.path(), &gif_settings),- !cfg!(debug_assertions)- );+ assert!(!should_force_ffmpeg_export(dir.path(), &gif_settings));}}diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rsindex cbf29ca46..61410a4c2 100644--- a/apps/desktop/src-tauri/src/lib.rs+++ b/apps/desktop/src-tauri/src/lib.rs@@ -3922,11 +3922,7 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {fake_window::remove_fake_window,focus_captures_panel,get_current_recording,- export::begin_export_session,- export::end_export_session,export::export_video,- export::export_video_no_progress,- export::export_video_no_progress_detached,export::get_export_estimates,export::generate_export_preview,export::generate_export_preview_fast,diff --git a/apps/desktop/src/utils/export.ts b/apps/desktop/src/utils/export.tsindex b8aa01ee0..98e262c7d 100644--- a/apps/desktop/src/utils/export.ts+++ b/apps/desktop/src/utils/export.ts@@ -1,4 +1,4 @@-import { Channel, invoke } from "@tauri-apps/api/core";+import { Channel } from "@tauri-apps/api/core";import { commands, type ExportSettings, type FramesRendered } from "./tauri";export function createExportTask(@@ -6,40 +6,6 @@ export function createExportTask(settings: ExportSettings,onProgress: (progress: FramesRendered) => void,) {- if (!import.meta.env.DEV) {- const promise = (async () => {- await invoke("begin_export_session");- try {- const exportPromise = invoke<string>(- "export_video_no_progress_detached",- {- projectPath,- settingsJson: JSON.stringify(settings),- },- );- try {- onProgress({- renderedCount: 0,- totalFrames: 1,- type: "FramesRendered",- });- } catch (error) {- console.error("Failed to handle initial export progress", error);- }- return await exportPromise;- } finally {- await invoke("end_export_session").catch((error) => {- console.error("Failed to release export session guard", error);- });- }- })();-- return {- cancel: () => {},- promise,- };- }-const progress = new Channel<FramesRendered>((e) => {onProgress(e);});diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.tsindex b57a57099..262665679 100644--- a/apps/desktop/src/utils/tauri.ts+++ b/apps/desktop/src/utils/tauri.ts@@ -92,21 +92,9 @@ async focusCapturesPanel() : Promise<void> {async getCurrentRecording() : Promise<JsonValue<CurrentRecording | null>> {return await TAURI_INVOKE("get_current_recording");},-async beginExportSession() : Promise<void> {- await TAURI_INVOKE("begin_export_session");-},-async endExportSession() : Promise<void> {- await TAURI_INVOKE("end_export_session");-},async exportVideo(projectPath: string, progress: TAURI_CHANNEL<FramesRendered>, settings: ExportSettings) : Promise<string> {return await TAURI_INVOKE("export_video", { projectPath, progress, settings });},-async exportVideoNoProgress(projectPath: string, settings: ExportSettings) : Promise<string> {- return await TAURI_INVOKE("export_video_no_progress", { projectPath, settings });-},-async exportVideoNoProgressDetached(projectPath: string, settingsJson: string) : Promise<string> {- return await TAURI_INVOKE("export_video_no_progress_detached", { projectPath, settingsJson });-},async getExportEstimates(path: string, settings: ExportSettings) : Promise<ExportEstimates> {return await TAURI_INVOKE("get_export_estimates", { path, settings });},