Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(export): prevent export progress from freezing at 102%

David Anyatonwufe92b384fd2e
diff --git a/apps/desktop/src-tauri/src/export.rs b/apps/desktop/src-tauri/src/export.rs
index fc022ef44..6c1300940 100644
--- a/apps/desktop/src-tauri/src/export.rs
+++ b/apps/desktop/src-tauri/src/export.rs
@@ -21,8 +21,8 @@ pub async fn export_video(
.await
.unwrap();
- // 30 FPS (calculated for output video)
- let total_frames = (duration * 30.0).round() as u32;
+ // Calculate total frames with ceiling to ensure we don't exceed 100%
+ let total_frames = ((duration * 30.0).ceil() as u32).max(1);
let editor_instance = upsert_editor_instance(&app, video_id.clone()).await;
@@ -41,9 +41,11 @@ pub async fn export_video(
project,
output_path.clone(),
move |frame_index| {
+ // Ensure progress never exceeds total frames
+ let current_frame = (frame_index + 1).min(total_frames);
progress
.send(RenderProgress::FrameRendered {
- current_frame: frame_index + 1,
+ current_frame,
})
.ok();
},
diff --git a/apps/desktop/src/routes/editor/Header.tsx b/apps/desktop/src/routes/editor/Header.tsx
index 2742f59b0..f2b14cbf9 100644
--- a/apps/desktop/src/routes/editor/Header.tsx
+++ b/apps/desktop/src/routes/editor/Header.tsx
@@ -260,14 +260,26 @@ function ExportButton() {
const progress = new Channel<RenderProgress>();
progress.onmessage = (p) => {
if (p.type === "FrameRendered" && progressState.type === "saving") {
- const percentComplete = Math.round(
- (p.current_frame / (progressState.totalFrames || 1)) * 100
+ const percentComplete = Math.min(
+ Math.round(
+ (p.current_frame / (progressState.totalFrames || 1)) * 100
+ ),
+ 100
);
+
setProgressState({
...progressState,
renderProgress: p.current_frame,
message: `Rendering video - ${percentComplete}%`,
});
+
+ // If rendering is complete, update the message
+ if (percentComplete === 100) {
+ setProgressState({
+ ...progressState,
+ message: "Finalizing export...",
+ });
+ }
}
if (
p.type === "EstimatedTotalFrames" &&
diff --git a/apps/desktop/src/routes/recordings-overlay.tsx b/apps/desktop/src/routes/recordings-overlay.tsx
index b0a6b2d69..83a1d6364 100644
--- a/apps/desktop/src/routes/recordings-overlay.tsx
+++ b/apps/desktop/src/routes/recordings-overlay.tsx
@@ -375,14 +375,26 @@ export default function () {
undefined &&
progressState.totalFrames
) {
- return `${Math.min(
+ const progress = Math.min(
Math.round(
(progressState.renderProgress /
progressState.totalFrames) *
100
),
100
- )}%`;
+ );
+
+ // If we hit 100%, transition to the next stage
+ if (progress === 100 && progressState.type === "uploading") {
+ setProgressState({
+ ...progressState,
+ stage: "uploading",
+ message: "Starting upload...",
+ uploadProgress: 0
+ });
+ }
+
+ return `${progress}%`;
}
return progressState.message;