Skip to content

Commit

Permalink
fix(export): check pro access before export and fix progress UI
Browse files Browse the repository at this point in the history
Signed-off-by: David Anyatonwu <davidanyatonwu@gmail.com>
  • Loading branch information
onyedikachi-david committed Dec 28, 2024
1 parent fe92b38 commit 173abf9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 38 deletions.
36 changes: 22 additions & 14 deletions apps/desktop/src-tauri/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ pub async fn export_video(
force: bool,
use_custom_muxer: bool,
) -> Result<PathBuf, String> {
let VideoRecordingMetadata { duration, .. } =
get_video_metadata(app.clone(), video_id.clone(), Some(VideoType::Screen))
.await
.unwrap();
let metadata = match get_video_metadata(app.clone(), video_id.clone(), Some(VideoType::Screen)).await {
Ok(meta) => meta,
Err(e) => {
sentry::capture_message(&format!("Failed to get video metadata: {}", e), sentry::Level::Error);
return Err("Failed to read video metadata. The recording may be from an incompatible version.".to_string());
}
};

let VideoRecordingMetadata { duration, .. } = metadata;

// Calculate total frames with ceiling to ensure we don't exceed 100%
let total_frames = ((duration * 30.0).ceil() as u32).max(1);
Expand All @@ -28,7 +33,7 @@ pub async fn export_video(

let output_path = editor_instance.meta().output_path();

// If the file exists, return it immediately
// If the file exists and we're not forcing a re-render, return it
if output_path.exists() && !force {
return Ok(output_path);
}
Expand Down Expand Up @@ -59,17 +64,20 @@ pub async fn export_video(
e.to_string()
})?;

if use_custom_muxer {
let result = if use_custom_muxer {
exporter.export_with_custom_muxer().await
} else {
exporter.export_with_ffmpeg_cli().await
}
.map_err(|e| {
sentry::capture_message(&e.to_string(), sentry::Level::Error);
e.to_string()
})?;
};

ShowCapWindow::PrevRecordings.show(&app).ok();

Ok(output_path)
match result {
Ok(_) => {
ShowCapWindow::PrevRecordings.show(&app).ok();
Ok(output_path)
}
Err(e) => {
sentry::capture_message(&e.to_string(), sentry::Level::Error);
Err(e.to_string())
}
}
}
56 changes: 32 additions & 24 deletions apps/desktop/src/routes/editor/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ import { save } from "@tauri-apps/plugin-dialog";
import { DEFAULT_PROJECT_CONFIG } from "./projectConfig";
import { createMutation } from "@tanstack/solid-query";
import { getRequestEvent } from "solid-js/web";
import { checkIsUpgradedAndUpdate } from "~/utils/plans";

function ExportButton() {
const { videoId, project, prettyName } = useEditorContext();
Expand All @@ -261,9 +262,7 @@ function ExportButton() {
progress.onmessage = (p) => {
if (p.type === "FrameRendered" && progressState.type === "saving") {
const percentComplete = Math.min(
Math.round(
(p.current_frame / (progressState.totalFrames || 1)) * 100
),
Math.round((p.current_frame / (progressState.totalFrames || 1)) * 100),
100
);

Expand All @@ -273,18 +272,15 @@ function ExportButton() {
message: `Rendering video - ${percentComplete}%`,
});

// If rendering is complete, update the message
// If rendering is complete, update to finalizing state
if (percentComplete === 100) {
setProgressState({
...progressState,
message: "Finalizing export...",
});
}
}
if (
p.type === "EstimatedTotalFrames" &&
progressState.type === "saving"
) {
if (p.type === "EstimatedTotalFrames" && progressState.type === "saving") {
setProgressState({
...progressState,
totalFrames: p.total_frames,
Expand All @@ -293,25 +289,30 @@ function ExportButton() {
}
};

const videoPath = await commands.exportVideo(
videoId,
project,
progress,
true,
useCustomMuxer
);
await commands.copyFileToPath(videoPath, path);
try {
const videoPath = await commands.exportVideo(
videoId,
project,
progress,
true,
useCustomMuxer
);
await commands.copyFileToPath(videoPath, path);

setProgressState({
type: "saving",
progress: 100,
message: "Saved successfully!",
mediaPath: path,
});
setProgressState({
type: "saving",
progress: 100,
message: "Saved successfully!",
mediaPath: path,
});

setTimeout(() => {
setTimeout(() => {
setProgressState({ type: "idle" });
}, 1500);
} catch (error) {
setProgressState({ type: "idle" });
}, 1500);
throw error;
}
},
}));

Expand Down Expand Up @@ -342,6 +343,13 @@ function ShareButton() {
throw new Error("Recording metadata not available");
}

// Check for pro access first before starting the export
const isUpgraded = await checkIsUpgradedAndUpdate();
if (!isUpgraded) {
await commands.showWindow("Upgrade");
throw new Error("Upgrade required to share recordings");
}

let unlisten: (() => void) | undefined;

try {
Expand Down

0 comments on commit 173abf9

Please sign in to comment.