mirror of
https://github.com/kunkunsh/kunkun-ext-neohtop.git
synced 2025-04-11 17:29:45 +00:00
fix: disks stats for windows
This commit is contained in:
parent
6199101647
commit
2345556161
@ -5,12 +5,13 @@ use sysinfo::{
|
|||||||
ProcessStatus,
|
ProcessStatus,
|
||||||
NetworksExt,
|
NetworksExt,
|
||||||
NetworkExt,
|
NetworkExt,
|
||||||
DiskExt,
|
Disk,
|
||||||
SystemExt,
|
SystemExt,
|
||||||
CpuExt,
|
CpuExt,
|
||||||
ProcessExt,
|
ProcessExt,
|
||||||
PidExt,
|
PidExt,
|
||||||
};
|
};
|
||||||
|
use std::slice::Iter;
|
||||||
use tauri::State;
|
use tauri::State;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@ -75,6 +76,20 @@ pub struct SystemStats {
|
|||||||
pub disk_free_bytes: u64,
|
pub disk_free_bytes: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Assume MacOS or Linux
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
fn filter_disks(disks: &[Disk]) -> Iter<Disk> {
|
||||||
|
disks.iter().filter(|disk| {
|
||||||
|
// Filter for physical disks - typically those mounted at "/"
|
||||||
|
disk.mount_point() == std::path::Path::new("/")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
fn filter_disks(disks: &[Disk]) -> Iter<Disk> {
|
||||||
|
disks.iter()
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn get_processes(state: State<'_, AppState>) -> Result<(Vec<ProcessInfo>, SystemStats), String> {
|
async fn get_processes(state: State<'_, AppState>) -> Result<(Vec<ProcessInfo>, SystemStats), String> {
|
||||||
let processes_data;
|
let processes_data;
|
||||||
@ -121,12 +136,8 @@ async fn get_processes(state: State<'_, AppState>) -> Result<(Vec<ProcessInfo>,
|
|||||||
|
|
||||||
*last_update = (current_time, current_rx, current_tx);
|
*last_update = (current_time, current_rx, current_tx);
|
||||||
|
|
||||||
// Calculate total disk usage - only for physical disks
|
// Calculate total disk usage
|
||||||
let disk_stats = sys.disks().iter()
|
let disk_stats = filter_disks(& sys.disks())
|
||||||
.filter(|disk| {
|
|
||||||
// Filter for physical disks - typically those mounted at "/"
|
|
||||||
disk.mount_point() == std::path::Path::new("/")
|
|
||||||
})
|
|
||||||
.fold((0, 0, 0), |acc, disk| {
|
.fold((0, 0, 0), |acc, disk| {
|
||||||
(
|
(
|
||||||
acc.0 + disk.total_space(),
|
acc.0 + disk.total_space(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user