moving imports trough die gegend

This commit is contained in:
2025-08-02 00:34:33 +02:00
parent fd94645096
commit cd05e6a1e6

View File

@@ -472,40 +472,12 @@ fn get_cpu_temp() -> Option<f32> {
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
{ {
// Method 1: Try WMI first (for modern hardware)
if let Some(temp) = get_cpu_temp_wmi() {
return Some(temp);
}
// Method 2: Fallback to Open Hardware Monitor (HTTP API)
if let Some(temp) = get_cpu_temp_ohm() {
return Some(temp);
}
// Method 3: Fallback to CoreTemp (shared memory)
if let Some(temp) = get_cpu_temp_coretemp() {
return Some(temp);
}
eprintln!("All methods failed to read CPU temperature.");
None
}
#[cfg(not(any(target_os = "linux", target_os = "windows")))]
{
println!("CPU temperature retrieval not supported on this OS.");
None
}
}
#[cfg(target_os = "windows")]
use com::runtime::init_runtime; use com::runtime::init_runtime;
use com::sys::{CLSCTX_INPROC_SERVER, COINIT_MULTITHREADED}; use com::sys::{CLSCTX_INPROC_SERVER, COINIT_MULTITHREADED};
use widestring::U16CString; use widestring::U16CString;
use winapi::shared::wtypes::VT_I4; use winapi::shared::wtypes::VT_I4;
use winapi::um::oaidl::VARIANT; use winapi::um::oaidl::VARIANT;
use winapi::um::{combaseapi, wbemcli}; use winapi::um::{combaseapi, wbemcli};
fn get_cpu_temp_wmi() -> Option<f32> {
init_runtime().ok()?; init_runtime().ok()?;
unsafe { unsafe {
@@ -541,7 +513,8 @@ fn get_cpu_temp_wmi() -> Option<f32> {
return None; return None;
} }
let query = U16CString::from_str("SELECT * FROM MSAcpi_ThermalZoneTemperature").unwrap(); let query =
U16CString::from_str("SELECT * FROM MSAcpi_ThermalZoneTemperature").unwrap();
let mut enumerator: *mut wbemcli::IEnumWbemClassObject = std::ptr::null_mut(); let mut enumerator: *mut wbemcli::IEnumWbemClassObject = std::ptr::null_mut();
let hr = (*services).ExecQuery( let hr = (*services).ExecQuery(
U16CString::from_str("WQL").unwrap().as_ptr().cast_mut(), U16CString::from_str("WQL").unwrap().as_ptr().cast_mut(),
@@ -591,33 +564,11 @@ fn get_cpu_temp_wmi() -> Option<f32> {
} }
} }
#[cfg(target_os = "windows")] #[cfg(not(any(target_os = "linux", target_os = "windows")))]
fn get_cpu_temp_ohm() -> Option<f32> { {
// Open Hardware Monitor HTTP API fallback println!("CPU temperature retrieval not supported on this OS.");
let output = Command::new("curl") None
.args(&["-s", "http://localhost:5000/data.json"])
.output()
.ok()?;
let json: serde_json::Value = serde_json::from_slice(&output.stdout).ok()?;
json["Children"][0]["Children"][0]["Children"]
.as_array()?
.iter()
.find(|s| s["Text"].as_str() == Some("CPU Package"))
.and_then(|s| s["Value"].as_f64())
.map(|t| t as f32)
} }
#[cfg(target_os = "windows")]
fn get_cpu_temp_coretemp() -> Option<f32> {
// CoreTemp shared memory fallback
let output = Command::new("CoreTemp.exe").arg("/S").output().ok()?;
String::from_utf8_lossy(&output.stdout)
.lines()
.find(|line| line.contains("Core 0"))
.and_then(|line| line.split_whitespace().last())
.and_then(|s| s.replace("°C", "").parse::<f32>().ok())
} }
fn get_disk_info() -> (f64, f64, f64) { fn get_disk_info() -> (f64, f64, f64) {