refactor: split info_stream into module

in preparation to create a client-server model
This commit is contained in:
electria 2026-08-16 11:02:32 -07:00
commit 171194e99f
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs

28
src/app/info_stream.rs Normal file
View file

@ -0,0 +1,28 @@
use iced::{
futures::{self, SinkExt},
stream,
};
use smol::Timer;
use crate::sysinfo_snapshot::SysinfoSnapshot;
pub fn create() -> impl futures::Stream<Item = SysinfoSnapshot> {
stream::channel(
1,
async |mut sender: futures::channel::mpsc::Sender<SysinfoSnapshot>| {
let mut sys = sysinfo::System::new();
let refreshes = sysinfo::RefreshKind::nothing()
.with_memory(sysinfo::MemoryRefreshKind::everything())
.with_cpu(sysinfo::CpuRefreshKind::nothing().with_cpu_usage());
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;
}
},
)
}