refactor: split info_stream into module
in preparation to create a client-server model
This commit is contained in:
parent
534b6cde99
commit
171194e99f
2 changed files with 31 additions and 23 deletions
28
src/app/info_stream.rs
Normal file
28
src/app/info_stream.rs
Normal 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;
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
@ -1,14 +1,11 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use iced::{
|
||||
Color, Element, Length, Renderer, Task, Theme, application, futures::SinkExt, stream, theme,
|
||||
widget,
|
||||
};
|
||||
use smol::Timer;
|
||||
use iced::{Color, Element, Length, Renderer, Task, Theme, application, theme, widget};
|
||||
|
||||
use crate::{app::graph::Graph, sysinfo_snapshot::SysinfoSnapshot};
|
||||
|
||||
mod graph;
|
||||
mod info_stream;
|
||||
|
||||
enum Message {
|
||||
Info(SysinfoSnapshot),
|
||||
|
|
@ -28,24 +25,7 @@ impl State {
|
|||
fn new() -> (Self, Task<Message>) {
|
||||
(
|
||||
Self::default(),
|
||||
Task::run(
|
||||
stream::channel(1, async |mut sender| {
|
||||
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;
|
||||
}
|
||||
}),
|
||||
Message::Info,
|
||||
),
|
||||
Task::run(info_stream::create(), Message::Info),
|
||||
)
|
||||
}
|
||||
fn update(&mut self, message: Message) -> Task<Message> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue