moving imports trough die gegend
This commit is contained in:
@@ -422,21 +422,50 @@ fn get_cpu_temp() -> Option<f32> {
|
||||
println!("Attempting to get CPU temperature...");
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
println!("Attempting to get CPU temperature on Linux...");
|
||||
let mut sys = System::new_all();
|
||||
//let components = Components::new_with_refreshed_list();
|
||||
sys.refresh_all();
|
||||
for component in sys.components() {
|
||||
if let Some(temperature) = component.temperature() {
|
||||
println!(
|
||||
"Component: {}, Temperature: {}°C",
|
||||
component.label(),
|
||||
temperature
|
||||
);
|
||||
// Versuche mehrere Methoden der Reihe nach
|
||||
// 1. sensors-Befehl
|
||||
if let Ok(output) = Command::new("sensors").output() {
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
for line in stdout.lines() {
|
||||
if line.contains("Package id") || line.contains("Tdie") || line.contains("CPU Temp")
|
||||
{
|
||||
if let Some(temp_str) = line
|
||||
.split('+')
|
||||
.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")]
|
||||
|
Reference in New Issue
Block a user