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::{
1414 hoverable_with, share_view::kind_icon, text, voice_stats, wave, widget::icon_button,
1515 };
1616
17-const PING_BARS: usize = 12;
17+const PING_POINTS: usize = 12;
1818
1919 impl Yumush {
2020 pub(super) fn dock(&self, entity: &Entity<Self>, palette: Palette) -> Option<impl IntoElement> {
@@ -61,7 +61,7 @@ impl Yumush {
6161 .voice_samples
6262 .back()
6363 .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);
6565 let pings: Vec<f32> = self
6666 .chat
6767 .voice_samples
@@ -71,17 +71,13 @@ impl Yumush {
7171 .collect();
7272 let peak = pings.iter().copied().fold(1., f32::max);
7373 let bars = div()
74- .flex()
75- .items_end()
76- .gap(px(1.))
74+ .w(px(PING_POINTS as f32 * 3.))
7775 .h(px(12.))
78- .children(pings.iter().map(|ping| {
79- div()
80- .w(px(2.))
81- .h(px((12. * ping / peak).max(1.)))
82- .rounded(px(1.))
83- .bg(tone)
84- }));
76+ .child(wave::line_of(
77+ pings.iter().map(|ping| ping / peak * 0.9).collect(),
78+ PING_POINTS,
79+ tone,
80+ ));
8581
8682 div()
8783 .flex()
crates/client/src/gui/wave.rsmodified+6 -2
@@ -193,13 +193,17 @@ fn wave(bars: &[f32], size: f32, color: Hsla) -> Div {
193193 }
194194
195195 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 {
196200 canvas(
197201 |_, _, _| {},
198202 move |bounds, _, window, _| {
199- let first = SAMPLE_HISTORY.saturating_sub(levels.len());
203+ let first = slots.saturating_sub(levels.len());
200204 let mut path = PathBuilder::stroke(px(1.5));
201205 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;
203207 let x = bounds.origin.x + bounds.size.width * step;
204208 let y = bounds.origin.y + bounds.size.height * (1. - level);
205209 if index == 0 {
crates/client/src/usage/mod.rsmodified+5 -0
@@ -124,6 +124,7 @@ struct Sampler {
124124 pid: Pid,
125125 cores: f32,
126126 cpu_model: Arc<str>,
127+ primed: bool,
127128 gpu: GpuSampler,
128129 #[cfg(target_os = "linux")]
129130 threads: threads::Sampler,
@@ -146,6 +147,7 @@ impl Sampler {
146147 system,
147148 pid: Pid::from_u32(std::process::id()),
148149 cpu_model,
150+ primed: false,
149151 gpu: GpuSampler::default(),
150152 #[cfg(target_os = "linux")]
151153 threads: threads::Sampler::default(),
@@ -161,6 +163,9 @@ impl Sampler {
161163 true,
162164 ProcessRefreshKind::nothing().with_cpu().with_memory(),
163165 );
166+ if !std::mem::replace(&mut self.primed, true) {
167+ return None;
168+ }
164169 let process = self.system.process(self.pid)?;
165170 let mb = |bytes: u64| (bytes / (1024 * 1024)) as u32;
166171 let total = self.system.total_memory();