moving imports trough die gegend

This commit is contained in:
2025-08-01 23:12:15 +02:00
parent b9bd984de4
commit 53d701ce5c

View File

@@ -422,21 +422,50 @@ fn get_cpu_temp() -> Option<f32> {
println!("Attempting to get CPU temperature..."); println!("Attempting to get CPU temperature...");
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
{ {
println!("Attempting to get CPU temperature on Linux..."); // Versuche mehrere Methoden der Reihe nach
let mut sys = System::new_all(); // 1. sensors-Befehl
//let components = Components::new_with_refreshed_list(); if let Ok(output) = Command::new("sensors").output() {
sys.refresh_all(); let stdout = String::from_utf8_lossy(&output.stdout);
for component in sys.components() { for line in stdout.lines() {
if let Some(temperature) = component.temperature() { if line.contains("Package id") || line.contains("Tdie") || line.contains("CPU Temp")
println!( {
"Component: {}, Temperature: {}°C", if let Some(temp_str) = line
component.label(), .split('+')
temperature .nth(1)
); .and_then(|s| s.split_whitespace().next())
{
if let Ok(temp) = temp_str.replace("°C", "").parse::<f32>() {
return Some(temp);
}
}
}
} }
} }
None // 2. Sysfs (Intel/AMD)
if let Ok(content) = fs::read_to_string("/sys/class/thermal/thermal_zone0/temp") {
if let Ok(temp) = content.trim().parse::<f32>() {
return Some(temp / 1000.0);
}
}
// 3. Alternative Sysfs-Pfade
let paths = [
"/sys/class/hwmon/hwmontemp1_input",
"/sys/class/hwmon/hwmondevice/temp1_input",
];
for path_pattern in &paths {
if let Ok(paths) = glob::glob(path_pattern) {
for path in paths.flatten() {
if let Ok(content) = fs::read_to_string(&path) {
if let Ok(temp) = content.trim().parse::<f32>() {
return Some(temp / 1000.0);
}
}
}
}
}
} }
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]