2019-09-08 19:56:23 -04:00
|
|
|
pub mod cpu;
|
2019-09-05 18:28:54 -04:00
|
|
|
pub mod disks;
|
2019-09-08 19:56:23 -04:00
|
|
|
pub mod mem;
|
2019-09-05 18:28:54 -04:00
|
|
|
pub mod network;
|
|
|
|
pub mod processes;
|
2019-09-08 19:56:23 -04:00
|
|
|
pub mod temperature;
|
|
|
|
|
|
|
|
use sysinfo::{System, SystemExt};
|
|
|
|
|
2019-09-09 18:34:13 -04:00
|
|
|
#[allow(dead_code)]
|
2019-09-08 19:56:23 -04:00
|
|
|
pub struct App<'a> {
|
2019-09-09 18:34:13 -04:00
|
|
|
title : &'a str,
|
2019-09-08 19:56:23 -04:00
|
|
|
pub should_quit : bool,
|
2019-09-09 18:34:13 -04:00
|
|
|
pub process_sorting_type : processes::ProcessSorting,
|
|
|
|
pub process_sorting_reverse : bool,
|
|
|
|
pub to_be_resorted : bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn set_if_valid<T : std::clone::Clone>(result : &Result<T, heim::Error>, value_to_set : &mut T) {
|
|
|
|
if let Ok(result) = result {
|
|
|
|
*value_to_set = (*result).clone();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default, Clone)]
|
|
|
|
pub struct Data {
|
2019-09-08 19:56:23 -04:00
|
|
|
pub list_of_cpu_packages : Vec<cpu::CPUData>,
|
|
|
|
pub list_of_io : Vec<disks::IOData>,
|
|
|
|
pub list_of_physical_io : Vec<disks::IOData>,
|
|
|
|
pub memory : mem::MemData,
|
|
|
|
pub swap : mem::MemData,
|
|
|
|
pub list_of_temperature : Vec<temperature::TempData>,
|
|
|
|
pub network : network::NetworkData,
|
|
|
|
pub list_of_processes : Vec<processes::ProcessData>,
|
|
|
|
pub list_of_disks : Vec<disks::DiskData>,
|
2019-09-09 18:34:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct DataState {
|
|
|
|
pub data : Data,
|
2019-09-09 00:09:58 -04:00
|
|
|
sys : System,
|
2019-09-08 19:56:23 -04:00
|
|
|
}
|
|
|
|
|
2019-09-09 18:34:13 -04:00
|
|
|
impl Default for DataState {
|
|
|
|
fn default() -> Self {
|
|
|
|
DataState {
|
|
|
|
data : Data::default(),
|
|
|
|
sys : System::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DataState {
|
|
|
|
pub async fn update_data(&mut self) {
|
|
|
|
self.sys.refresh_system();
|
|
|
|
self.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!
|
|
|
|
set_if_valid(&network::get_network_data(&self.sys), &mut self.data.network);
|
|
|
|
set_if_valid(&cpu::get_cpu_data_list(&self.sys), &mut self.data.list_of_cpu_packages);
|
|
|
|
|
|
|
|
// TODO: We can convert this to a multi-threaded task...
|
|
|
|
set_if_valid(&processes::get_sorted_processes_list().await, &mut self.data.list_of_processes);
|
|
|
|
set_if_valid(&disks::get_disk_usage_list().await, &mut self.data.list_of_disks);
|
|
|
|
set_if_valid(&disks::get_io_usage_list(false).await, &mut self.data.list_of_io);
|
|
|
|
set_if_valid(&disks::get_io_usage_list(true).await, &mut self.data.list_of_physical_io);
|
|
|
|
set_if_valid(&mem::get_mem_data_list().await, &mut self.data.memory);
|
|
|
|
set_if_valid(&mem::get_swap_data_list().await, &mut self.data.swap);
|
|
|
|
set_if_valid(&temperature::get_temperature_data().await, &mut self.data.list_of_temperature);
|
2019-09-08 19:56:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> App<'a> {
|
|
|
|
pub fn new(title : &str) -> App {
|
2019-09-09 00:09:58 -04:00
|
|
|
App {
|
|
|
|
title,
|
|
|
|
process_sorting_type : processes::ProcessSorting::NAME, // TODO: Change this based on input args...
|
|
|
|
should_quit : false,
|
|
|
|
process_sorting_reverse : false,
|
2019-09-09 18:34:13 -04:00
|
|
|
to_be_resorted : false,
|
2019-09-09 00:09:58 -04:00
|
|
|
}
|
2019-09-08 19:56:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn on_key(&mut self, c : char) {
|
|
|
|
match c {
|
|
|
|
'q' => self.should_quit = true,
|
2019-09-09 00:09:58 -04:00
|
|
|
'c' => {
|
2019-09-09 18:34:13 -04:00
|
|
|
self.process_sorting_type = processes::ProcessSorting::CPU; // TODO: Change this such that reversing can be done by just hitting "c" twice...
|
|
|
|
self.to_be_resorted = true;
|
2019-09-09 00:09:58 -04:00
|
|
|
}
|
|
|
|
'm' => {
|
|
|
|
self.process_sorting_type = processes::ProcessSorting::MEM;
|
2019-09-09 18:34:13 -04:00
|
|
|
self.to_be_resorted = true;
|
2019-09-09 00:09:58 -04:00
|
|
|
}
|
|
|
|
'p' => {
|
|
|
|
self.process_sorting_type = processes::ProcessSorting::PID;
|
2019-09-09 18:34:13 -04:00
|
|
|
self.to_be_resorted = true;
|
2019-09-09 00:09:58 -04:00
|
|
|
}
|
|
|
|
'n' => {
|
|
|
|
self.process_sorting_type = processes::ProcessSorting::NAME;
|
2019-09-09 18:34:13 -04:00
|
|
|
self.to_be_resorted = true;
|
2019-09-09 00:09:58 -04:00
|
|
|
}
|
|
|
|
'r' => {
|
|
|
|
self.process_sorting_reverse = !self.process_sorting_reverse;
|
2019-09-09 18:34:13 -04:00
|
|
|
self.to_be_resorted = true;
|
2019-09-09 00:09:58 -04:00
|
|
|
}
|
2019-09-08 19:56:23 -04:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-09 18:34:13 -04:00
|
|
|
pub fn on_left(&mut self) {
|
|
|
|
}
|
2019-09-08 19:56:23 -04:00
|
|
|
|
2019-09-09 18:34:13 -04:00
|
|
|
pub fn on_right(&mut self) {
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn on_up(&mut self) {
|
|
|
|
}
|
2019-09-08 19:56:23 -04:00
|
|
|
|
2019-09-09 18:34:13 -04:00
|
|
|
pub fn on_down(&mut self) {
|
2019-09-08 19:56:23 -04:00
|
|
|
}
|
|
|
|
}
|