From c613275621ffbb03b8aaa2e13633aea11566ce19 Mon Sep 17 00:00:00 2001 From: elkowar <5300871+elkowar@users.noreply.github.com> Date: Sat, 10 Jun 2023 20:30:10 +0200 Subject: [PATCH] Don't constantly log total_avg error --- crates/eww/src/config/system_stats.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/crates/eww/src/config/system_stats.rs b/crates/eww/src/config/system_stats.rs index 46f201b..e55cfa5 100644 --- a/crates/eww/src/config/system_stats.rs +++ b/crates/eww/src/config/system_stats.rs @@ -111,6 +111,8 @@ pub fn get_battery_capacity() -> Result { #[cfg(target_os = "linux")] pub fn get_battery_capacity() -> Result { + use std::sync::atomic::AtomicBool; + let mut current = 0_f64; let mut total = 0_f64; let mut json = String::from('{'); @@ -143,10 +145,14 @@ pub fn get_battery_capacity() -> Result { current += c.trim_end_matches(|c| c == '\n').parse::()?; total += t.trim_end_matches(|c| c == '\n').parse::()?; } else { - log::warn!( - "Failed to get/calculate uWh: the total_avg value of the battery magic var will probably be a garbage \ - value that can not be trusted." - ); + static WARNED: AtomicBool = AtomicBool::new(false); + if !WARNED.load(std::sync::atomic::Ordering::Relaxed) { + WARNED.store(true, std::sync::atomic::Ordering::Relaxed); + log::warn!( + "Failed to get/calculate uWh: the total_avg value of the battery magic var will probably be a \ + garbage value that can not be trusted." + ); + } } } }