forge
Explore
Log in

Don't you dare go Hollow

Dock ping is a line wave like the stats graph

Browse files at this commit

d58406ac6a5fc85dc8840e1f20e7f308cb1e59e7Ahmet Kaan GümüşParent: 24aef4b
  • feat
    • dock ping is a line wave like the stats graph
  • fix
    • usage drops its first sample (sysinfo's first per-process CPU on Windows is lifetime-vs-boot garbage)
Show full message
✨ feat: dock ping is a line wave like the stats graph; 🐛 fix: usage drops its first sample (sysinfo's first per-process CPU on Windows is lifetime-vs-boot garbage)
crates/client/src/gui/dock.rsmodified+8 -12
@@ -14,7 +14,7 @@ use super::{
14 hoverable_with, share_view::kind_icon, text, voice_stats, wave, widget::icon_button,14 hoverable_with, share_view::kind_icon, text, voice_stats, wave, widget::icon_button,
15 };15 };
16 16
17-const PING_BARS: usize = 12;17+const PING_POINTS: usize = 12;
18 18
19 impl Yumush {19 impl Yumush {
20 pub(super) fn dock(&self, entity: &Entity<Self>, palette: Palette) -> Option<impl IntoElement> {20 pub(super) fn dock(&self, entity: &Entity<Self>, palette: Palette) -> Option<impl IntoElement> {
@@ -61,7 +61,7 @@ impl Yumush {
61 .voice_samples61 .voice_samples
62 .back()62 .back()
63 .map_or(0., |sample| sample.ping_ms);63 .map_or(0., |sample| sample.ping_ms);
64- let start = self.chat.voice_samples.len().saturating_sub(PING_BARS);64+ let start = self.chat.voice_samples.len().saturating_sub(PING_POINTS);
65 let pings: Vec<f32> = self65 let pings: Vec<f32> = self
66 .chat66 .chat
67 .voice_samples67 .voice_samples
@@ -71,17 +71,13 @@ impl Yumush {
71 .collect();71 .collect();
72 let peak = pings.iter().copied().fold(1., f32::max);72 let peak = pings.iter().copied().fold(1., f32::max);
73 let bars = div()73 let bars = div()
74- .flex()74+ .w(px(PING_POINTS as f32 * 3.))
75- .items_end()
76- .gap(px(1.))
77 .h(px(12.))75 .h(px(12.))
78- .children(pings.iter().map(|ping| {76+ .child(wave::line_of(
79- div()77+ pings.iter().map(|ping| ping / peak * 0.9).collect(),
80- .w(px(2.))78+ PING_POINTS,
81- .h(px((12. * ping / peak).max(1.)))79+ tone,
82- .rounded(px(1.))80+ ));
83- .bg(tone)
84- }));
85 81
86 div()82 div()
87 .flex()83 .flex()
crates/client/src/gui/wave.rsmodified+6 -2
@@ -193,13 +193,17 @@ fn wave(bars: &[f32], size: f32, color: Hsla) -> Div {
193 }193 }
194 194
195 pub fn line(levels: Vec<f32>, color: Hsla) -> impl IntoElement {195 pub fn line(levels: Vec<f32>, color: Hsla) -> impl IntoElement {
196+ line_of(levels, SAMPLE_HISTORY, color)
197+}
198+
199+pub fn line_of(levels: Vec<f32>, slots: usize, color: Hsla) -> impl IntoElement {
196 canvas(200 canvas(
197 |_, _, _| {},201 |_, _, _| {},
198 move |bounds, _, window, _| {202 move |bounds, _, window, _| {
199- let first = SAMPLE_HISTORY.saturating_sub(levels.len());203+ let first = slots.saturating_sub(levels.len());
200 let mut path = PathBuilder::stroke(px(1.5));204 let mut path = PathBuilder::stroke(px(1.5));
201 for (index, &level) in levels.iter().enumerate() {205 for (index, &level) in levels.iter().enumerate() {
202- let step = (first + index) as f32 / (SAMPLE_HISTORY - 1) as f32;206+ let step = (first + index) as f32 / slots.saturating_sub(1).max(1) as f32;
203 let x = bounds.origin.x + bounds.size.width * step;207 let x = bounds.origin.x + bounds.size.width * step;
204 let y = bounds.origin.y + bounds.size.height * (1. - level);208 let y = bounds.origin.y + bounds.size.height * (1. - level);
205 if index == 0 {209 if index == 0 {
crates/client/src/usage/mod.rsmodified+5 -0
@@ -124,6 +124,7 @@ struct Sampler {
124 pid: Pid,124 pid: Pid,
125 cores: f32,125 cores: f32,
126 cpu_model: Arc<str>,126 cpu_model: Arc<str>,
127+ primed: bool,
127 gpu: GpuSampler,128 gpu: GpuSampler,
128 #[cfg(target_os = "linux")]129 #[cfg(target_os = "linux")]
129 threads: threads::Sampler,130 threads: threads::Sampler,
@@ -146,6 +147,7 @@ impl Sampler {
146 system,147 system,
147 pid: Pid::from_u32(std::process::id()),148 pid: Pid::from_u32(std::process::id()),
148 cpu_model,149 cpu_model,
150+ primed: false,
149 gpu: GpuSampler::default(),151 gpu: GpuSampler::default(),
150 #[cfg(target_os = "linux")]152 #[cfg(target_os = "linux")]
151 threads: threads::Sampler::default(),153 threads: threads::Sampler::default(),
@@ -161,6 +163,9 @@ impl Sampler {
161 true,163 true,
162 ProcessRefreshKind::nothing().with_cpu().with_memory(),164 ProcessRefreshKind::nothing().with_cpu().with_memory(),
163 );165 );
166+ if !std::mem::replace(&mut self.primed, true) {
167+ return None;
168+ }
164 let process = self.system.process(self.pid)?;169 let process = self.system.process(self.pid)?;
165 let mb = |bytes: u64| (bytes / (1024 * 1024)) as u32;170 let mb = |bytes: u64| (bytes / (1024 * 1024)) as u32;
166 let total = self.system.total_memory();171 let total = self.system.total_memory();