moving imports trough die gegend
This commit is contained in:
@@ -472,40 +472,12 @@ fn get_cpu_temp() -> Option<f32> {
|
||||
|
||||
#[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::sys::{CLSCTX_INPROC_SERVER, COINIT_MULTITHREADED};
|
||||
use widestring::U16CString;
|
||||
use winapi::shared::wtypes::VT_I4;
|
||||
use winapi::um::oaidl::VARIANT;
|
||||
use winapi::um::{combaseapi, wbemcli};
|
||||
fn get_cpu_temp_wmi() -> Option<f32> {
|
||||
init_runtime().ok()?;
|
||||
|
||||
unsafe {
|
||||
@@ -541,7 +513,8 @@ fn get_cpu_temp_wmi() -> Option<f32> {
|
||||
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 hr = (*services).ExecQuery(
|
||||
U16CString::from_str("WQL").unwrap().as_ptr().cast_mut(),
|
||||
@@ -591,33 +564,11 @@ fn get_cpu_temp_wmi() -> Option<f32> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
fn get_cpu_temp_ohm() -> Option<f32> {
|
||||
// Open Hardware Monitor HTTP API fallback
|
||||
let output = Command::new("curl")
|
||||
.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(not(any(target_os = "linux", target_os = "windows")))]
|
||||
{
|
||||
println!("CPU temperature retrieval not supported on this OS.");
|
||||
None
|
||||
}
|
||||
|
||||
#[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) {
|
||||
|
Reference in New Issue
Block a user