Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix metadata for pause/resume

Brendan Allan808e5828fa48
diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs
index 6762371b1..91f3797f3 100644
--- a/apps/desktop/src-tauri/src/lib.rs
+++ b/apps/desktop/src-tauri/src/lib.rs
@@ -988,66 +988,47 @@ async fn get_video_metadata(
.join("recordings")
.join(format!("{}.cap", video_id));
- let mut meta = RecordingMeta::load_for_project(&project_path)?;
+ let meta = RecordingMeta::load_for_project(&project_path)?;
- fn get_duration_for_paths(paths: Vec<PathBuf>) -> Result<f64, String> {
- let mut max_duration: f64 = 0.0;
- for path in paths {
- let reader = BufReader::new(
- File::open(&path).map_err(|e| format!("Failed to open video file: {}", e))?,
- );
- let file_size = path
- .metadata()
- .map_err(|e| format!("Failed to get file metadata: {}", e))?
- .len();
-
- let current_duration = match Mp4Reader::read_header(reader, file_size) {
- Ok(mp4) => mp4.duration().as_secs_f64(),
- Err(e) => {
- println!(
- "Failed to read MP4 header: {}. Falling back to default duration.",
- e
- );
- 0.0_f64
- }
- };
- max_duration = max_duration.max(current_duration);
- }
- Ok(max_duration)
- }
+ fn get_duration_for_path(path: PathBuf) -> Result<f64, String> {
+ let reader = BufReader::new(
+ File::open(&path).map_err(|e| format!("Failed to open video file: {}", e))?,
+ );
+ let file_size = path
+ .metadata()
+ .map_err(|e| format!("Failed to get file metadata: {}", e))?
+ .len();
- fn content_paths(project_path: &PathBuf, meta: &RecordingMeta) -> Vec<PathBuf> {
- match &meta.content {
- Content::SingleSegment { segment } => {
- vec![meta.path(&segment.display.path)]
+ let current_duration = match Mp4Reader::read_header(reader, file_size) {
+ Ok(mp4) => mp4.duration().as_secs_f64(),
+ Err(e) => {
+ println!(
+ "Failed to read MP4 header: {}. Falling back to default duration.",
+ e
+ );
+ 0.0_f64
}
- Content::MultipleSegments { inner } => inner
- .segments
- .iter()
- .map(|s| meta.path(&s.display.path))
- .collect(),
- }
- }
+ };
- // Get display duration
- let display_duration = get_duration_for_paths(content_paths(&project_path, &meta))?;
+ Ok(current_duration)
+ }
- // Get camera duration
- let camera_paths = match &meta.content {
- Content::SingleSegment { segment } => segment
- .camera
- .as_ref()
- .map_or(vec![], |c| vec![meta.path(&c.path)]),
+ let display_paths = match &meta.content {
+ Content::SingleSegment { segment } => {
+ vec![meta.path(&segment.display.path)]
+ }
Content::MultipleSegments { inner } => inner
.segments
.iter()
- .filter_map(|s| s.camera.as_ref().map(|c| meta.path(&c.path)))
+ .map(|s| meta.path(&s.display.path))
.collect(),
};
- let camera_duration = get_duration_for_paths(camera_paths)?;
- // Use the longer duration
- let duration = display_duration.max(camera_duration);
+ // Use the shorter duration
+ let duration = display_paths
+ .into_iter()
+ .map(get_duration_for_path)
+ .sum::<Result<_, _>>()?;
// Calculate estimated size using same logic as get_export_estimates
let (width, height) = (1920, 1080); // Default to 1080p
diff --git a/apps/desktop/src/routes/in-progress-recording.tsx b/apps/desktop/src/routes/in-progress-recording.tsx
index 07b0627bd..d7996e14e 100644
--- a/apps/desktop/src/routes/in-progress-recording.tsx
+++ b/apps/desktop/src/routes/in-progress-recording.tsx
@@ -8,6 +8,7 @@ import {
createOptionsQuery,
createCurrentRecordingQuery,
} from "~/utils/queries";
+import { createStore, produce } from "solid-js/store";
const audioLevelStore = {
level: 0,
@@ -48,6 +49,14 @@ export default function () {
const currentRecording = createCurrentRecordingQuery();
const { options } = createOptionsQuery();
+ const [pauseResumes, setPauseResumes] = createStore<
+ | []
+ | [
+ ...Array<{ pause: number; resume?: number }>,
+ { pause: number; resume?: number }
+ ]
+ >([]);
+
const isAudioEnabled = () => {
return options.data?.audioInputName != null;
};
@@ -97,11 +106,19 @@ export default function () {
mutationFn: async () => {
if (isPaused()) {
await commands.resumeRecording();
+ setPauseResumes(
+ produce((a) => {
+ if (a.length === 0) return a;
+ a[a.length - 1].resume = Date.now();
+ })
+ );
setIsPaused(false);
} else {
await commands.pauseRecording();
+ setPauseResumes((a) => [...a, { pause: Date.now() }]);
setIsPaused(true);
}
+ setTime(Date.now());
},
}));
@@ -114,6 +131,14 @@ export default function () {
},
}));
+ const adjustedTime = () => {
+ let t = time() - start;
+ for (const { pause, resume } of pauseResumes) {
+ if (pause && resume) t -= resume - pause;
+ }
+ return t;
+ };
+
return (
<div class="flex flex-row items-stretch bg-gray-500 dark:bg-gray-50 w-full h-full animate-in fade-in">
<div class="flex flex-row justify-between p-[0.25rem] flex-1">
@@ -125,7 +150,7 @@ export default function () {
>
<IconCapStopCircle />
<span class="font-[500] text-[0.875rem]">
- {formatTime((time() - start) / 1000)}
+ {formatTime(adjustedTime() / 1000)}
</span>
</button>
diff --git a/apps/desktop/src/routes/recordings-overlay.tsx b/apps/desktop/src/routes/recordings-overlay.tsx
index e154fc7c7..2203256f1 100644
--- a/apps/desktop/src/routes/recordings-overlay.tsx
+++ b/apps/desktop/src/routes/recordings-overlay.tsx
@@ -388,48 +388,43 @@ export default function () {
</Button>
</div>
</div>
- <Show when={metadata()}>
+ <Show when={metadata.latest}>
{(metadata) => (
<div
style={{
- color: "white",
"font-size": "12px",
"border-end-end-radius": "7.4px",
"border-end-start-radius": "7.4px",
}}
class={cx(
- "absolute bottom-0 left-0 right-0 font-medium bg-[--gray-50] dark:bg-gray-50/60 backdrop-blur-md p-2.5 flex justify-between items-center pointer-events-none transition-all max-w-full overflow-hidden",
+ "absolute bottom-0 left-0 right-0 font-medium text-gray-200 backdrop-blur-lg px-3 py-2 flex justify-between items-center pointer-events-none transition-all max-w-full overflow-hidden",
isLoading() || showUpgradeTooltip()
? "opacity-0"
: "group-hover:opacity-0"
)}
>
- <p class="flex items-center gap-4 text-[--gray-500]">
- <span class="flex items-center">
- <IconCapCamera class="w-[16px] h-[16px] mr-1.5" />
- {Math.floor(metadata().duration / 60)}:
- {Math.floor(metadata().duration % 60)
- .toString()
- .padStart(2, "0")}
- </span>
- <span class="flex items-center">
- <IconLucideHardDrive class="w-[16px] h-[16px] mr-1.5" />
- {metadata().size.toFixed(2)} MB
- </span>
- <span class="flex items-center">
- <IconLucideClock class="w-[16px] h-[16px] mr-1.5" />
- ~
- {Math.floor(
- metadata().estimatedExportTime / 60
- )}
- :
- {Math.floor(
- metadata().estimatedExportTime % 60
- )
- .toString()
- .padStart(2, "0")}
- </span>
- </p>
+ <span class="flex items-center">
+ <IconCapCamera class="w-[16px] h-[16px] mr-1.5" />
+ {Math.floor(metadata().duration / 60)}:
+ {Math.floor(metadata().duration % 60)
+ .toString()
+ .padStart(2, "0")}
+ </span>
+ <span class="flex items-center">
+ <IconLucideHardDrive class="w-[16px] h-[16px] mr-1.5" />
+ {metadata().size.toFixed(2)} MB
+ </span>
+ <span class="flex items-center">
+ <IconLucideClock class="w-[16px] h-[16px] mr-1.5" />
+ ~
+ {Math.floor(
+ metadata().estimatedExportTime / 60
+ )}
+ :
+ {Math.floor(metadata().estimatedExportTime % 60)
+ .toString()
+ .padStart(2, "0")}
+ </span>
</div>
)}
</Show>
diff --git a/crates/flags/src/lib.rs b/crates/flags/src/lib.rs
index 822e822bc..f7162bb01 100644
--- a/crates/flags/src/lib.rs
+++ b/crates/flags/src/lib.rs
@@ -9,7 +9,7 @@ pub struct Flags {
pub const FLAGS: Flags = Flags {
record_mouse: true,
- split: false, // cfg!(debug_assertions),
- pause_resume: false, // cfg!(debug_assertions),
+ split: false, // cfg!(debug_assertions),
+ pause_resume: cfg!(debug_assertions),
zoom: true,
};