Skip to content

Commit

Permalink
fix: 取得できた値はそのまま返却するように修正
Browse files Browse the repository at this point in the history
  • Loading branch information
shm11C3 committed Sep 22, 2024
1 parent 531e072 commit 8c4a4d3
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions src-tauri/src/commands/hardware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ pub fn get_cpu_usage(state: tauri::State<'_, AppState>) -> i32 {
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SysInfo {
pub cpu: system_info_service::CpuInfo,
pub memory: system_info_service::MemoryInfo,
pub gpus: Vec<graphic_service::GraphicInfo>,
pub cpu: Option<system_info_service::CpuInfo>,
pub memory: Option<system_info_service::MemoryInfo>,
pub gpus: Option<Vec<graphic_service::GraphicInfo>>,
}

///
Expand All @@ -58,24 +58,21 @@ pub struct SysInfo {
pub async fn get_hardware_info(
state: tauri::State<'_, AppState>,
) -> Result<SysInfo, String> {
let cpu = system_info_service::get_cpu_info(state.system.lock().unwrap());
let memory = system_info_service::get_memory_info();
let gpus = graphic_service::get_nvidia_gpu_info().await;

match (cpu, memory, gpus) {
(Ok(cpu_info), Ok(memory_info), Ok(gpu_info)) => Ok(SysInfo {
cpu: cpu_info,
memory: memory_info,
gpus: gpu_info,
}),
(Err(e), _, _) | (_, Err(e), _) | (_, _, Err(e)) => {
log_error!(
"get_sys_info_failed",
"get_hardware_info",
Some(e.to_string())
);
Err(format!("Failed to get hardware info: {}", e))
}
let cpu_result = system_info_service::get_cpu_info(state.system.lock().unwrap());
let memory_result = system_info_service::get_memory_info();
let gpus_result = graphic_service::get_nvidia_gpu_info().await;

let sys_info = SysInfo {
cpu: cpu_result.ok(),
memory: memory_result.ok(),
gpus: gpus_result.ok(),
};

// すべての情報が失敗した場合にのみエラーメッセージを返す
if sys_info.cpu.is_none() && sys_info.memory.is_none() && sys_info.gpus.is_none() {
Err("Failed to get any hardware info".to_string())
} else {
Ok(sys_info)
}
}

Expand Down

0 comments on commit 8c4a4d3

Please sign in to comment.