diff --git a/flake.nix b/flake.nix index 167c06e..351e0b4 100644 --- a/flake.nix +++ b/flake.nix @@ -33,7 +33,6 @@ programs.nixfmt.enable = true; programs.qmlformat.enable = true; programs.rustfmt.enable = true; - programs.taplo.enable = true; }; forAllSystems = fn: diff --git a/stats-daemon/Cargo.toml b/stats-daemon/Cargo.toml index 2e42faf..71f41fe 100644 --- a/stats-daemon/Cargo.toml +++ b/stats-daemon/Cargo.toml @@ -3,12 +3,6 @@ name = "nova-stats" version = "0.1.0" edition = "2021" -[lints.clippy] -pedantic = { level = "warn", priority = -1 } -cast_possible_truncation = "allow" -cast_precision_loss = "allow" -cast_sign_loss = "allow" - [[bin]] name = "nova-stats" path = "src/main.rs" diff --git a/stats-daemon/src/cpu.rs b/stats-daemon/src/cpu.rs index c0ad4ae..34c8863 100644 --- a/stats-daemon/src/cpu.rs +++ b/stats-daemon/src/cpu.rs @@ -56,7 +56,11 @@ pub fn emit_cpu(out: &mut impl Write, prev: &[Sample], curr: &[Sample], freqs: & return; } - let usage = prev.first().zip(curr.first()).map_or(0, |(p, c)| pct(p, c)); + let usage = prev + .first() + .zip(curr.first()) + .map(|(p, c)| pct(p, c)) + .unwrap_or(0); let core_usage: Vec = prev .iter() diff --git a/stats-daemon/src/gpu.rs b/stats-daemon/src/gpu.rs index 5d114b9..3c2a989 100644 --- a/stats-daemon/src/gpu.rs +++ b/stats-daemon/src/gpu.rs @@ -53,7 +53,7 @@ fn find_amd_hwmon() -> Option { None } -fn read_amd(card: &str, hwmon: Option<&String>) -> Option { +fn read_amd(card: &str, hwmon: &Option) -> Option { let usage: u32 = fs::read_to_string(format!("{card}/gpu_busy_percent")) .ok()? .trim() @@ -70,9 +70,11 @@ fn read_amd(card: &str, hwmon: Option<&String>) -> Option { .parse() .ok()?; let temp_c = hwmon + .as_ref() .and_then(|h| fs::read_to_string(format!("{h}/temp1_input")).ok()) .and_then(|s| s.trim().parse::().ok()) - .map_or(0, |mc| mc / 1000); + .map(|mc| mc / 1000) + .unwrap_or(0); Some(GpuInfo { usage, vram_used_gb: vram_used as f64 / 1_073_741_824.0, @@ -112,7 +114,7 @@ pub fn emit_gpu(out: &mut impl Write, backend: &GpuBackend) { GpuBackend::Amd { card_path, hwmon_path, - } => read_amd(card_path, hwmon_path.as_ref()), + } => read_amd(card_path, hwmon_path), GpuBackend::Nvidia => read_nvidia(), GpuBackend::None => return, }; diff --git a/stats-daemon/src/main.rs b/stats-daemon/src/main.rs index 66fa98d..572b864 100644 --- a/stats-daemon/src/main.rs +++ b/stats-daemon/src/main.rs @@ -55,8 +55,8 @@ fn main() { tick += 1; let elapsed = t0.elapsed(); - if let Some(remaining) = interval.checked_sub(elapsed) { - thread::sleep(remaining); + if elapsed < interval { + thread::sleep(interval - elapsed); } } } diff --git a/stats-daemon/src/temp.rs b/stats-daemon/src/temp.rs index e84765c..2c93ef9 100644 --- a/stats-daemon/src/temp.rs +++ b/stats-daemon/src/temp.rs @@ -15,8 +15,9 @@ pub fn read_thermal_devices() -> Vec { let temp_path = format!("/sys/class/thermal/thermal_zone{i}/temp"); let type_path = format!("/sys/class/thermal/thermal_zone{i}/type"); - let Ok(temp_str) = fs::read_to_string(&temp_path) else { - break; + let temp_str = match fs::read_to_string(&temp_path) { + Ok(s) => s, + Err(_) => break, }; let millic: i32 = match temp_str.trim().parse() { @@ -26,7 +27,8 @@ pub fn read_thermal_devices() -> Vec { let celsius = millic / 1000; let name = fs::read_to_string(&type_path) - .map_or_else(|_| format!("zone{i}"), |s| s.trim().to_string()); + .map(|s| s.trim().to_string()) + .unwrap_or_else(|_| format!("zone{i}")); // Keep the highest temp seen for each device type let entry = by_name.entry(name).or_insert(celsius);