feat: add uptime to title
it will be displayed somewhere else later, hopefully with better formatting too.
This commit is contained in:
parent
79aff51856
commit
534b6cde99
2 changed files with 22 additions and 0 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use iced::{
|
use iced::{
|
||||||
Color, Element, Length, Renderer, Task, Theme, application, futures::SinkExt, stream, theme,
|
Color, Element, Length, Renderer, Task, Theme, application, futures::SinkExt, stream, theme,
|
||||||
widget,
|
widget,
|
||||||
|
|
@ -14,6 +16,8 @@ enum Message {
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct State {
|
struct State {
|
||||||
|
uptime: Duration,
|
||||||
|
|
||||||
total_cpu_graph: Graph,
|
total_cpu_graph: Graph,
|
||||||
cpu_graphs: Vec<Graph>,
|
cpu_graphs: Vec<Graph>,
|
||||||
memory_graph: Graph,
|
memory_graph: Graph,
|
||||||
|
|
@ -47,6 +51,8 @@ impl State {
|
||||||
fn update(&mut self, message: Message) -> Task<Message> {
|
fn update(&mut self, message: Message) -> Task<Message> {
|
||||||
match message {
|
match message {
|
||||||
Message::Info(snapshot) => {
|
Message::Info(snapshot) => {
|
||||||
|
self.uptime = snapshot.uptime();
|
||||||
|
|
||||||
self.total_cpu_graph.update(snapshot.cpu_total);
|
self.total_cpu_graph.update(snapshot.cpu_total);
|
||||||
|
|
||||||
self.memory_graph
|
self.memory_graph
|
||||||
|
|
@ -103,10 +109,15 @@ impl State {
|
||||||
])
|
])
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn title(&self) -> String {
|
||||||
|
format!("itop {:?}", self.uptime)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run() -> Result<(), impl std::error::Error> {
|
pub fn run() -> Result<(), impl std::error::Error> {
|
||||||
application(State::new, State::update, State::view)
|
application(State::new, State::update, State::view)
|
||||||
|
.title(State::title)
|
||||||
.theme(theme::Theme::custom(
|
.theme(theme::Theme::custom(
|
||||||
"high-contrast-dark",
|
"high-contrast-dark",
|
||||||
theme::Palette {
|
theme::Palette {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct SysinfoSnapshot {
|
pub struct SysinfoSnapshot {
|
||||||
|
uptime: u64,
|
||||||
|
|
||||||
pub cpu_total: f32,
|
pub cpu_total: f32,
|
||||||
pub cpus: Vec<f32>,
|
pub cpus: Vec<f32>,
|
||||||
|
|
||||||
|
|
@ -8,10 +12,17 @@ pub struct SysinfoSnapshot {
|
||||||
pub swap: u64,
|
pub swap: u64,
|
||||||
pub swap_total: u64,
|
pub swap_total: u64,
|
||||||
}
|
}
|
||||||
|
impl SysinfoSnapshot {
|
||||||
|
pub fn uptime(&self) -> Duration {
|
||||||
|
Duration::from_secs(self.uptime)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<&sysinfo::System> for SysinfoSnapshot {
|
impl From<&sysinfo::System> for SysinfoSnapshot {
|
||||||
fn from(value: &sysinfo::System) -> Self {
|
fn from(value: &sysinfo::System) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
uptime: sysinfo::System::uptime(),
|
||||||
|
|
||||||
cpu_total: value.global_cpu_usage(),
|
cpu_total: value.global_cpu_usage(),
|
||||||
cpus: value.cpus().iter().map(|cpu| cpu.cpu_usage()).collect(),
|
cpus: value.cpus().iter().map(|cpu| cpu.cpu_usage()).collect(),
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue