Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix file export from ExportDialog (#437)

Brendan Allan5f1aa8f223a8
diff --git a/apps/desktop/src-tauri/src/export.rs b/apps/desktop/src-tauri/src/export.rs
index c7d95fec8..ba2805cc4 100644
--- a/apps/desktop/src-tauri/src/export.rs
+++ b/apps/desktop/src-tauri/src/export.rs
@@ -1,6 +1,5 @@
use crate::{create_editor_instance_impl, get_video_metadata, RenderProgress};
-use cap_editor::EditorInstance;
-use cap_project::{ProjectConfiguration, RecordingMeta, XY};
+use cap_project::{RecordingMeta, XY};
use std::path::PathBuf;
use tauri::AppHandle;
@@ -8,24 +7,26 @@ use tauri::AppHandle;
#[specta::specta]
pub async fn export_video(
app: AppHandle,
- path: PathBuf,
+ project_path: PathBuf,
progress: tauri::ipc::Channel<RenderProgress>,
fps: u32,
resolution_base: XY<u32>,
) -> Result<PathBuf, String> {
- let editor_instance = create_editor_instance_impl(&app, path.clone()).await?;
-
- let screen_metadata = get_video_metadata(path.clone()).await.map_err(|e| {
- sentry::capture_message(
- &format!("Failed to get video metadata: {}", e),
- sentry::Level::Error,
- );
- "Failed to read video metadata. The recording may be from an incompatible version."
- .to_string()
- })?;
+ let editor_instance = create_editor_instance_impl(&app, project_path.clone()).await?;
+
+ let screen_metadata = get_video_metadata(project_path.clone())
+ .await
+ .map_err(|e| {
+ sentry::capture_message(
+ &format!("Failed to get video metadata: {}", e),
+ sentry::Level::Error,
+ );
+ "Failed to read video metadata. The recording may be from an incompatible version."
+ .to_string()
+ })?;
// Get camera metadata if it exists
- let camera_metadata = get_video_metadata(path.clone()).await.ok();
+ let camera_metadata = get_video_metadata(project_path.clone()).await.ok();
// Use the longer duration between screen and camera
let duration = screen_metadata.duration.max(
diff --git a/apps/desktop/src/routes/editor/ExportDialog.tsx b/apps/desktop/src/routes/editor/ExportDialog.tsx
index 576e80568..217cfc9bd 100644
--- a/apps/desktop/src/routes/editor/ExportDialog.tsx
+++ b/apps/desktop/src/routes/editor/ExportDialog.tsx
@@ -95,7 +95,7 @@ const ExportDialog = () => {
const selectedStyle =
"ring-1 ring-offset-2 ring-offset-gray-200 bg-gray-300 ring-gray-500";
- const path = editorInstance.path;
+ const projectPath = editorInstance.path;
const [exportEstimates] = createResource(
() => ({
@@ -105,7 +105,8 @@ const ExportDialog = () => {
},
fps: settings.fps,
}),
- (params) => commands.getExportEstimates(path, params.resolution, params.fps)
+ (params) =>
+ commands.getExportEstimates(projectPath, params.resolution, params.fps)
);
const exportButtonIcon: Record<"file" | "clipboard" | "link", JSX.Element> = {
file: <IconCapFile class="text-solid-white size-4" />,
@@ -149,7 +150,7 @@ const ExportDialog = () => {
// First try to get existing rendered video
const outputPath = await commands.exportVideo(
- path,
+ projectPath,
progress,
settings.fps,
{
@@ -187,23 +188,23 @@ const ExportDialog = () => {
}));
const [recordingMeta, metaActions] = createResource(() =>
- commands.getRecordingMeta(path, "recording")
+ commands.getRecordingMeta(projectPath, "recording")
);
const exportWithSettings = createMutation(() => ({
mutationFn: async () => {
setExportState({ type: "idle" });
- const path = await save({
+ const outputPath = await save({
filters: [{ name: "mp4 filter", extensions: ["mp4"] }],
defaultPath: `~/Desktop/${prettyName()}.mp4`,
});
- if (!path) return;
+ if (!outputPath) return;
trackEvent("export_started", {
resolution: settings.resolution,
fps: settings.fps,
- path: path,
+ path: outputPath,
});
setExportState({ type: "starting" });
@@ -235,7 +236,7 @@ const ExportDialog = () => {
try {
const videoPath = await commands.exportVideo(
- path,
+ projectPath,
progress,
settings.fps,
{
@@ -246,7 +247,7 @@ const ExportDialog = () => {
setExportState({ type: "saving", done: false });
- await commands.copyFileToPath(videoPath, path);
+ await commands.copyFileToPath(videoPath, outputPath);
setExportState({ type: "saving", done: true });
//needs to be here so if the user cancels file selection the dialog does not close
@@ -298,7 +299,7 @@ const ExportDialog = () => {
throw new Error("Recording metadata not available");
}
- const metadata = await commands.getVideoMetadata(path);
+ const metadata = await commands.getVideoMetadata(projectPath);
const plan = await commands.checkUpgradedAndUpdate();
const canShare = {
allowed: plan || metadata.duration < 300,
@@ -357,7 +358,7 @@ const ExportDialog = () => {
);
};
- await commands.exportVideo(path, progress, settings.fps, {
+ await commands.exportVideo(projectPath, progress, settings.fps, {
x: settings.resolution.width,
y: settings.resolution.height,
});
@@ -366,8 +367,8 @@ const ExportDialog = () => {
// Now proceed with upload
const result = recordingMeta()?.sharing
- ? await commands.uploadExportedVideo(path, "Reupload")
- : await commands.uploadExportedVideo(path, {
+ ? await commands.uploadExportedVideo(projectPath, "Reupload")
+ : await commands.uploadExportedVideo(projectPath, {
Initial: { pre_created_video: null },
});
@@ -393,7 +394,7 @@ const ExportDialog = () => {
onSuccess: () => {
metaActions.refetch();
setUploadState({ type: "complete" });
- metaUpdateStore.notifyUpdate(path);
+ metaUpdateStore.notifyUpdate(projectPath);
},
onError: (error) => {
commands.globalMessageDialog(
diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.ts
index 2823ebca3..f20889c05 100644
--- a/apps/desktop/src/utils/tauri.ts
+++ b/apps/desktop/src/utils/tauri.ts
@@ -53,8 +53,8 @@ async focusCapturesPanel() : Promise<void> {
async getCurrentRecording() : Promise<JsonValue<CurrentRecording | null>> {
return await TAURI_INVOKE("get_current_recording");
},
-async exportVideo(path: string, progress: TAURI_CHANNEL<RenderProgress>, fps: number, resolutionBase: XY<number>) : Promise<string> {
- return await TAURI_INVOKE("export_video", { path, progress, fps, resolutionBase });
+async exportVideo(projectPath: string, progress: TAURI_CHANNEL<RenderProgress>, fps: number, resolutionBase: XY<number>) : Promise<string> {
+ return await TAURI_INVOKE("export_video", { projectPath, progress, fps, resolutionBase });
},
async getExportEstimates(path: string, resolution: XY<number>, fps: number) : Promise<ExportEstimates> {
return await TAURI_INVOKE("get_export_estimates", { path, resolution, fps });