From b0042ff47571ff2b744a617f6cf15f9a3fca078c Mon Sep 17 00:00:00 2001 From: shm Date: Sun, 24 Nov 2024 01:28:58 +0900 Subject: [PATCH] Fix: Corrected bugs in the processes list, including display errors and sorting issues --- src-tauri/Cargo.lock | 2 +- src-tauri/Cargo.toml | 2 +- src-tauri/src/commands/hardware.rs | 6 ++--- src-tauri/tauri.conf.json | 2 +- src/components/charts/ProcessTable.tsx | 31 ++++++++++++++++++++++---- 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 1c364cb..49c612c 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1693,7 +1693,7 @@ dependencies = [ [[package]] name = "hardware_visualizer" -version = "0.1.1" +version = "0.1.2" dependencies = [ "base64 0.22.1", "chrono", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 1c25b40..b10769e 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -12,7 +12,7 @@ lto = true [package] name = "hardware_visualizer" -version = "0.1.1" +version = "0.1.2" description = "A real-time hardware monitoring tool for Windows" authors = ["@shm11C3"] license = "" diff --git a/src-tauri/src/commands/hardware.rs b/src-tauri/src/commands/hardware.rs index e0f8ac4..6a5a7bc 100644 --- a/src-tauri/src/commands/hardware.rs +++ b/src-tauri/src/commands/hardware.rs @@ -87,11 +87,11 @@ pub fn get_process_list(state: tauri::State<'_, AppState>) -> Vec { let memory_usage = if let Some(history) = process_memory_histories.get(&pid) { let len = history.len().min(5); // 最大5秒分のデータ let sum: f32 = history.iter().rev().take(len).sum(); - let avg = sum / len as f32; + let avg = (sum as f32 / 1024.0) / len as f32; - (avg * 10.0).round() / 10.0 + (avg * 10.0).round() / 10.0 // 小数点1桁で丸める } else { - process.memory() as f32 / 1024.0 // 履歴がなければ現在のメモリ使用量を返す + process.memory() as f32 / 1024.0 // KB → MBに変換 }; ProcessInfo { diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 81ede2e..a0f3f20 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -45,7 +45,7 @@ }, "productName": "HardwareVisualizer", "mainBinaryName": "hardware-visualizer", - "version": "0.1.1", + "version": "0.1.2", "identifier": "HardwareVisualizer", "plugins": {}, "app": { diff --git a/src/components/charts/ProcessTable.tsx b/src/components/charts/ProcessTable.tsx index 8b20090..b6fb5f3 100644 --- a/src/components/charts/ProcessTable.tsx +++ b/src/components/charts/ProcessTable.tsx @@ -39,12 +39,35 @@ const ProcessesTable = ({ const sortedProcesses = [...processes]; if (sortConfig !== null) { sortedProcesses.sort((a, b) => { - if (a[sortConfig.key] < b[sortConfig.key]) { - return sortConfig.direction === "ascending" ? -1 : 1; + const aValue = a[sortConfig.key]; + const bValue = b[sortConfig.key]; + + // 数値の場合はそのまま比較 + if (typeof aValue === "number" && typeof bValue === "number") { + return sortConfig.direction === "ascending" + ? aValue - bValue + : bValue - aValue; } - if (a[sortConfig.key] > b[sortConfig.key]) { - return sortConfig.direction === "ascending" ? 1 : -1; + + // 数値を文字列として保持している場合は数値に変換 + if (typeof aValue === "string" && typeof bValue === "string") { + const aNumber = Number.parseFloat(aValue); + const bNumber = Number.parseFloat(bValue); + + // 小数が文字列として比較されてしまうため、NaNでない場合は数値として比較 + if (!Number.isNaN(aNumber) && !Number.isNaN(bNumber)) { + return sortConfig.direction === "ascending" + ? aNumber - bNumber + : bNumber - aNumber; + } + + // 数値でない場合は文字列として比較 + return sortConfig.direction === "ascending" + ? aValue.localeCompare(bValue) + : bValue.localeCompare(aValue); } + + // 型が異なる場合は順序を変更しない return 0; }); }