Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

clippy

Richie McIlroycfd360ecdb0e
diff --git a/apps/desktop/src-tauri/src/captions.rs b/apps/desktop/src-tauri/src/captions.rs
index a0224c4ea..80a135e5b 100644
--- a/apps/desktop/src-tauri/src/captions.rs
+++ b/apps/desktop/src-tauri/src/captions.rs
@@ -115,30 +115,28 @@ async fn extract_audio_from_video(video_path: &str, output_path: &PathBuf) -> Re
if mixed_samples.is_empty() {
mixed_samples = audio.samples().to_vec();
channel_count = audio.channels() as usize;
- } else {
- if audio.channels() as usize != channel_count {
- log::info!(
- "Channel count mismatch: {} vs {}, mixing to mono",
- channel_count,
- audio.channels()
- );
-
- if channel_count > 1 {
- let mono_samples = convert_to_mono(&mixed_samples, channel_count);
- mixed_samples = mono_samples;
- channel_count = 1;
- }
+ } else if audio.channels() as usize != channel_count {
+ log::info!(
+ "Channel count mismatch: {} vs {}, mixing to mono",
+ channel_count,
+ audio.channels()
+ );
- let samples = if audio.channels() > 1 {
- convert_to_mono(audio.samples(), audio.channels() as usize)
- } else {
- audio.samples().to_vec()
- };
+ if channel_count > 1 {
+ let mono_samples = convert_to_mono(&mixed_samples, channel_count);
+ mixed_samples = mono_samples;
+ channel_count = 1;
+ }
- mix_samples(&mut mixed_samples, &samples);
+ let samples = if audio.channels() > 1 {
+ convert_to_mono(audio.samples(), audio.channels() as usize)
} else {
- mix_samples(&mut mixed_samples, audio.samples());
- }
+ audio.samples().to_vec()
+ };
+
+ mix_samples(&mut mixed_samples, &samples);
+ } else {
+ mix_samples(&mut mixed_samples, audio.samples());
}
}
Err(e) => {
@@ -1012,13 +1010,11 @@ fn start_whisperx_server(
std::thread::spawn(move || {
use std::io::BufRead;
let reader = std::io::BufReader::new(stderr);
- for line in reader.lines() {
- if let Ok(line) = line {
- if line.starts_with("STDERR:") {
- log::info!("[WhisperX] {}", &line[7..]);
- } else {
- log::info!("[WhisperX stderr] {}", line);
- }
+ for line in reader.lines().flatten() {
+ if let Some(stripped) = line.strip_prefix("STDERR:") {
+ log::info!("[WhisperX] {}", stripped);
+ } else {
+ log::info!("[WhisperX stderr] {}", line);
}
}
});
diff --git a/apps/desktop/src-tauri/src/export.rs b/apps/desktop/src-tauri/src/export.rs
index a342d1776..b9226028c 100644
--- a/apps/desktop/src-tauri/src/export.rs
+++ b/apps/desktop/src-tauri/src/export.rs
@@ -1,6 +1,6 @@
use crate::{FramesRendered, get_video_metadata};
use cap_export::ExporterBase;
-use cap_project::{RecordingMeta, XY};
+use cap_project::RecordingMeta;
use serde::Deserialize;
use specta::Type;
use std::path::PathBuf;
diff --git a/apps/desktop/src-tauri/src/tray.rs b/apps/desktop/src-tauri/src/tray.rs
index a9347fb3d..4e491250e 100644
--- a/apps/desktop/src-tauri/src/tray.rs
+++ b/apps/desktop/src-tauri/src/tray.rs
@@ -89,7 +89,10 @@ impl TryFrom<MenuId> for TrayItem {
#[derive(Debug, Clone)]
enum PreviousItemType {
StudioRecording,
- InstantRecording { link: Option<String> },
+ InstantRecording {
+ #[allow(dead_code)]
+ link: Option<String>,
+ },
Screenshot,
}
@@ -104,16 +107,11 @@ struct CachedPreviousItem {
created_at: std::time::SystemTime,
}
+#[derive(Default)]
struct PreviousItemsCache {
items: Vec<CachedPreviousItem>,
}
-impl Default for PreviousItemsCache {
- fn default() -> Self {
- Self { items: Vec::new() }
- }
-}
-
fn recordings_path(app: &AppHandle) -> PathBuf {
let path = app.path().app_data_dir().unwrap().join("recordings");
std::fs::create_dir_all(&path).unwrap_or_default();
@@ -230,27 +228,25 @@ fn load_all_previous_items(app: &AppHandle, load_thumbnails: bool) -> Vec<Cached
let screenshots_dir = screenshots_path(app);
let recordings_dir = recordings_path(app);
- if recordings_dir.exists() {
- if let Ok(entries) = std::fs::read_dir(&recordings_dir) {
- for entry in entries.flatten() {
- if let Some(item) =
- load_single_item(&entry.path(), &screenshots_dir, load_thumbnails)
- {
- items.push(item);
- }
+ if recordings_dir.exists()
+ && let Ok(entries) = std::fs::read_dir(&recordings_dir)
+ {
+ for entry in entries.flatten() {
+ if let Some(item) = load_single_item(&entry.path(), &screenshots_dir, load_thumbnails) {
+ items.push(item);
}
}
}
- if screenshots_dir.exists() {
- if let Ok(entries) = std::fs::read_dir(&screenshots_dir) {
- for entry in entries.flatten() {
- let path = entry.path();
- if path.extension().and_then(|s| s.to_str()) == Some("cap") {
- if let Some(item) = load_single_item(&path, &screenshots_dir, load_thumbnails) {
- items.push(item);
- }
- }
+ if screenshots_dir.exists()
+ && let Ok(entries) = std::fs::read_dir(&screenshots_dir)
+ {
+ for entry in entries.flatten() {
+ let path = entry.path();
+ if path.extension().and_then(|s| s.to_str()) == Some("cap")
+ && let Some(item) = load_single_item(&path, &screenshots_dir, load_thumbnails)
+ {
+ items.push(item);
}
}
}
diff --git a/crates/frame-converter/src/pool.rs b/crates/frame-converter/src/pool.rs
index e90defc68..c0a93f146 100644
--- a/crates/frame-converter/src/pool.rs
+++ b/crates/frame-converter/src/pool.rs
@@ -185,7 +185,7 @@ impl AsyncConverterPool {
Err(flume::TrySendError::Full(_)) => {
self.stats.frames_dropped.fetch_add(1, Ordering::Relaxed);
let dropped = self.stats.frames_dropped.load(Ordering::Relaxed);
- if dropped % 30 == 0 {
+ if dropped.is_multiple_of(30) {
warn!(
"Converter pool input full, dropped {} frames so far",
dropped
diff --git a/crates/recording/src/feeds/camera.rs b/crates/recording/src/feeds/camera.rs
index 62d404443..44cdaa5dc 100644
--- a/crates/recording/src/feeds/camera.rs
+++ b/crates/recording/src/feeds/camera.rs
@@ -506,7 +506,7 @@ async fn setup_camera(
}))
.try_send();
- if callback_num % 30 == 0 {
+ if callback_num.is_multiple_of(30) {
tracing::debug!(
"Camera callback: sent frame {} to actor, result={:?}",
callback_num,
@@ -514,7 +514,7 @@ async fn setup_camera(
);
}
- if send_result.is_err() && callback_num % 30 == 0 {
+ if send_result.is_err() && callback_num.is_multiple_of(30) {
tracing::warn!(
"Camera callback: failed to send frame {} to actor (mailbox full?)",
callback_num
@@ -612,7 +612,7 @@ async fn setup_camera(
}))
.try_send();
- if callback_num % 30 == 0 {
+ if callback_num.is_multiple_of(30) {
tracing::debug!(
"Camera callback: sent frame {} to actor, result={:?}",
callback_num,
@@ -620,7 +620,7 @@ async fn setup_camera(
);
}
- if send_result.is_err() && callback_num % 30 == 0 {
+ if send_result.is_err() && callback_num.is_multiple_of(30) {
tracing::warn!(
"Camera callback: failed to send frame {} to actor (mailbox full?)",
callback_num
@@ -789,7 +789,7 @@ impl Message<NewFrame> for CameraFeed {
async fn handle(&mut self, msg: NewFrame, _: &mut Context<Self, Self::Reply>) -> Self::Reply {
let frame_num = CAMERA_FRAME_COUNTER.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
- if frame_num % 30 == 0 {
+ if frame_num.is_multiple_of(30) {
debug!(
"CameraFeed: received frame {}, broadcasting to {} senders",
frame_num,
@@ -803,7 +803,7 @@ impl Message<NewFrame> for CameraFeed {
match sender.try_send(msg.0.clone()) {
Ok(()) => {}
Err(flume::TrySendError::Full(_)) => {
- if frame_num % 30 == 0 {
+ if frame_num.is_multiple_of(30) {
warn!(
"Camera sender {} channel full at frame {}, dropping frame",
i, frame_num
@@ -843,7 +843,7 @@ impl Message<NewNativeFrame> for CameraFeed {
let frame_num =
NATIVE_CAMERA_FRAME_COUNTER.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
- if frame_num % 30 == 0 {
+ if frame_num.is_multiple_of(30) {
debug!(
"CameraFeed: received native frame {}, broadcasting to {} native senders",
frame_num,
@@ -857,7 +857,7 @@ impl Message<NewNativeFrame> for CameraFeed {
match sender.try_send(msg.0.clone()) {
Ok(()) => {}
Err(flume::TrySendError::Full(_)) => {
- if frame_num % 30 == 0 {
+ if frame_num.is_multiple_of(30) {
warn!(
"Native camera sender {} channel full at frame {}, dropping frame",
i, frame_num
diff --git a/crates/recording/src/output_pipeline/async_camera.rs b/crates/recording/src/output_pipeline/async_camera.rs
index fd458eeec..e9ae05242 100644
--- a/crates/recording/src/output_pipeline/async_camera.rs
+++ b/crates/recording/src/output_pipeline/async_camera.rs
@@ -267,7 +267,7 @@ impl VideoMuxer for AsyncCameraMp4Muxer {
}
}
- if self.frames_submitted % 60 == 0 {
+ if self.frames_submitted.is_multiple_of(60) {
trace!(
"Camera encoder progress: submitted={}, encoded={}, backlog={}",
self.frames_submitted, self.frames_encoded, backlog
diff --git a/crates/recording/src/sources/camera.rs b/crates/recording/src/sources/camera.rs
index be2de19f2..8d9de98b8 100644
--- a/crates/recording/src/sources/camera.rs
+++ b/crates/recording/src/sources/camera.rs
@@ -69,7 +69,7 @@ impl VideoSource for Camera {
match video_tx.try_send(frame) {
Ok(()) => {
sent_count += 1;
- if sent_count % 30 == 0 {
+ if sent_count.is_multiple_of(30) {
tracing::debug!(
"Camera source: sent {} frames, dropped {} in {:?}",
sent_count,
@@ -81,7 +81,7 @@ impl VideoSource for Camera {
Err(e) => {
if e.is_full() {
dropped_count += 1;
- if dropped_count % 30 == 0 {
+ if dropped_count.is_multiple_of(30) {
tracing::warn!(
"Camera source: encoder can't keep up, dropped {} frames so far",
dropped_count
diff --git a/crates/recording/src/sources/native_camera.rs b/crates/recording/src/sources/native_camera.rs
index e2e95ab27..128b015bf 100644
--- a/crates/recording/src/sources/native_camera.rs
+++ b/crates/recording/src/sources/native_camera.rs
@@ -68,7 +68,7 @@ impl VideoSource for NativeCamera {
match video_tx.try_send(frame) {
Ok(()) => {
sent_count += 1;
- if sent_count % 30 == 0 {
+ if sent_count.is_multiple_of(30) {
tracing::debug!(
"Native camera source: sent {} frames, dropped {} in {:?}",
sent_count,
@@ -80,7 +80,7 @@ impl VideoSource for NativeCamera {
Err(e) => {
if e.is_full() {
dropped_count += 1;
- if dropped_count % 30 == 0 {
+ if dropped_count.is_multiple_of(30) {
tracing::warn!(
"Native camera source: encoder can't keep up, dropped {} frames so far",
dropped_count