diff --git a/crates/client/src/gui/dock.rs b/crates/client/src/gui/dock.rs index 80b0262..6563e20 100644 --- a/crates/client/src/gui/dock.rs +++ b/crates/client/src/gui/dock.rs @@ -14,7 +14,7 @@ use super::{ hoverable_with, share_view::kind_icon, text, voice_stats, wave, widget::icon_button, }; -const PING_BARS: usize = 12; +const PING_POINTS: usize = 12; impl Yumush { pub(super) fn dock(&self, entity: &Entity, palette: Palette) -> Option { @@ -61,7 +61,7 @@ impl Yumush { .voice_samples .back() .map_or(0., |sample| sample.ping_ms); - let start = self.chat.voice_samples.len().saturating_sub(PING_BARS); + let start = self.chat.voice_samples.len().saturating_sub(PING_POINTS); let pings: Vec = self .chat .voice_samples @@ -71,17 +71,13 @@ impl Yumush { .collect(); let peak = pings.iter().copied().fold(1., f32::max); let bars = div() - .flex() - .items_end() - .gap(px(1.)) + .w(px(PING_POINTS as f32 * 3.)) .h(px(12.)) - .children(pings.iter().map(|ping| { - div() - .w(px(2.)) - .h(px((12. * ping / peak).max(1.))) - .rounded(px(1.)) - .bg(tone) - })); + .child(wave::line_of( + pings.iter().map(|ping| ping / peak * 0.9).collect(), + PING_POINTS, + tone, + )); div() .flex() diff --git a/crates/client/src/gui/wave.rs b/crates/client/src/gui/wave.rs index 0d9a10c..a45af63 100644 --- a/crates/client/src/gui/wave.rs +++ b/crates/client/src/gui/wave.rs @@ -193,13 +193,17 @@ fn wave(bars: &[f32], size: f32, color: Hsla) -> Div { } pub fn line(levels: Vec, color: Hsla) -> impl IntoElement { + line_of(levels, SAMPLE_HISTORY, color) +} + +pub fn line_of(levels: Vec, slots: usize, color: Hsla) -> impl IntoElement { canvas( |_, _, _| {}, move |bounds, _, window, _| { - let first = SAMPLE_HISTORY.saturating_sub(levels.len()); + let first = slots.saturating_sub(levels.len()); let mut path = PathBuilder::stroke(px(1.5)); for (index, &level) in levels.iter().enumerate() { - let step = (first + index) as f32 / (SAMPLE_HISTORY - 1) as f32; + let step = (first + index) as f32 / slots.saturating_sub(1).max(1) as f32; let x = bounds.origin.x + bounds.size.width * step; let y = bounds.origin.y + bounds.size.height * (1. - level); if index == 0 { diff --git a/crates/client/src/usage/mod.rs b/crates/client/src/usage/mod.rs index efc70e6..e03d26a 100644 --- a/crates/client/src/usage/mod.rs +++ b/crates/client/src/usage/mod.rs @@ -124,6 +124,7 @@ struct Sampler { pid: Pid, cores: f32, cpu_model: Arc, + primed: bool, gpu: GpuSampler, #[cfg(target_os = "linux")] threads: threads::Sampler, @@ -146,6 +147,7 @@ impl Sampler { system, pid: Pid::from_u32(std::process::id()), cpu_model, + primed: false, gpu: GpuSampler::default(), #[cfg(target_os = "linux")] threads: threads::Sampler::default(), @@ -161,6 +163,9 @@ impl Sampler { true, ProcessRefreshKind::nothing().with_cpu().with_memory(), ); + if !std::mem::replace(&mut self.primed, true) { + return None; + } let process = self.system.process(self.pid)?; let mb = |bytes: u64| (bytes / (1024 * 1024)) as u32; let total = self.system.total_memory();