Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

clippy

Richie McIlroy4534dd88a8d9
diff --git a/.claude/settings.local.json b/.claude/settings.local.json
index 6de7d1cc4..4eb7da12a 100644
--- a/.claude/settings.local.json
+++ b/.claude/settings.local.json
@@ -38,7 +38,8 @@
"Bash(pnpm --dir apps/desktop exec biome format:*)",
"Bash(echo:*)",
"Bash(pnpm exec biome:*)",
- "Bash(rustfmt:*)"
+ "Bash(rustfmt:*)",
+ "Bash(cargo tree:*)"
],
"deny": [],
"ask": []
diff --git a/apps/desktop/src-tauri/src/frame_ws.rs b/apps/desktop/src-tauri/src/frame_ws.rs
index f51e7ce92..93146003f 100644
--- a/apps/desktop/src-tauri/src/frame_ws.rs
+++ b/apps/desktop/src-tauri/src/frame_ws.rs
@@ -15,6 +15,7 @@ pub struct WSFrame {
pub width: u32,
pub height: u32,
pub stride: u32,
+ #[allow(dead_code)]
pub created_at: Instant,
}
diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs
index 1588ee4a9..98eccdfef 100644
--- a/apps/desktop/src-tauri/src/lib.rs
+++ b/apps/desktop/src-tauri/src/lib.rs
@@ -2313,6 +2313,7 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {
.commands(tauri_specta::collect_commands![
set_mic_input,
set_camera_input,
+ recording_settings::set_recording_mode,
upload_logs,
recording::start_recording,
recording::stop_recording,
diff --git a/apps/desktop/src-tauri/src/recording_settings.rs b/apps/desktop/src-tauri/src/recording_settings.rs
index 9b62c4f57..aaaff1178 100644
--- a/apps/desktop/src-tauri/src/recording_settings.rs
+++ b/apps/desktop/src-tauri/src/recording_settings.rs
@@ -4,6 +4,8 @@ use cap_recording::{
use tauri::{AppHandle, Wry};
use tauri_plugin_store::StoreExt;
+use crate::tray;
+
#[derive(serde::Serialize, serde::Deserialize, specta::Type, Debug, Clone, Copy)]
#[serde(rename_all = "camelCase")]
pub enum RecordingTargetMode {
@@ -28,35 +30,29 @@ impl RecordingSettingsStore {
pub fn get(app: &AppHandle<Wry>) -> Result<Option<Self>, String> {
match app.store("store").map(|s| s.get(Self::KEY)) {
- Ok(Some(store)) => {
- // Handle potential deserialization errors gracefully
- match serde_json::from_value(store) {
- Ok(settings) => Ok(Some(settings)),
- Err(e) => Err(format!("Failed to deserialize general settings store: {e}")),
- }
- }
+ Ok(Some(store)) => match serde_json::from_value(store) {
+ Ok(settings) => Ok(Some(settings)),
+ Err(e) => Err(format!("Failed to deserialize general settings store: {e}")),
+ },
_ => Ok(None),
}
}
- // i don't trust anyone to not overwrite the whole store lols
- // pub fn update(app: &AppHandle, update: impl FnOnce(&mut Self)) -> Result<(), String> {
- // let Ok(store) = app.store("store") else {
- // return Err("Store not found".to_string());
- // };
-
- // let mut settings = Self::get(app)?.unwrap_or_default();
- // update(&mut settings);
- // store.set(Self::KEY, json!(settings));
- // store.save().map_err(|e| e.to_string())
- // }
-
- // fn save(&self, app: &AppHandle) -> Result<(), String> {
- // let Ok(store) = app.store("store") else {
- // return Err("Store not found".to_string());
- // };
-
- // store.set(Self::KEY, json!(self));
- // store.save().map_err(|e| e.to_string())
- // }
+ pub fn set_mode(app: &AppHandle<Wry>, mode: RecordingMode) -> Result<(), String> {
+ let store = app.store("store").map_err(|e| e.to_string())?;
+
+ let mut settings = Self::get(app)?.unwrap_or_default();
+ settings.mode = Some(mode);
+
+ store.set(Self::KEY, serde_json::json!(settings));
+ store.save().map_err(|e| e.to_string())
+ }
+}
+
+#[tauri::command]
+#[specta::specta]
+pub fn set_recording_mode(app: AppHandle, mode: RecordingMode) -> Result<(), String> {
+ RecordingSettingsStore::set_mode(&app, mode)?;
+ tray::update_tray_icon_for_mode(&app, mode);
+ Ok(())
}
diff --git a/apps/desktop/src-tauri/src/windows.rs b/apps/desktop/src-tauri/src/windows.rs
index 485bc5428..b92284305 100644
--- a/apps/desktop/src-tauri/src/windows.rs
+++ b/apps/desktop/src-tauri/src/windows.rs
@@ -188,7 +188,7 @@ impl CapWindowId {
Self::Settings => (600.0, 450.0),
Self::Camera => (200.0, 200.0),
Self::Upgrade => (950.0, 850.0),
- Self::ModeSelect => (900.0, 500.0),
+ Self::ModeSelect => (580.0, 340.0),
_ => return None,
})
}
@@ -486,16 +486,15 @@ impl ShowCapWindow {
builder.build()?
}
Self::ModeSelect => {
- // Hide main window when mode select window opens
if let Some(main) = CapWindowId::Main.get(app) {
let _ = main.hide();
}
let mut builder = self
.window_builder(app, "/mode-select")
- .inner_size(900.0, 500.0)
- .min_inner_size(900.0, 500.0)
- .resizable(true)
+ .inner_size(580.0, 340.0)
+ .min_inner_size(580.0, 340.0)
+ .resizable(false)
.maximized(false)
.maximizable(false)
.center()
diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.ts
index d3f34c9c9..9ad74ec1c 100644
--- a/apps/desktop/src/utils/tauri.ts
+++ b/apps/desktop/src/utils/tauri.ts
@@ -420,7 +420,7 @@ fast: boolean | null }
export type HapticPattern = "alignment" | "levelChange" | "generic"
export type HapticPerformanceTime = "default" | "now" | "drawCompleted"
export type Hotkey = { code: string; meta: boolean; ctrl: boolean; alt: boolean; shift: boolean }
-export type HotkeyAction = "startStudioRecording" | "startInstantRecording" | "stopRecording" | "restartRecording" | "openRecordingPicker" | "openRecordingPickerDisplay" | "openRecordingPickerWindow" | "openRecordingPickerArea" | "other"
+export type HotkeyAction = "startStudioRecording" | "startInstantRecording" | "stopRecording" | "restartRecording" | "cycleRecordingMode" | "openRecordingPicker" | "openRecordingPickerDisplay" | "openRecordingPickerWindow" | "openRecordingPickerArea" | "other"
export type HotkeysConfiguration = { show: boolean }
export type HotkeysStore = { hotkeys: { [key in HotkeyAction]: Hotkey } }
export type IncompleteRecordingInfo = { projectPath: string; prettyName: string; segmentCount: number; estimatedDurationSecs: number }
diff --git a/crates/editor/src/editor_instance.rs b/crates/editor/src/editor_instance.rs
index 3fd9d4c8b..7ccaae9e0 100644
--- a/crates/editor/src/editor_instance.rs
+++ b/crates/editor/src/editor_instance.rs
@@ -193,9 +193,7 @@ impl EditorInstance {
if let Some(task) = state.preview_task.take() {
task.abort();
- if let Err(e) = task.await {
- tracing::error!(%e, "preview task join error or cancelled");
- }
+ let _ = task.await;
}
self.renderer.stop().await;
@@ -210,8 +208,6 @@ impl EditorInstance {
tokio::task::yield_now().await;
drop(state);
-
- println!("EditorInstance disposed");
}
pub async fn modify_and_emit_state(&self, modify: impl Fn(&mut EditorState)) {
@@ -437,14 +433,7 @@ impl EditorInstance {
}
impl Drop for EditorInstance {
- fn drop(&mut self) {
- // TODO: Ensure that *all* resources have been released by this point?
- // For now the `dispose` method is adequate.
- println!(
- "*** Editor instance has been released: {:?} ***",
- self.project_path
- );
- }
+ fn drop(&mut self) {}
}
type PreviewFrameInstruction = (u32, u32, XY<u32>);
diff --git a/crates/enc-mediafoundation/src/video/h264.rs b/crates/enc-mediafoundation/src/video/h264.rs
index 08c52fb4e..4fae2c189 100644
--- a/crates/enc-mediafoundation/src/video/h264.rs
+++ b/crates/enc-mediafoundation/src/video/h264.rs
@@ -213,7 +213,7 @@ impl H264Encoder {
transform
.ProcessMessage(
MFT_MESSAGE_SET_D3D_MANAGER,
- std::mem::transmute::<_, usize>(temp),
+ std::mem::transmute::<IMFDXGIDeviceManager, usize>(temp),
)
.map_err(NewVideoEncoderError::EncoderTransform)?;
};
diff --git a/crates/export/src/lib.rs b/crates/export/src/lib.rs
index 2e80be962..4b187f7c9 100644
--- a/crates/export/src/lib.rs
+++ b/crates/export/src/lib.rs
@@ -5,7 +5,6 @@ use cap_editor::SegmentMedia;
use cap_project::{ProjectConfiguration, RecordingMeta, StudioRecordingMeta};
use cap_rendering::{ProjectRecordingsMeta, RenderVideoConstants};
use std::{path::PathBuf, sync::Arc};
-use tracing::error;
#[derive(thiserror::Error, Debug)]
pub enum ExportError {
diff --git a/crates/recording/src/recovery.rs b/crates/recording/src/recovery.rs
index 79f766980..da5560e4c 100644
--- a/crates/recording/src/recovery.rs
+++ b/crates/recording/src/recovery.rs
@@ -82,21 +82,30 @@ impl RecoveryManager {
};
if let Some(studio_meta) = meta.studio_meta()
- && matches!(
- studio_meta.status(),
- StudioRecordingStatus::InProgress
- | StudioRecordingStatus::NeedsRemux
- | StudioRecordingStatus::Failed { .. }
- )
- && let Some(incomplete_recording) = Self::analyze_incomplete(&path, &meta)
+ && Self::should_check_for_recovery(&studio_meta.status())
{
- incomplete.push(incomplete_recording);
+ match Self::analyze_incomplete(&path, &meta) {
+ Some(incomplete_recording) => {
+ incomplete.push(incomplete_recording);
+ }
+ None => {
+ Self::mark_unrecoverable(&path, &meta);
+ }
+ }
}
}
incomplete
}
+ fn should_check_for_recovery(status: &StudioRecordingStatus) -> bool {
+ match status {
+ StudioRecordingStatus::InProgress | StudioRecordingStatus::NeedsRemux => true,
+ StudioRecordingStatus::Failed { error } => error != "No recoverable segments found",
+ StudioRecordingStatus::Complete => false,
+ }
+ }
+
fn analyze_incomplete(
project_path: &Path,
meta: &RecordingMeta,
@@ -728,4 +737,32 @@ impl RecoveryManager {
Ok(())
}
+
+ fn mark_unrecoverable(project_path: &Path, meta: &RecordingMeta) {
+ let mut updated_meta = meta.clone();
+
+ let status_updated = match &mut updated_meta.inner {
+ RecordingMetaInner::Studio(StudioRecordingMeta::MultipleSegments { inner, .. }) => {
+ inner.status = Some(StudioRecordingStatus::Failed {
+ error: "No recoverable segments found".to_string(),
+ });
+ true
+ }
+ _ => false,
+ };
+
+ if status_updated {
+ if let Err(e) = updated_meta.save_for_project() {
+ warn!(
+ "Failed to mark recording as unrecoverable at {:?}: {}",
+ project_path, e
+ );
+ } else {
+ info!(
+ "Marked recording as unrecoverable (no recoverable segments): {:?}",
+ project_path
+ );
+ }
+ }
+ }
}
diff --git a/crates/recording/src/sources/audio_mixer.rs b/crates/recording/src/sources/audio_mixer.rs
index ee312c971..5157aa137 100644
--- a/crates/recording/src/sources/audio_mixer.rs
+++ b/crates/recording/src/sources/audio_mixer.rs
@@ -251,7 +251,8 @@ impl AudioMixer {
let buffer_last_elapsed = buffer_last_timestamp.duration_since(self.timestamps);
if timestamp_elapsed > buffer_last_elapsed {
- let elapsed_since_last_frame = timestamp_elapsed - buffer_last_elapsed;
+ let elapsed_since_last_frame =
+ timestamp_elapsed.saturating_sub(buffer_last_elapsed);
if let Some(diff) =
elapsed_since_last_frame.checked_sub(buffer_last_duration)
@@ -342,7 +343,8 @@ impl AudioMixer {
frame.set_rate(source.info.rate() as u32);
- let timestamp = start_timestamp + (elapsed_since_start - remaining);
+ let timestamp =
+ start_timestamp + elapsed_since_start.saturating_sub(remaining);
source.buffer_last = Some((timestamp, frame_duration));
source.buffer.push_front(AudioFrame::new(frame, timestamp));
diff --git a/crates/rendering/src/decoder/mod.rs b/crates/rendering/src/decoder/mod.rs
index 8d587d19c..c3d6d021c 100644
--- a/crates/rendering/src/decoder/mod.rs
+++ b/crates/rendering/src/decoder/mod.rs
@@ -200,30 +200,7 @@ impl AsyncVideoDecoderHandle {
return None;
}
- let start = std::time::Instant::now();
- let result = rx.await;
- let wait_ms = start.elapsed().as_millis() as u64;
-
- let success = result.is_ok();
- let cancelled = result.is_err();
- if cancelled || wait_ms > 50 {
- let timestamp = std::time::SystemTime::now()
- .duration_since(std::time::UNIX_EPOCH)
- .map(|d| d.as_millis() as u64)
- .unwrap_or(0);
- debug!(
- time = time,
- wait_ms = wait_ms,
- success = success,
- cancelled = cancelled,
- timestamp = timestamp,
- session_id = "debug-session",
- hypothesis_id = "A",
- "get_frame completed"
- );
- }
-
- result.ok()
+ rx.await.ok()
}
pub fn get_time(&self, time: f32) -> f32 {