From 826bc701c11e5dae9d9e130c215ecdecb48428ce Mon Sep 17 00:00:00 2001 From: ClementTsang Date: Sat, 7 Sep 2019 23:34:29 -0400 Subject: [PATCH] Added 'used' field in disks polling, as it is more accurate --- src/main.rs | 7 ++----- src/widgets/disks.rs | 6 ++++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 41c7d4e1..a9095c38 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,3 @@ -use futures::{ - future::{err, join_all, ok}, - prelude::*, -}; use sysinfo::{System, SystemExt}; mod widgets; @@ -37,6 +33,7 @@ async fn main() { sys.refresh_network(); // What we want to do: For timed data, if there is an error, just do not add. For other data, just don't update! + // TODO: Joining all would be better... list_of_timed_network.push(network::get_network_data(&sys)); if let Ok(process_vec) = processes::get_sorted_processes_list(processes::ProcessSorting::CPU, true).await { @@ -66,7 +63,7 @@ async fn main() { ); } for disk in &list_of_disks { - println!("{} is mounted on {}: {}/{} free.", disk.name, disk.mount_point, disk.avail_space as f64, disk.total_space as f64); + println!("{} is mounted on {}: {} used.", disk.name, disk.mount_point, disk.used_space as f64 / disk.total_space as f64); // TODO: Check if this is valid } diff --git a/src/widgets/disks.rs b/src/widgets/disks.rs index c87bb0f9..0739ee4d 100644 --- a/src/widgets/disks.rs +++ b/src/widgets/disks.rs @@ -4,7 +4,8 @@ use heim_common::prelude::StreamExt; pub struct DiskInfo { pub name : Box, pub mount_point : Box, - pub avail_space : u64, + pub free_space : u64, + pub used_space : u64, pub total_space : u64, } @@ -59,7 +60,8 @@ pub async fn get_disk_usage_list() -> Result, heim::Error> { let usage = heim::disk::usage(partition.mount_point().to_path_buf()).await?; vec_disks.push(DiskInfo { - avail_space : usage.free().get::(), + free_space : usage.free().get::(), + used_space : usage.used().get::(), total_space : usage.total().get::(), mount_point : Box::from(partition.mount_point().to_str().unwrap_or("Name Unavailable")), name : Box::from(partition.device().unwrap_or_else(|| std::ffi::OsStr::new("Name Unavailable")).to_str().unwrap_or("Name Unavailable")),