this is unnacceptably unperformant; I think I've reached the point at which sysinfo doesn't do what I want, which is keep track of a table of processes efficiently enough.
64 lines
1.9 KiB
Rust
64 lines
1.9 KiB
Rust
use std::env;
|
|
|
|
use iced::{
|
|
Task,
|
|
futures::{self, SinkExt},
|
|
stream,
|
|
};
|
|
use ron::de;
|
|
use smol::{Timer, unblock};
|
|
|
|
use crate::{
|
|
app,
|
|
sysinfo_snapshot::{self, SysinfoSnapshot},
|
|
};
|
|
|
|
pub fn create() -> Task<app::Message> {
|
|
if env::args()
|
|
.nth(1)
|
|
.is_some_and(|command| command == "client")
|
|
{
|
|
Task::run(
|
|
stream::channel(
|
|
1,
|
|
async |mut sender: futures::channel::mpsc::Sender<SysinfoSnapshot>| {
|
|
let mut buf = String::new();
|
|
loop {
|
|
buf = unblock(move || {
|
|
std::io::stdin().read_line(&mut buf).unwrap();
|
|
buf
|
|
})
|
|
.await;
|
|
|
|
match de::from_str(&buf) {
|
|
Ok(info) => sender.send(info).await.unwrap(),
|
|
Err(e) => eprintln!("{e}"),
|
|
}
|
|
buf.clear();
|
|
}
|
|
},
|
|
),
|
|
app::Message::Info,
|
|
)
|
|
} else {
|
|
Task::run(
|
|
stream::channel(
|
|
1,
|
|
async |mut sender: futures::channel::mpsc::Sender<SysinfoSnapshot>| {
|
|
let mut sys = sysinfo::System::new();
|
|
let refreshes = sysinfo_snapshot::refreshes();
|
|
|
|
sys.refresh_specifics(refreshes);
|
|
Timer::after(sysinfo::MINIMUM_CPU_UPDATE_INTERVAL).await;
|
|
|
|
loop {
|
|
sys.refresh_specifics(refreshes);
|
|
sender.send(SysinfoSnapshot::from(&sys)).await.unwrap();
|
|
Timer::after(sysinfo::MINIMUM_CPU_UPDATE_INTERVAL).await;
|
|
}
|
|
},
|
|
),
|
|
app::Message::Info,
|
|
)
|
|
}
|
|
}
|