Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Add SharedWallClockPause for wall clock pause tracking

Richie McIlroy97d6e464f9c2
diff --git a/crates/project/src/configuration.rs b/crates/project/src/configuration.rs
index 8a1928b9c..f3883914e 100644
--- a/crates/project/src/configuration.rs
+++ b/crates/project/src/configuration.rs
@@ -460,7 +460,7 @@ impl Default for CursorConfiguration {
tension: 65.0,
mass: 1.8,
friction: 16.0,
- raw: false,
+ raw: true,
motion_blur: 0.5,
use_svg: true,
};
diff --git a/crates/recording/src/output_pipeline/core.rs b/crates/recording/src/output_pipeline/core.rs
index 5fd5d127a..b7e293dae 100644
--- a/crates/recording/src/output_pipeline/core.rs
+++ b/crates/recording/src/output_pipeline/core.rs
@@ -471,6 +471,61 @@ impl SharedPauseState {
}
}
+struct SharedWallClockPauseInner {
+ pause_started_at: Option<std::time::Instant>,
+ total_pause_duration: Duration,
+}
+
+#[derive(Clone)]
+pub struct SharedWallClockPause {
+ flag: Arc<AtomicBool>,
+ inner: Arc<std::sync::Mutex<SharedWallClockPauseInner>>,
+}
+
+impl SharedWallClockPause {
+ pub fn new(flag: Arc<AtomicBool>) -> Self {
+ Self {
+ flag,
+ inner: Arc::new(std::sync::Mutex::new(SharedWallClockPauseInner {
+ pause_started_at: None,
+ total_pause_duration: Duration::ZERO,
+ })),
+ }
+ }
+
+ pub fn check(&self) -> (bool, Duration) {
+ let mut inner = match self.inner.lock() {
+ Ok(guard) => guard,
+ Err(poisoned) => poisoned.into_inner(),
+ };
+
+ let is_paused = self.flag.load(Ordering::Acquire);
+
+ if is_paused {
+ if inner.pause_started_at.is_none() {
+ inner.pause_started_at = Some(std::time::Instant::now());
+ }
+ } else if let Some(started) = inner.pause_started_at.take() {
+ let delta = started.elapsed();
+ inner.total_pause_duration = inner.total_pause_duration.saturating_add(delta);
+ debug!(
+ pause_delta_ms = delta.as_millis(),
+ total_pause_ms = inner.total_pause_duration.as_millis(),
+ "Shared pause state: resumed"
+ );
+ }
+
+ (is_paused, inner.total_pause_duration)
+ }
+
+ pub fn total_pause_duration(&self) -> Duration {
+ match self.inner.lock() {
+ Ok(guard) => guard.total_pause_duration,
+ Err(poisoned) => poisoned.into_inner().total_pause_duration,
+ }
+ }
+}
+
pub struct OnceSender<T>(Option<oneshot::Sender<T>>);
impl<T> OnceSender<T> {