Skip to content

Commit efa6a3a

Browse files
committed
restrict clippy a lot more
1 parent 8399fa5 commit efa6a3a

File tree

24 files changed

+202
-398
lines changed

24 files changed

+202
-398
lines changed

Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ unexpected_cfgs = "allow"
6969
dbg_macro = "deny"
7070
let_underscore_future = "deny"
7171
unchecked_duration_subtraction = "deny"
72+
collapsible_if = "deny"
73+
manual_is_multiple_of = "deny"
74+
clone_on_copy = "deny"
75+
redundant_closure = "deny"
76+
ptr_arg = "deny"
77+
len_zero = "deny"
78+
let_unit_value = "deny"
79+
unnecessary_lazy_evaluations = "deny"
80+
needless_range_loop = "deny"
81+
manual_clamp = "deny"
7282

7383
# Optimize for smaller binary size
7484
[profile.release]

apps/desktop/src-tauri/src/platform/macos/sc_shareable_content.rs

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
use cidre::{arc, ns, sc};
2-
use core_graphics::{display::CGDirectDisplayID, window::CGWindowID};
3-
use std::sync::Arc;
4-
use std::{
5-
collections::HashMap,
6-
sync::{OnceLock, RwLock},
7-
time::Instant,
8-
};
2+
use std::sync::{Arc, OnceLock, RwLock};
93
use tokio::sync::{Mutex, Notify};
104
use tracing::trace;
115

@@ -62,8 +56,6 @@ pub async fn prewarm_shareable_content() -> Result<(), arc::R<ns::Error>> {
6256

6357
pub async fn get_shareable_content()
6458
-> Result<Option<arc::R<sc::ShareableContent>>, arc::R<ns::Error>> {
65-
let lookup_start = Instant::now();
66-
6759
if let Some(content) = state()
6860
.cache
6961
.read()
@@ -82,14 +74,10 @@ pub async fn get_shareable_content()
8274

8375
async fn run_warmup(task: WarmupTask) {
8476
let result = async {
85-
let warm_start = Instant::now();
86-
8777
let content = sc::ShareableContent::current().await?;
8878
let cache = ShareableContentCache::new(content);
89-
let elapsed_ms = warm_start.elapsed().as_micros() as f64 / 1000.0;
9079

9180
let mut guard = state().cache.write().unwrap();
92-
let replaced = guard.is_some();
9381
*guard = Some(cache);
9482

9583
Ok::<(), arc::R<ns::Error>>(())
@@ -115,40 +103,14 @@ async fn run_warmup(task: WarmupTask) {
115103
struct ShareableContentCache {
116104
#[allow(dead_code)]
117105
content: arc::R<sc::ShareableContent>,
118-
displays: HashMap<CGDirectDisplayID, arc::R<sc::Display>>,
119-
windows: HashMap<CGWindowID, arc::R<sc::Window>>,
120106
}
121107

122108
unsafe impl Send for ShareableContentCache {}
123109
unsafe impl Sync for ShareableContentCache {}
124110

125111
impl ShareableContentCache {
126112
fn new(content: arc::R<sc::ShareableContent>) -> Self {
127-
let displays = content
128-
.displays()
129-
.iter()
130-
.map(|display| (display.display_id().0, display.retained()))
131-
.collect();
132-
133-
let windows = content
134-
.windows()
135-
.iter()
136-
.map(|window| (window.id(), window.retained()))
137-
.collect();
138-
139-
Self {
140-
content,
141-
displays,
142-
windows,
143-
}
144-
}
145-
146-
fn display(&self, id: CGDirectDisplayID) -> Option<arc::R<sc::Display>> {
147-
self.displays.get(&id).cloned()
148-
}
149-
150-
fn window(&self, id: CGWindowID) -> Option<arc::R<sc::Window>> {
151-
self.windows.get(&id).cloned()
113+
Self { content }
152114
}
153115
}
154116

apps/desktop/src-tauri/src/recording.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -978,11 +978,10 @@ async fn handle_recording_finish(
978978
return;
979979
}
980980

981-
if GeneralSettingsStore::get(&app).ok().flatten().unwrap_or_default().delete_instant_recordings_after_upload {
982-
if let Err(err) = tokio::fs::remove_dir_all(&recording_dir).await {
981+
if GeneralSettingsStore::get(&app).ok().flatten().unwrap_or_default().delete_instant_recordings_after_upload && let Err(err) = tokio::fs::remove_dir_all(&recording_dir).await {
983982
error!("Failed to remove recording files after upload: {err:?}");
984983
}
985-
}
984+
986985
}
987986
} else if let Ok(meta) = build_video_meta(&output_path)
988987
.map_err(|err| error!("Error getting video metadata: {}", err))

apps/desktop/src-tauri/src/recording_settings.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use cap_recording::{
22
RecordingMode, feeds::camera::DeviceOrModelID, sources::screen_capture::ScreenCaptureTarget,
33
};
4-
use serde_json::json;
54
use tauri::{AppHandle, Wry};
65
use tauri_plugin_store::StoreExt;
76

@@ -40,23 +39,23 @@ impl RecordingSettingsStore {
4039
}
4140

4241
// i don't trust anyone to not overwrite the whole store lols
43-
pub fn update(app: &AppHandle, update: impl FnOnce(&mut Self)) -> Result<(), String> {
44-
let Ok(store) = app.store("store") else {
45-
return Err("Store not found".to_string());
46-
};
47-
48-
let mut settings = Self::get(app)?.unwrap_or_default();
49-
update(&mut settings);
50-
store.set(Self::KEY, json!(settings));
51-
store.save().map_err(|e| e.to_string())
52-
}
53-
54-
fn save(&self, app: &AppHandle) -> Result<(), String> {
55-
let Ok(store) = app.store("store") else {
56-
return Err("Store not found".to_string());
57-
};
58-
59-
store.set(Self::KEY, json!(self));
60-
store.save().map_err(|e| e.to_string())
61-
}
42+
// pub fn update(app: &AppHandle, update: impl FnOnce(&mut Self)) -> Result<(), String> {
43+
// let Ok(store) = app.store("store") else {
44+
// return Err("Store not found".to_string());
45+
// };
46+
47+
// let mut settings = Self::get(app)?.unwrap_or_default();
48+
// update(&mut settings);
49+
// store.set(Self::KEY, json!(settings));
50+
// store.save().map_err(|e| e.to_string())
51+
// }
52+
53+
// fn save(&self, app: &AppHandle) -> Result<(), String> {
54+
// let Ok(store) = app.store("store") else {
55+
// return Err("Store not found".to_string());
56+
// };
57+
58+
// store.set(Self::KEY, json!(self));
59+
// store.save().map_err(|e| e.to_string())
60+
// }
6261
}

apps/desktop/src-tauri/src/thumbnails/mac.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ fn convert_32bit_pixel_buffer(
162162
#[derive(Copy, Clone)]
163163
enum Nv12Range {
164164
Video,
165-
Full,
165+
_Full,
166166
}
167167

168168
fn convert_nv12_pixel_buffer(
@@ -228,7 +228,7 @@ fn convert_nv12_pixel_buffer(
228228
}
229229
let uv_row = &uv_plane[uv_row_start..uv_row_start + width];
230230

231-
for x in 0..width {
231+
for (x, y_val) in y_row.iter().enumerate().take(width) {
232232
let uv_index = (x / 2) * 2;
233233
if uv_index + 1 >= uv_row.len() {
234234
warn!(
@@ -239,10 +239,9 @@ fn convert_nv12_pixel_buffer(
239239
return None;
240240
}
241241

242-
let y_val = y_row[x];
243242
let cb = uv_row[uv_index];
244243
let cr = uv_row[uv_index + 1];
245-
let (r, g, b) = ycbcr_to_rgb(y_val, cb, cr, range);
244+
let (r, g, b) = ycbcr_to_rgb(*y_val, cb, cr, range);
246245
let out = (y_idx * width + x) * 4;
247246
rgba_data[out] = r;
248247
rgba_data[out + 1] = g;
@@ -261,7 +260,7 @@ fn ycbcr_to_rgb(y: u8, cb: u8, cr: u8, range: Nv12Range) -> (u8, u8, u8) {
261260

262261
let (y_value, scale) = match range {
263262
Nv12Range::Video => ((y - 16.0).max(0.0), 1.164383_f32),
264-
Nv12Range::Full => (y, 1.0_f32),
263+
Nv12Range::_Full => (y, 1.0_f32),
265264
};
266265

267266
let r = scale * y_value + 1.596027_f32 * cr;
@@ -272,7 +271,7 @@ fn ycbcr_to_rgb(y: u8, cb: u8, cr: u8, range: Nv12Range) -> (u8, u8, u8) {
272271
}
273272

274273
fn clamp_channel(value: f32) -> u8 {
275-
value.max(0.0).min(255.0) as u8
274+
value.clamp(0.0, 255.0) as u8
276275
}
277276

278277
struct PixelBufferLock<'a> {

apps/desktop/src-tauri/src/upload.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ pub fn build_video_meta(path: &PathBuf) -> Result<S3VideoMeta, String> {
289289
height: video.height(),
290290
fps: video
291291
.frame_rate()
292-
.map(|v| (v.numerator() as f32 / v.denominator() as f32)),
292+
.map(|v| v.numerator() as f32 / v.denominator() as f32),
293293
})
294294
}
295295

@@ -503,8 +503,7 @@ pub fn from_pending_file_to_chunks(
503503

504504
loop {
505505
// Check if realtime recording is done
506-
if !realtime_is_done.unwrap_or(true) {
507-
if let Some(ref realtime_receiver) = realtime_upload_done {
506+
if !realtime_is_done.unwrap_or(true) && let Some(ref realtime_receiver) = realtime_upload_done {
508507
match realtime_receiver.try_recv() {
509508
Ok(_) => realtime_is_done = Some(true),
510509
Err(flume::TryRecvError::Empty) => {},
@@ -513,7 +512,7 @@ pub fn from_pending_file_to_chunks(
513512
// It possibly means something has gone wrong but that's not the uploader's problem.
514513
Err(_) => realtime_is_done = Some(true),
515514
}
516-
}
515+
517516
}
518517

519518
let file_size = match file.metadata().await {

apps/desktop/src-tauri/src/window_exclusion.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ impl WindowExclusion {
2121
owner_name: Option<&str>,
2222
window_title: Option<&str>,
2323
) -> bool {
24-
if let Some(identifier) = self.bundle_identifier.as_deref() {
25-
if bundle_identifier
24+
if let Some(identifier) = self.bundle_identifier.as_deref()
25+
&& bundle_identifier
2626
.map(|candidate| candidate == identifier)
2727
.unwrap_or(false)
28-
{
29-
return true;
30-
}
28+
{
29+
return true;
3130
}
3231

3332
if let Some(expected_owner) = self.owner_name.as_deref() {

crates/audio/src/latency.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl OutputLatencyEstimator {
258258
}
259259

260260
pub fn with_bias(bias_secs: f64) -> Self {
261-
let bias_secs = bias_secs.max(0.0).min(MAX_LATENCY_SECS);
261+
let bias_secs = bias_secs.clamp(0.0, MAX_LATENCY_SECS);
262262
Self {
263263
smoothed_latency_secs: if bias_secs > 0.0 {
264264
Some(bias_secs)
@@ -292,7 +292,7 @@ impl OutputLatencyEstimator {
292292
}
293293

294294
pub fn set_bias_secs(&mut self, bias_secs: f64) {
295-
self.bias_secs = bias_secs.max(0.0).min(MAX_LATENCY_SECS);
295+
self.bias_secs = bias_secs.clamp(0.0, MAX_LATENCY_SECS);
296296
}
297297

298298
pub fn set_floor_and_ceiling(&mut self, min_floor_secs: f64, max_ceiling_secs: f64) {
@@ -367,14 +367,13 @@ impl OutputLatencyEstimator {
367367
return;
368368
}
369369

370-
if let Some(prev_raw) = self.last_raw_latency_secs {
371-
if self.update_count < WARMUP_GUARD_SAMPLES as u64
372-
&& clamped > prev_raw * WARMUP_SPIKE_RATIO
373-
{
374-
self.last_raw_latency_secs = Some(clamped);
375-
self.update_count = self.update_count.saturating_add(1);
376-
return;
377-
}
370+
if let Some(prev_raw) = self.last_raw_latency_secs
371+
&& self.update_count < WARMUP_GUARD_SAMPLES as u64
372+
&& clamped > prev_raw * WARMUP_SPIKE_RATIO
373+
{
374+
self.last_raw_latency_secs = Some(clamped);
375+
self.update_count = self.update_count.saturating_add(1);
376+
return;
378377
}
379378

380379
let now = Instant::now();
@@ -586,10 +585,10 @@ mod macos {
586585
let mut max_latency = 0u32;
587586

588587
for stream in streams {
589-
if is_output_stream(&stream)? {
590-
if let Ok(latency) = stream.latency() {
591-
max_latency = max_latency.max(latency);
592-
}
588+
if is_output_stream(&stream)?
589+
&& let Ok(latency) = stream.latency()
590+
{
591+
max_latency = max_latency.max(latency);
593592
}
594593
}
595594

crates/audio/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
mod audio_data;
22
mod latency;
3-
mod playback;
43
mod renderer;
54

65
pub use audio_data::*;
76
pub use latency::*;
8-
// playback module now only re-exports from latency module
97
pub use renderer::*;
108

119
pub trait FromSampleBytes: cpal::SizedSample + std::fmt::Debug + Send + 'static {

crates/audio/src/playback.rs

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)