forge
Explore
Log in

Don't you dare go Hollow

Stats sheet as two columns over the call bar (connection numbers and ping spark, traffic sparks, machine tracks, sending layers, watching per stream)

Browse files at this commit

62f41caa99ac848770abd478a034c49e3be8fd42Ahmet Kaan GümüşParent: 06e6d99
  • feat
    • stats sheet as two columns over the call bar (connection numbers and ping spark, traffic sparks, machine tracks, sending layers, watching per stream)
    • stage keeps voice lines above shares
    • each person picks a hue (Appearance → Your hue), sent with the user
    • sequential default hues
    • popovers open on first click (no fade inside popover content)
    • sidebar animates only on toggle
    • friend requests stay visible while searching
Show full message
✨ feat: stats sheet as two columns over the call bar (connection numbers and ping spark, traffic sparks, machine tracks, sending layers, watching per stream); stage keeps voice lines above shares; each person picks a hue (Appearance → Your hue), sent with the user; sequential default hues; popovers open on first click (no fade inside popover content); sidebar animates only on toggle; friend requests stay visible while searching

22 changed files +855 -1032

crates/client/src/gui.rsmodified+2 -1
@@ -304,7 +304,7 @@ pub fn millis_time(millis: u64, format: &str) -> String {
304304 .to_string()
305305 }
306306
307-pub use parts::{motion, pop_in, swap_in};
307+pub use parts::motion;
308308
309309 pub fn hoverable(id: impl Into<ElementId>, element: Div, palette: Palette) -> Stateful<Div> {
310310 hoverable_with(id, element, palette.hover)
@@ -655,6 +655,7 @@ impl Yumush {
655655 self.accounts.sign_in(&user, token);
656656 self.request_user_avatar(&user, cx);
657657 self.chat.muted = mutes::load(user.id);
658+ style::remember(&[&user]);
658659 self.user = Some(user);
659660 self.change_page(Route::Chat, window, cx);
660661 self.load_communities(window, cx);
crates/client/src/gui/camera_view.rsmodified+13 -11
@@ -226,24 +226,26 @@ impl Yumush {
226226 .into_iter()
227227 .map(|source| stage_tile(entity, self, palette, source))
228228 .collect();
229- if tiles.is_empty() {
230- return Some(self.voices(palette).into_any_element());
231- }
232-
233- Some(
229+ let strip = (!tiles.is_empty()).then(|| {
234230 div()
235231 .id("stage_strip")
236232 .flex()
237233 .flex_shrink_0()
238234 .h(px(STRIP_H))
239235 .gap(px(space::SM))
240- .p(px(space::SM))
241- .bg(palette.window)
236+ .px(px(space::XL))
237+ .pb(px(space::SM))
242238 .overflow_x_scroll()
243- .border_b_1()
244- .border_color(palette.border)
245239 .children(tiles)
246- .into_any_element(),
240+ });
241+
242+ Some(
243+ div()
244+ .flex()
245+ .flex_col()
246+ .flex_shrink_0()
247+ .child(self.voices(palette))
248+ .children(strip),
247249 )
248250 }
249251
@@ -254,7 +256,7 @@ impl Yumush {
254256 .voice_community()
255257 .map(|community_id| self.chat.voice_ids(community_id))
256258 .unwrap_or_default()
257- .into_iter()
259+ .iter()
258260 .filter_map(|id| self.chat.author(*id))
259261 .map(|user| {
260262 let speaking = self.chat.waves.speaking.contains(&user.id);
crates/client/src/gui/chat.rsmodified+129 -109
@@ -1,4 +1,4 @@
1-use super::style::{radius, size, space, stroke, text};
1+use super::style::{self, radius, size, space, stroke, text};
22 use super::text;
33 use crate::gui::CLOCK;
44 use std::{
@@ -19,7 +19,7 @@ use crate::gui::{
1919 composer::{self, Composer},
2020 entity_action, hoverable,
2121 media_view::{self, Media},
22- message_actions, millis_time, new_input, notify_error, palette, poll, pop_in, presence_avatar,
22+ message_actions, millis_time, new_input, notify_error, palette, poll, presence_avatar,
2323 primary_button,
2424 profile::profile_popover,
2525 rank_tag,
@@ -145,6 +145,7 @@ pub struct Chat {
145145 pub(super) found: Option<User>,
146146 pub(super) invite: InviteLookup,
147147 pub(super) sidebar_collapsed: bool,
148+ pub(super) sidebar_toggled: Option<std::time::Instant>,
148149 pub(super) composer: Composer,
149150 pub(super) drafts: HashMap<Id, String>,
150151 pub(super) poll_question: Entity<InputState>,
@@ -390,6 +391,7 @@ impl Chat {
390391 found: None,
391392 invite: InviteLookup::Idle,
392393 sidebar_collapsed: false,
394+ sidebar_toggled: None,
393395 view: View::Chat,
394396 section: 0,
395397 username_input: editable_input("Username...", Yumush::save_username, window, cx),
@@ -617,7 +619,17 @@ impl Chat {
617619 Event::CommunityUpdated(community) | Event::CommunityAdded(community) => {
618620 self.insert_community(community)
619621 }
620- Event::FriendsUpdated(friends) => self.friends = friends,
622+ Event::FriendsUpdated(friends) => {
623+ style::remember(
624+ &friends
625+ .friends
626+ .iter()
627+ .chain(&friends.incoming)
628+ .chain(&friends.outgoing)
629+ .collect::<Vec<_>>(),
630+ );
631+ self.friends = friends;
632+ }
621633 Event::InvitationsUpdated(invitations) => self.invitations = invitations,
622634 Event::CommunityDeleted { community_id } | Event::Removed { community_id, .. } => {
623635 self.remove_community(community_id)
@@ -882,6 +894,7 @@ impl Chat {
882894 }
883895
884896 fn insert_member(&mut self, member: Member) {
897+ style::remember(&[&member.user]);
885898 self.remove_member(member.user.id);
886899 self.members.push(member);
887900 self.members.sort_by_key(|member| member.user.id);
@@ -995,6 +1008,7 @@ impl Chat {
9951008 }
9961009
9971010 pub fn update_member(&mut self, user: &User) {
1011+ style::remember(&[user]);
9981012 let peers = self
9991013 .communities
10001014 .iter_mut()
@@ -1322,6 +1336,7 @@ impl Yumush {
13221336 .min_w_0()
13231337 .flex()
13241338 .flex_col()
1339+ .relative()
13251340 .bg(palette.window)
13261341 .overflow_hidden()
13271342 .children(self.announcement_banner(entity, palette))
@@ -1343,40 +1358,42 @@ impl Yumush {
13431358 .children(self.stage_strip(entity, themed))
13441359 .children(self.unread_bar(entity, themed))
13451360 .children(self.poll_banner(entity, themed))
1346- .child(
1347- div()
1348- .flex_1()
1349- .min_h_0()
1350- .flex()
1351- .child(div().flex_1().min_w_0().flex().flex_col().map(|panel| {
1352- match self.inline_viewer(entity, themed) {
1353- Some(viewer) => panel.child(viewer),
1354- None => match self.stage_grid(entity, themed) {
1355- Some(grid) => panel.child(grid),
1356- None => panel
1357- .child(self.message_area(entity, themed))
1358- .child(self.composer(entity, themed, cx)),
1359- },
1360- }
1361- }))
1362- .children(self.stats_side(palette)),
1363- ),
1361+ .child(div().flex_1().min_h_0().flex().child(
1362+ div().flex_1().min_w_0().flex().flex_col().map(|panel| {
1363+ match self.inline_viewer(entity, themed) {
1364+ Some(viewer) => panel.child(viewer),
1365+ None => match self.stage_grid(entity, themed) {
1366+ Some(grid) => panel.child(grid),
1367+ None => panel
1368+ .child(self.message_area(entity, themed))
1369+ .child(self.composer(entity, themed, cx)),
1370+ },
1371+ }
1372+ }),
1373+ )),
13641374 None => panel.child(empty_state(palette)),
13651375 },
13661376 })
1377+ .children(self.stats_sheet(palette))
13671378 .children(self.dock(entity, palette, cx))
13681379 }
13691380
1370- fn stats_side(&self, palette: Palette) -> Option<impl IntoElement> {
1371- (self.chat.stats_open && self.in_stage_chat()).then(|| {
1381+ fn stats_sheet(&self, palette: Palette) -> Option<impl IntoElement> {
1382+ (self.chat.stats_open && self.chat.voice_community().is_some()).then(|| {
13721383 div()
1373- .id("stats_side")
1374- .w(px(size::SHEET))
1375- .flex_shrink_0()
1376- .p(px(space::MD))
1377- .border_l_1()
1378- .border_color(palette.border)
1384+ .id("stats_sheet")
1385+ .absolute()
1386+ .right(px(space::LG))
1387+ .bottom(px(size::ROW + space::MD + space::SM))
1388+ .max_w(relative(0.95))
1389+ .max_h(relative(0.8))
13791390 .overflow_y_scroll()
1391+ .p(px(space::XL))
1392+ .rounded(px(radius::LG))
1393+ .border_1()
1394+ .border_color(palette.border)
1395+ .bg(palette.tokens.raise())
1396+ .shadow_lg()
13801397 .child(voice_stats::stats_panel(&self.chat, palette))
13811398 })
13821399 }
@@ -1835,6 +1852,12 @@ impl Yumush {
18351852 .users
18361853 .insert(member.user.id, member.user.clone());
18371854 }
1855+ style::remember(
1856+ &members
1857+ .iter()
1858+ .map(|member| &member.user)
1859+ .collect::<Vec<_>>(),
1860+ );
18381861 let old = std::mem::replace(&mut yumush.chat.members, members);
18391862 yumush
18401863 .chat
@@ -1864,6 +1887,7 @@ impl Yumush {
18641887 };
18651888 let _ = this.update(cx, |yumush, cx| {
18661889 yumush.request_user_avatar(&user, cx);
1890+ style::remember(&[&user]);
18671891 yumush.chat.users.insert(user.id, user);
18681892 cx.notify();
18691893 });
@@ -2662,88 +2686,84 @@ fn members_popover(entity: &Entity<Yumush>, yumush: &Yumush, palette: Palette) -
26622686 .content(move |_, _, _| {
26632687 let entity = entity.clone();
26642688
2665- pop_in(
2666- "members_list",
2667- div()
2668- .w(px(size::SIDEBAR))
2669- .p(px(space::XS))
2670- .flex()
2671- .flex_col()
2672- .rounded(px(radius::LG))
2673- .bg(palette.field)
2674- .children(members.iter().map(
2675- |MemberRow {
2676- user,
2677- rank,
2678- in_voice,
2679- muted,
2680- presence,
2681- }| {
2682- profile_popover(
2683- format!("member_{}", user.id),
2684- Anchor::TopRight,
2685- user,
2686- &entity,
2687- hoverable(
2688- format!("member_trigger_{}", user.id),
2689- div()
2690- .h(px(size::CONTROL))
2691- .px(px(space::SM))
2692- .flex()
2693- .items_center()
2694- .gap(px(space::SM))
2695- .rounded(px(radius::MD))
2696- .child(presence_avatar(
2697- avatar(
2698- palette,
2699- user,
2700- px(size::ICON),
2701- text(text::CAPTION),
2702- &avatars,
2703- ),
2704- *presence,
2705- px(size::ICON),
2689+ div()
2690+ .w(px(size::SIDEBAR))
2691+ .p(px(space::XS))
2692+ .flex()
2693+ .flex_col()
2694+ .rounded(px(radius::LG))
2695+ .bg(palette.field)
2696+ .children(members.iter().map(
2697+ |MemberRow {
2698+ user,
2699+ rank,
2700+ in_voice,
2701+ muted,
2702+ presence,
2703+ }| {
2704+ profile_popover(
2705+ format!("member_{}", user.id),
2706+ Anchor::TopRight,
2707+ user,
2708+ &entity,
2709+ hoverable(
2710+ format!("member_trigger_{}", user.id),
2711+ div()
2712+ .h(px(size::CONTROL))
2713+ .px(px(space::SM))
2714+ .flex()
2715+ .items_center()
2716+ .gap(px(space::SM))
2717+ .rounded(px(radius::MD))
2718+ .child(presence_avatar(
2719+ avatar(
27062720 palette,
2707- ))
2708- .child(
2709- div()
2710- .flex_1()
2711- .min_w_0()
2712- .flex()
2713- .flex_col()
2714- .child(
2715- div()
2716- .flex()
2717- .items_center()
2718- .gap(px(space::SM))
2719- .child(user.username.clone())
2720- .children(rank_tag(*rank, palette))
2721- .children(in_voice.then(|| {
2722- Icon::new(IconName::Headphones)
2723- .size(px(size::ICON_SM))
2724- .text_color(palette.muted)
2725- }))
2726- .children(muted.then(|| {
2727- Icon::new(IconName::MicOff)
2728- .size(px(size::ICON_SM))
2729- .text_color(palette.danger)
2730- })),
2731- )
2732- .children((!user.status.is_empty()).then(|| {
2733- div()
2734- .text_size(text(text::CAPTION))
2735- .text_color(palette.muted)
2736- .truncate()
2737- .child(user.status.clone())
2738- })),
2721+ user,
2722+ px(size::ICON),
2723+ text(text::CAPTION),
2724+ &avatars,
27392725 ),
2740- palette,
2741- ),
2742- )
2743- },
2744- )),
2745- Anchor::TopRight,
2746- )
2726+ *presence,
2727+ px(size::ICON),
2728+ palette,
2729+ ))
2730+ .child(
2731+ div()
2732+ .flex_1()
2733+ .min_w_0()
2734+ .flex()
2735+ .flex_col()
2736+ .child(
2737+ div()
2738+ .flex()
2739+ .items_center()
2740+ .gap(px(space::SM))
2741+ .child(user.username.clone())
2742+ .children(rank_tag(*rank, palette))
2743+ .children(in_voice.then(|| {
2744+ Icon::new(IconName::Headphones)
2745+ .size(px(size::ICON_SM))
2746+ .text_color(palette.muted)
2747+ }))
2748+ .children(muted.then(|| {
2749+ Icon::new(IconName::MicOff)
2750+ .size(px(size::ICON_SM))
2751+ .text_color(palette.danger)
2752+ })),
2753+ )
2754+ .children((!user.status.is_empty()).then(|| {
2755+ div()
2756+ .text_size(text(text::CAPTION))
2757+ .text_color(palette.muted)
2758+ .truncate()
2759+ .child(user.status.clone())
2760+ })),
2761+ ),
2762+ palette,
2763+ ),
2764+ )
2765+ },
2766+ ))
27472767 })
27482768 }
27492769
crates/client/src/gui/composer.rsmodified+157 -173
@@ -33,7 +33,7 @@ use gpui_kit::{
3333 use super::{
3434 Palette, Trigger, Yumush,
3535 chat::{Chat, TYPING_SEND_INTERVAL},
36- clickable, hoverable, new_input, notify_error, pop_in, primary_button,
36+ clickable, hoverable, new_input, notify_error, primary_button,
3737 };
3838
3939 actions!(composer, [Bold, Italic, Code, Strike]);
@@ -550,35 +550,31 @@ pub fn format_popover(palette: Palette) -> impl IntoElement {
550550 palette,
551551 ))
552552 .content(move |_, _, _| {
553- pop_in(
554- "format_list",
555- panel(palette)
556- .w(px(size::SHEET))
557- .p(px(space::SM))
558- .flex()
559- .flex_col()
560- .gap(px(space::SM))
561- .text_size(text(text::CAPTION))
562- .children(FORMAT_ROWS.map(|(syntax, shortcut)| {
563- div()
564- .flex()
565- .items_center()
566- .gap(px(space::MD))
567- .child(
568- div()
569- .w(px(size::THUMB))
570- .text_color(palette.muted)
571- .child(syntax),
572- )
573- .child(div().flex_1().child(TextView::markdown(syntax, syntax)))
574- .child(
575- div()
576- .text_color(palette.muted)
577- .child(shortcut_label(shortcut)),
578- )
579- })),
580- Anchor::BottomLeft,
581- )
553+ panel(palette)
554+ .w(px(size::SHEET))
555+ .p(px(space::SM))
556+ .flex()
557+ .flex_col()
558+ .gap(px(space::SM))
559+ .text_size(text(text::CAPTION))
560+ .children(FORMAT_ROWS.map(|(syntax, shortcut)| {
561+ div()
562+ .flex()
563+ .items_center()
564+ .gap(px(space::MD))
565+ .child(
566+ div()
567+ .w(px(size::THUMB))
568+ .text_color(palette.muted)
569+ .child(syntax),
570+ )
571+ .child(div().flex_1().child(TextView::markdown(syntax, syntax)))
572+ .child(
573+ div()
574+ .text_color(palette.muted)
575+ .child(shortcut_label(shortcut)),
576+ )
577+ }))
582578 })
583579 }
584580
@@ -645,160 +641,148 @@ pub fn plus_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> i
645641 if entity.read(cx).chat.plus_menu == PlusMenu::Menu {
646642 let file = entity.clone();
647643 let poll = entity.clone();
648- return pop_in(
649- "plus_menu",
650- panel(palette)
651- .w(px(size::SIDEBAR))
652- .p(px(space::XS))
653- .flex()
654- .flex_col()
655- .gap(px(space::XS))
656- .child(plus_row(
657- "plus_file",
658- IconName::File,
659- "File",
660- palette,
661- move |window, cx| {
662- popover.update(cx, |state, cx| state.dismiss(window, cx));
663- file.update(cx, |yumush, cx| yumush.attach_files(window, cx));
664- },
665- ))
666- .child(plus_row(
667- "plus_poll",
668- IconName::ChartBar,
669- "Poll",
670- palette,
671- move |_, cx| {
672- poll.update(cx, |yumush, cx| {
673- yumush.chat.plus_menu = PlusMenu::Poll;
674- cx.notify();
675- })
676- },
677- )),
678- Anchor::BottomLeft,
679- )
680- .into_any_element();
644+ return panel(palette)
645+ .w(px(size::SIDEBAR))
646+ .p(px(space::XS))
647+ .flex()
648+ .flex_col()
649+ .gap(px(space::XS))
650+ .child(plus_row(
651+ "plus_file",
652+ IconName::File,
653+ "File",
654+ palette,
655+ move |window, cx| {
656+ popover.update(cx, |state, cx| state.dismiss(window, cx));
657+ file.update(cx, |yumush, cx| yumush.attach_files(window, cx));
658+ },
659+ ))
660+ .child(plus_row(
661+ "plus_poll",
662+ IconName::ChartBar,
663+ "Poll",
664+ palette,
665+ move |_, cx| {
666+ poll.update(cx, |yumush, cx| {
667+ yumush.chat.plus_menu = PlusMenu::Poll;
668+ cx.notify();
669+ })
670+ },
671+ ))
672+ .into_any_element();
681673 }
682674 let toggle = entity.clone();
683675 let toggle_public = entity.clone();
684676 let duration_entity = entity.clone();
685677 let submit = entity.clone();
686- pop_in(
687- "poll_form",
688- panel(palette)
689- .w(px(size::POPOVER))
690- .p(px(space::SM))
691- .flex()
692- .flex_col()
693- .gap(px(space::SM))
694- .text_size(text(text::CAPTION))
695- .child(compact_field(palette, &question))
696- .children(options.iter().enumerate().map(|(index, option)| {
697- let remove = entity.clone();
698- let trailing_blank =
699- index + 1 == options.len() && option_text(option, cx).is_empty();
678+ panel(palette)
679+ .w(px(size::POPOVER))
680+ .p(px(space::SM))
681+ .flex()
682+ .flex_col()
683+ .gap(px(space::SM))
684+ .text_size(text(text::CAPTION))
685+ .child(compact_field(palette, &question))
686+ .children(options.iter().enumerate().map(|(index, option)| {
687+ let remove = entity.clone();
688+ let trailing_blank =
689+ index + 1 == options.len() && option_text(option, cx).is_empty();
690+ div()
691+ .flex()
692+ .items_center()
693+ .gap(px(space::SM))
694+ .child(
695+ div()
696+ .flex_1()
697+ .min_w_0()
698+ .child(compact_field(palette, option)),
699+ )
700+ .children(
701+ (options.len() > MINIMUM_POLL_OPTIONS && !trailing_blank).then(|| {
702+ icon_button(
703+ format!("poll_remove_{index}"),
704+ palette,
705+ IconName::Close,
706+ "Remove option",
707+ move |_, cx| {
708+ remove.update(cx, |yumush, cx| {
709+ yumush.remove_poll_option(index, cx)
710+ });
711+ },
712+ )
713+ }),
714+ )
715+ }))
716+ .child(
717+ div()
718+ .flex()
719+ .items_center()
720+ .gap(px(space::XS))
721+ .text_color(palette.muted)
722+ .child(Icon::new(IconName::Timer).size(px(size::ICON_SM)))
723+ .children(POLL_DURATIONS.map(|(label, seconds)| {
724+ let set = duration_entity.clone();
725+ let active = duration == seconds;
726+ clickable(label, palette, move |_, cx| {
727+ set.update(cx, |yumush, cx| {
728+ yumush.chat.poll_duration = seconds;
729+ cx.notify();
730+ })
731+ })
732+ .px(px(space::SM))
733+ .py(px(space::XXS))
734+ .rounded(px(radius::SM))
735+ .text_color(if active {
736+ palette.accent
737+ } else {
738+ palette.muted
739+ })
740+ .when(active, |this| this.bg(palette.tokens.press()))
741+ .child(label)
742+ })),
743+ )
744+ .child(
745+ div().flex().items_center().justify_between().child(
700746 div()
701747 .flex()
702748 .items_center()
703- .gap(px(space::SM))
749+ .gap(px(space::MD))
704750 .child(
705- div()
706- .flex_1()
707- .min_w_0()
708- .child(compact_field(palette, option)),
709- )
710- .children(
711- (options.len() > MINIMUM_POLL_OPTIONS && !trailing_blank).then(
712- || {
713- icon_button(
714- format!("poll_remove_{index}"),
715- palette,
716- IconName::Close,
717- "Remove option",
718- move |_, cx| {
719- remove.update(cx, |yumush, cx| {
720- yumush.remove_poll_option(index, cx)
721- });
722- },
723- )
724- },
725- ),
751+ Checkbox::new("poll_multiple")
752+ .label("Multiple answers")
753+ .checked(multiple)
754+ .on_click(move |_, _, cx| {
755+ toggle.update(cx, |yumush, cx| {
756+ yumush.chat.poll_multiple = !yumush.chat.poll_multiple;
757+ cx.notify();
758+ })
759+ }),
726760 )
727- }))
728- .child(
729- div()
730- .flex()
731- .items_center()
732- .gap(px(space::XS))
733- .text_color(palette.muted)
734- .child(Icon::new(IconName::Timer).size(px(size::ICON_SM)))
735- .children(POLL_DURATIONS.map(|(label, seconds)| {
736- let set = duration_entity.clone();
737- let active = duration == seconds;
738- clickable(label, palette, move |_, cx| {
739- set.update(cx, |yumush, cx| {
740- yumush.chat.poll_duration = seconds;
741- cx.notify();
742- })
743- })
744- .px(px(space::SM))
745- .py(px(space::XXS))
746- .rounded(px(radius::SM))
747- .text_color(if active {
748- palette.accent
749- } else {
750- palette.muted
751- })
752- .when(active, |this| this.bg(palette.tokens.press()))
753- .child(label)
754- })),
755- )
756- .child(
757- div().flex().items_center().justify_between().child(
758- div()
759- .flex()
760- .items_center()
761- .gap(px(space::MD))
762- .child(
763- Checkbox::new("poll_multiple")
764- .label("Multiple answers")
765- .checked(multiple)
766- .on_click(move |_, _, cx| {
767- toggle.update(cx, |yumush, cx| {
768- yumush.chat.poll_multiple =
769- !yumush.chat.poll_multiple;
770- cx.notify();
771- })
772- }),
773- )
774- .child(
775- Checkbox::new("poll_public")
776- .label("Show voters")
777- .checked(public)
778- .on_click(move |_, _, cx| {
779- toggle_public.update(cx, |yumush, cx| {
780- yumush.toggle_poll_public(cx)
781- })
782- }),
783- ),
784- ),
785- )
786- .child(
787- primary_button("poll_create", palette, move |window, cx| {
788- if submit.update(cx, |yumush, cx| yumush.send_poll(window, cx)) {
789- popover.update(cx, |state, cx| state.dismiss(window, cx));
790- }
791- })
792- .h(px(size::CONTROL_SM))
793- .flex()
794- .items_center()
795- .justify_center()
796- .rounded(px(radius::MD))
797- .child("Create"),
761+ .child(
762+ Checkbox::new("poll_public")
763+ .label("Show voters")
764+ .checked(public)
765+ .on_click(move |_, _, cx| {
766+ toggle_public
767+ .update(cx, |yumush, cx| yumush.toggle_poll_public(cx))
768+ }),
769+ ),
798770 ),
799- Anchor::BottomLeft,
800- )
801- .into_any_element()
771+ )
772+ .child(
773+ primary_button("poll_create", palette, move |window, cx| {
774+ if submit.update(cx, |yumush, cx| yumush.send_poll(window, cx)) {
775+ popover.update(cx, |state, cx| state.dismiss(window, cx));
776+ }
777+ })
778+ .h(px(size::CONTROL_SM))
779+ .flex()
780+ .items_center()
781+ .justify_center()
782+ .rounded(px(radius::MD))
783+ .child("Create"),
784+ )
785+ .into_any_element()
802786 })
803787 }
804788
crates/client/src/gui/message_actions.rsmodified+58 -75
@@ -24,7 +24,7 @@ use super::{
2424 chat::{Chat, ReportTarget},
2525 clickable,
2626 composer::trigger_icon,
27- entity_action, millis_time, notify_error, pop_in, primary_button, sidebar,
27+ entity_action, millis_time, notify_error, primary_button, sidebar,
2828 style::{radius, size, space, text},
2929 widget::{field, icon_button, panel, spawn_done},
3030 };
@@ -99,40 +99,31 @@ pub fn react_popover(
9999 ))
100100 .content(move |_, _, cx| {
101101 let popover = cx.entity();
102- pop_in(
103- "react_list",
104- panel(palette)
102+ panel(palette)
103+ .flex()
104+ .gap(px(space::XXS))
105+ .p(px(space::XS))
106+ .children(REACTIONS.map(|emoji| {
107+ let entity = entity.clone();
108+ let popover = popover.clone();
109+ clickable(
110+ format!("react_{emoji}_{message_id}"),
111+ palette,
112+ move |window, cx| {
113+ popover.update(cx, |state, cx| state.dismiss(window, cx));
114+ entity.update(cx, |yumush, cx| {
115+ yumush.toggle_reaction(message_id, emoji.to_string(), window, cx)
116+ });
117+ },
118+ )
119+ .size(px(size::CONTROL_SM))
105120 .flex()
106- .gap(px(space::XXS))
107- .p(px(space::XS))
108- .children(REACTIONS.map(|emoji| {
109- let entity = entity.clone();
110- let popover = popover.clone();
111- clickable(
112- format!("react_{emoji}_{message_id}"),
113- palette,
114- move |window, cx| {
115- popover.update(cx, |state, cx| state.dismiss(window, cx));
116- entity.update(cx, |yumush, cx| {
117- yumush.toggle_reaction(
118- message_id,
119- emoji.to_string(),
120- window,
121- cx,
122- )
123- });
124- },
125- )
126- .size(px(size::CONTROL_SM))
127- .flex()
128- .items_center()
129- .justify_center()
130- .rounded(px(radius::MD))
131- .text_size(text(text::BODY))
132- .child(emoji)
133- })),
134- Anchor::TopRight,
135- )
121+ .items_center()
122+ .justify_center()
123+ .rounded(px(radius::MD))
124+ .text_size(text(text::BODY))
125+ .child(emoji)
126+ }))
136127 })
137128 }
138129
@@ -295,27 +286,23 @@ pub fn search_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) ->
295286 ))
296287 .content(move |_, _, cx| {
297288 let popover = cx.entity();
298- pop_in(
299- "search_list",
300- panel(palette)
301- .w(px(size::POPOVER))
302- .p(px(space::XS))
303- .flex()
304- .flex_col()
305- .gap(px(space::XS))
306- .child(sidebar::input_box(&input, palette))
307- .children(hits.iter().map(|hit| {
308- jump_row("search_hit", hit, &entity, &popover, palette)
309- .children(hit.time.as_ref().map(|time| {
310- div()
311- .flex_shrink_0()
312- .text_color(palette.muted)
313- .child(time.clone())
314- }))
315- .child(div().flex_1().min_w_0().truncate().child(hit.body.clone()))
316- })),
317- Anchor::TopRight,
318- )
289+ panel(palette)
290+ .w(px(size::POPOVER))
291+ .p(px(space::XS))
292+ .flex()
293+ .flex_col()
294+ .gap(px(space::XS))
295+ .child(sidebar::input_box(&input, palette))
296+ .children(hits.iter().map(|hit| {
297+ jump_row("search_hit", hit, &entity, &popover, palette)
298+ .children(hit.time.as_ref().map(|time| {
299+ div()
300+ .flex_shrink_0()
301+ .text_color(palette.muted)
302+ .child(time.clone())
303+ }))
304+ .child(div().flex_1().min_w_0().truncate().child(hit.body.clone()))
305+ }))
319306 })
320307 }
321308
@@ -341,26 +328,22 @@ pub fn pins_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> i
341328 .trigger(trigger_icon("pins_trigger", IconName::Pin, 24., palette))
342329 .content(move |_, _, cx| {
343330 let popover = cx.entity();
344- pop_in(
345- "pins_list",
346- panel(palette)
347- .w(px(size::POPOVER))
348- .p(px(space::XS))
349- .flex()
350- .flex_col()
351- .gap(px(space::XXS))
352- .children(pins.iter().map(|hit| {
353- jump_row("pin_hit", hit, &entity, &popover, palette).child(
354- div()
355- .flex_1()
356- .min_w_0()
357- .truncate()
358- .text_color(palette.muted)
359- .child(hit.body.clone()),
360- )
361- })),
362- Anchor::TopRight,
363- )
331+ panel(palette)
332+ .w(px(size::POPOVER))
333+ .p(px(space::XS))
334+ .flex()
335+ .flex_col()
336+ .gap(px(space::XXS))
337+ .children(pins.iter().map(|hit| {
338+ jump_row("pin_hit", hit, &entity, &popover, palette).child(
339+ div()
340+ .flex_1()
341+ .min_w_0()
342+ .truncate()
343+ .text_color(palette.muted)
344+ .child(hit.body.clone()),
345+ )
346+ }))
364347 })
365348 }
366349
crates/client/src/gui/parts.rsmodified+0 -32
@@ -413,38 +413,6 @@ pub fn spark(values: Vec<f32>, slots: usize, color: Hsla) -> AnyElement {
413413 super::wave::line_of(values, slots, color).into_any_element()
414414 }
415415
416-const MOTION_TRAVEL: f32 = 6.;
417-
418416 pub fn motion() -> gpui_kit::Animation {
419417 gpui_kit::Animation::new(Duration::from_millis(160)).with_easing(gpui_kit::ease_out_quint())
420418 }
421-
422-pub fn pop_in<E: IntoElement + Styled + 'static>(
423- id: impl Into<ElementId>,
424- element: E,
425- anchor: gpui_kit::Anchor,
426-) -> gpui_kit::AnimationElement<E> {
427- let travel = if anchor.is_bottom() {
428- MOTION_TRAVEL
429- } else {
430- -MOTION_TRAVEL
431- };
432- gpui_kit::AnimationExt::with_animation(element, id, motion(), move |element, delta| {
433- element.top(px(travel * (1. - delta))).opacity(delta)
434- })
435-}
436-
437-pub fn swap_in<E: IntoElement + Styled + 'static>(
438- id: impl Into<ElementId>,
439- element: E,
440- forward: bool,
441-) -> gpui_kit::AnimationElement<E> {
442- let travel = if forward {
443- MOTION_TRAVEL
444- } else {
445- -MOTION_TRAVEL
446- };
447- gpui_kit::AnimationExt::with_animation(element, id, motion(), move |element, delta| {
448- element.left(px(travel * (1. - delta))).opacity(delta)
449- })
450-}
crates/client/src/gui/poll.rsmodified+10 -14
@@ -11,7 +11,7 @@ use gpui_kit::{
1111 use super::{
1212 Palette, Tooltip as _, Trigger, Yumush, avatar,
1313 chat::Chat,
14- clickable, hoverable, pop_in,
14+ clickable, hoverable,
1515 style::{radius, size, space, text},
1616 text,
1717 widget::{icon_button, panel, spawn_done},
@@ -143,19 +143,15 @@ fn voters_popover(key: &str, poll: &Poll, entity: &Entity<Yumush>, palette: Pale
143143 })
144144 }))
145145 });
146- pop_in(
147- list.clone(),
148- panel(palette)
149- .w(px(size::SIDEBAR))
150- .id(list.clone())
151- .max_h(px(size::POPOVER))
152- .overflow_y_scroll()
153- .p(px(space::SM))
154- .flex()
155- .flex_col()
156- .children(rows),
157- Anchor::BottomLeft,
158- )
146+ panel(palette)
147+ .w(px(size::SIDEBAR))
148+ .id(list.clone())
149+ .max_h(px(size::POPOVER))
150+ .overflow_y_scroll()
151+ .p(px(space::SM))
152+ .flex()
153+ .flex_col()
154+ .children(rows)
159155 })
160156 .into_any_element()
161157 }
crates/client/src/gui/profile.rsmodified+3 -11
@@ -27,7 +27,7 @@ use super::style::{radius, size, space, stroke, text};
2727 use super::widget::{panel, spawn_done};
2828 use super::{
2929 DAY_YEAR, Palette, Trigger, Yumush, avatar, clickable, entity_action, input_dialog,
30- millis_time, notify_error, palette, pop_in, presence_color, rank_tag, swap_in, text,
30+ millis_time, notify_error, palette, presence_color, rank_tag, text,
3131 };
3232
3333 const ACCOUNTS_MAX_H: f32 = 180.;
@@ -117,11 +117,7 @@ pub(super) fn profile_popover(
117117 user: user.clone(),
118118 };
119119
120- pop_in(
121- "profile_card",
122- card.render(&entity, cx.entity(), palette(cx), &yumush.chat.avatars),
123- anchor,
124- )
120+ card.render(&entity, cx.entity(), palette(cx), &yumush.chat.avatars)
125121 })
126122 }
127123
@@ -302,11 +298,7 @@ impl Card {
302298 .then(|| report_bar(&self.reason, entity, palette)),
303299 )
304300 .children(divider)
305- .child(swap_in(
306- ("profile_rows", self.card_menu as usize),
307- div().flex().flex_col().gap(px(space::MD)).children(rows),
308- self.card_menu != CardMenu::Main,
309- ))
301+ .child(div().flex().flex_col().gap(px(space::MD)).children(rows))
310302 }
311303
312304 fn moderation_rows(
crates/client/src/gui/settings_page.rsmodified+49 -3
@@ -2,8 +2,8 @@ use std::future::Future;
22
33 use crate::net::Fail;
44 use common::{
5- call::{DeleteUser, RemoveAvatar, UpdateAvatar, UpdateStatus, UpdateUser},
6- model::User,
5+ call::{DeleteUser, RemoveAvatar, UpdateAvatar, UpdateHue, UpdateStatus, UpdateUser},
6+ model::{Hue, User},
77 };
88 use gpui_kit::{
99 AnyElement, App, AsyncWindowContext, Context, Div, Entity, FontWeight, Hsla,
@@ -21,7 +21,7 @@ use super::{
2121 primary_button, text, widget::field,
2222 };
2323 use crate::{
24- gui::style::{Theme, radius, size, space, stroke, text},
24+ gui::style::{self, Theme, radius, size, space, stroke, text},
2525 settings::{self, FontSize},
2626 };
2727
@@ -107,6 +107,14 @@ impl Yumush {
107107 Yumush::set_theme,
108108 ),
109109 ),
110+ row(
111+ "Your hue",
112+ hue_picker(
113+ self.user.as_ref().map(|user| style::hue_of(user.id)),
114+ entity,
115+ palette,
116+ ),
117+ ),
110118 row(
111119 "Font size",
112120 segmented(
@@ -180,6 +188,16 @@ impl Yumush {
180188 .detach();
181189 }
182190
191+ pub(super) fn save_hue(&mut self, hue: Hue, window: &mut Window, cx: &mut Context<Self>) {
192+ let network = self.network.clone();
193+
194+ cx.spawn_in(window, async move |this, cx| {
195+ let result = network.call(UpdateHue { hue: Some(hue) }).await;
196+ apply_user(&this, cx, result);
197+ })
198+ .detach();
199+ }
200+
183201 pub(super) fn save_status(&mut self, window: &mut Window, cx: &mut Context<Self>) {
184202 let status = self.chat.status_input.read(cx).text().to_string();
185203 let network = self.network.clone();
@@ -280,6 +298,34 @@ fn apply_user(this: &WeakEntity<Yumush>, cx: &mut AsyncWindowContext, result: Re
280298 }
281299 }
282300
301+fn hue_picker(current: Option<Hue>, entity: &Entity<Yumush>, palette: Palette) -> Div {
302+ let t = palette.tokens;
303+ div()
304+ .flex()
305+ .items_center()
306+ .gap(px(space::XS))
307+ .children(style::PICKS.iter().map(|&hue| {
308+ let entity = entity.clone();
309+ let on = current == Some(hue);
310+ div()
311+ .id(hue.as_str())
312+ .flex()
313+ .items_center()
314+ .h(px(size::CONTROL_SM))
315+ .px(px(space::XS))
316+ .cursor_pointer()
317+ .child(
318+ div()
319+ .w(px(size::CHIP))
320+ .h(px(if on { stroke::LINE * 2. } else { stroke::LINE }))
321+ .bg(t.hue(hue)),
322+ )
323+ .on_click(move |_, window, cx| {
324+ entity.update(cx, |yumush, cx| yumush.save_hue(hue, window, cx))
325+ })
326+ }))
327+}
328+
283329 pub(super) fn picked_avatar(
284330 cx: &App,
285331 maximum: u64,
crates/client/src/gui/share_view.rsmodified+2 -6
@@ -34,7 +34,7 @@ use super::{
3434 chat::View,
3535 clickable, entity_action,
3636 media_view::into_render_image,
37- notify_error, pop_in,
37+ notify_error,
3838 settings_page::segmented,
3939 stream_stats::{stream_card, watch_stats},
4040 style::{radius, size, space, text},
@@ -504,11 +504,7 @@ impl Yumush {
504504 ))
505505 .content(move |_, _, cx| {
506506 let entity = settings.clone();
507- pop_in(
508- "share_settings_card",
509- settings_card(&entity, entity.read(cx), palette),
510- Anchor::BottomRight,
511- )
507+ settings_card(&entity, entity.read(cx), palette)
512508 })
513509 }
514510
crates/client/src/gui/sidebar.rsmodified+12 -11
@@ -48,14 +48,19 @@ impl Yumush {
4848 self.expanded_sidebar(entity, palette)
4949 };
5050
51- div()
51+ let sidebar = div()
5252 .h_full()
5353 .flex_shrink_0()
5454 .overflow_hidden()
55- .child(content)
56- .with_animation(id, motion(), move |sidebar, delta| {
57- sidebar.w(px(from + (to - from) * delta))
58- })
55+ .child(content);
56+ match self.chat.sidebar_toggled {
57+ Some(at) if at.elapsed() < motion().duration => sidebar
58+ .with_animation(id, motion(), move |sidebar, delta| {
59+ sidebar.w(px(from + (to - from) * delta))
60+ })
61+ .into_any_element(),
62+ _ => sidebar.w(px(to)).into_any_element(),
63+ }
5964 }
6065
6166 fn collapsed_sidebar(&self, entity: &Entity<Self>, palette: Palette) -> Div {
@@ -371,6 +376,7 @@ impl Yumush {
371376 tip,
372377 entity_action(entity, |yumush, _, cx| {
373378 yumush.chat.sidebar_collapsed = !yumush.chat.sidebar_collapsed;
379+ yumush.chat.sidebar_toggled = Some(std::time::Instant::now());
374380 cx.notify();
375381 }),
376382 )
@@ -413,12 +419,7 @@ impl Yumush {
413419 .gap(px(space::XL))
414420 .child(input_box(&self.chat.search_input, palette))
415421 .children(found.map(|user| self.found_row(entity, user, palette)))
416- .children(
417- query
418- .is_empty()
419- .then(|| self.requests(entity, palette))
420- .flatten(),
421- )
422+ .children(self.requests(entity, palette))
422423 .children(group(
423424 "Friends",
424425 palette,
crates/client/src/gui/snippet.rsmodified+1 -0
@@ -55,6 +55,7 @@ fn snippet_row(
5555 username: item.username.clone(),
5656 role: Role::User,
5757 status: String::new(),
58+ hue: None,
5859 avatar_id: item.avatar_id,
5960 created_at: item.created_at,
6061 });
crates/client/src/gui/social.rsmodified+8 -0
@@ -142,6 +142,14 @@ impl Yumush {
142142 };
143143
144144 let _ = this.update(cx, |yumush, cx| {
145+ super::style::remember(
146+ &friends
147+ .friends
148+ .iter()
149+ .chain(&friends.incoming)
150+ .chain(&friends.outgoing)
151+ .collect::<Vec<_>>(),
152+ );
145153 yumush.chat.friends = friends;
146154 yumush.chat.invitations = invitations;
147155 yumush.chat.presences = presences.into_iter().collect();
crates/client/src/gui/style.rsmodified+22 -6
@@ -1,6 +1,6 @@
1-use std::hash::{DefaultHasher, Hash, Hasher};
1+use std::{cell::RefCell, collections::HashMap};
22
3-use common::model::{Hue, Id};
3+use common::model::{Hue, Id, User};
44 use gpui_kit::{App, Global, Hsla, Rems, rems, rgb};
55
66 use crate::settings::FontSize;
@@ -104,11 +104,27 @@ impl Tokens {
104104 }
105105 }
106106
107+pub const PICKS: &[Hue] = Hue::ALL.split_last().unwrap().1;
108+
109+thread_local! {
110+ static CHOSEN: RefCell<HashMap<Id, Hue>> = RefCell::default();
111+}
112+
113+pub fn remember(users: &[&User]) {
114+ CHOSEN.with_borrow_mut(|chosen| {
115+ for user in users {
116+ match user.hue {
117+ Some(hue) => chosen.insert(user.id, hue),
118+ None => chosen.remove(&user.id),
119+ };
120+ }
121+ });
122+}
123+
107124 pub fn hue_of(id: Id) -> Hue {
108- let mut hasher = DefaultHasher::new();
109- id.hash(&mut hasher);
110- let picks = &Hue::ALL[..Hue::ALL.len() - 1];
111- picks[hasher.finish() as usize % picks.len()]
125+ CHOSEN
126+ .with_borrow(|chosen| chosen.get(&id).copied())
127+ .unwrap_or(PICKS[id.rem_euclid(PICKS.len() as Id) as usize])
112128 }
113129
114130 fn color(value: u32) -> Hsla {
crates/client/src/gui/voice_stats.rsmodified+348 -573
@@ -1,32 +1,26 @@
11 use std::collections::VecDeque;
22
33 use common::{
4- model::{Hue, Id},
4+ model::Id,
55 share::{Kind, Layer},
66 };
7-use gpui_kit::{
8- Div, FontWeight, Hsla, ParentElement, Styled, assets::IconName, component::Icon, div,
9- prelude::FluentBuilder as _, px, relative,
10-};
7+use gpui_kit::{AnyElement, Div, FontWeight, Hsla, IntoElement, ParentElement, Styled, div, px};
118
129 use super::{
1310 Palette,
1411 chat::Chat,
15- share_view::kind_icon,
16- style::{radius, size, space, stroke, text},
17- text as text_size, wave,
12+ parts::{Fill, Ink, Text, band, grow, spark, stack, track, words},
13+ style::{Tokens, size, space},
1814 };
1915 use crate::media::decode::Engine;
2016 use crate::share::session::{LayerStats, WatchStats};
21-use crate::usage::{Gpu, Usage};
17+use crate::usage::Usage;
2218 use crate::voice::VoiceSample;
2319
2420 pub const SAMPLE_HISTORY: usize = 60;
25-const MIRROR_HALF: f32 = size::CHIP;
26-const LAYER_W: f32 = 70.;
27-const WATCH_LAYER_W: f32 = 64.;
28-const RATE_W: f32 = 52.;
29-const VALUE_W: f32 = 76.;
21+const LABEL_W: f32 = size::ROW * 2.;
22+const VALUE_W: f32 = size::THUMB;
23+const COLUMN_W: f32 = size::TALK + size::ROW * 2.;
3024 const PING_SCALE: f32 = 150.;
3125 const GOOD_LOSS: f32 = 2.;
3226 const FAIR_LOSS: f32 = 8.;
@@ -68,14 +62,6 @@ impl Quality {
6862 Self::Poor => "poor",
6963 }
7064 }
71-
72- pub fn color(self, palette: Palette) -> Hsla {
73- match self {
74- Self::Good => palette.ok,
75- Self::Fair => palette.tokens.hue(Hue::Gold),
76- Self::Poor => palette.danger,
77- }
78- }
7965 }
8066
8167 pub fn quality(samples: &VecDeque<VoiceSample>) -> Option<Quality> {
@@ -83,487 +69,386 @@ pub fn quality(samples: &VecDeque<VoiceSample>) -> Option<Quality> {
8369 }
8470
8571 pub fn stats_panel(chat: &Chat, palette: Palette) -> Div {
72+ let t = palette.tokens;
8673 let share = &chat.share_sample;
87- div()
88- .flex()
89- .flex_col()
90- .gap(px(space::LG))
91- .child(network_block(chat, palette))
92- .children(sending_blocks(&share.sending, palette))
93- .child(receiving_block(&share.watching, chat, palette))
94- .children(chat.usage.as_ref().map(|usage| usage_block(usage, palette)))
95-}
96-
97-fn network_block(chat: &Chat, palette: Palette) -> Div {
98- let latest = chat.voice_samples.back();
99- let color = latest.map_or(palette.ok, |sample| Quality::of(sample).color(palette));
100- let word = latest.map_or("…", |sample| Quality::of(sample).word());
101- let ping = latest.map_or("…".into(), |sample| format!("{:.0} ms", sample.ping_ms));
102- let jitter = latest.map_or("…".into(), |sample| {
103- format!("{:.0} ms", sample.traffic.jitter_ms)
104- });
105- let loss = latest.map_or("…".into(), |sample| {
106- format!("{:.1} %", sample.traffic.loss * 100.)
107- });
108- let buffer = latest.map_or("…".into(), |sample| {
109- format!("{:.0} ms", sample.traffic.buffer_ms)
110- });
111-
112- div()
113- .flex()
114- .flex_col()
115- .gap(px(space::SM))
116- .child(header(IconName::Activity, "Network", color).child(chip(word, color, palette)))
74+ band(space::XXL)
75+ .items_start()
76+ .flex_wrap()
11777 .child(
118- div()
119- .flex()
120- .gap(px(space::SM))
121- .child(stat_cell("ping", ping, color, palette))
122- .child(stat_cell("jitter", jitter, color, palette))
123- .child(stat_cell("loss", loss, color, palette))
124- .child(stat_cell("buffer", buffer, palette.text, palette)),
78+ stack(space::XL)
79+ .w(px(COLUMN_W))
80+ .child(connection(chat, t))
81+ .child(traffic(chat, t))
82+ .children(chat.usage.as_ref().map(|usage| machine(usage, t))),
12583 )
12684 .child(
127- div()
128- .h(px(size::CONTROL))
129- .p(px(space::XXS))
130- .rounded(px(radius::SM))
131- .bg(palette.window)
132- .child(wave::line(
133- chat.voice_samples
134- .iter()
135- .map(|sample| (sample.ping_ms / PING_SCALE).clamp(0., 1.))
136- .collect(),
137- color,
138- )),
85+ stack(space::XL)
86+ .w(px(COLUMN_W))
87+ .children(sending(&share.sending, t))
88+ .children(watching(&share.watching, chat, t)),
13989 )
140- .child(traffic(chat, palette))
14190 }
14291
143-fn traffic(chat: &Chat, palette: Palette) -> Div {
144- let up: Vec<f32> = chat.traffic.iter().map(|(up, _)| *up).collect();
145- let down: Vec<f32> = chat.traffic.iter().map(|(_, down)| *down).collect();
146- let up_latest = up.last().copied().unwrap_or_default();
147- let down_latest = down.last().copied().unwrap_or_default();
148- let max = up.iter().chain(&down).copied().fold(1., f32::max);
149-
150- div()
151- .flex()
152- .flex_col()
153- .gap(px(space::XXS))
154- .text_size(text_size(text::CAPTION))
92+fn title(name: &'static str, sub: String, trailing: Option<Div>, t: Tokens) -> Div {
93+ band(space::SM)
15594 .child(
156- div()
157- .text_color(up_color(palette))
158- .child(format!("↑ {}", rate(up_latest as u32))),
159- )
160- .child(
161- div()
162- .h(px(MIRROR_HALF * 2.))
163- .flex()
164- .flex_col()
165- .child(
166- div()
167- .h(px(MIRROR_HALF))
168- .flex()
169- .items_end()
170- .gap(px(space::XXS))
171- .children(bars(&up, max, up_color(palette))),
172- )
173- .child(div().h(px(stroke::LINE)).bg(palette.border))
174- .child(
175- div()
176- .h(px(MIRROR_HALF))
177- .flex()
178- .items_start()
179- .gap(px(space::XXS))
180- .children(bars(&down, max, down_color(palette))),
181- ),
182- )
183- .child(
184- div()
185- .text_color(down_color(palette))
186- .child(format!("↓ {}", rate(down_latest as u32))),
95+ words(name, Text::Label, Ink::Paper, t)
96+ .font_weight(FontWeight::MEDIUM)
97+ .flex_none(),
18798 )
99+ .child(words(sub, Text::Caption, Ink::Faint, t))
100+ .child(grow())
101+ .children(trailing)
188102 }
189103
190-fn bars(values: &[f32], max: f32, color: Hsla) -> Vec<Div> {
191- let empty = SAMPLE_HISTORY.saturating_sub(values.len());
192- (0..empty)
193- .map(|_| div().flex_1())
194- .chain(
195- values
196- .iter()
197- .map(|value| div().flex_1().h(px(value / max * MIRROR_HALF)).bg(color)),
104+fn line_row(label: AnyElement, fill: AnyElement, value: String, bad: bool, t: Tokens) -> Div {
105+ band(space::MD)
106+ .h(px(size::CONTROL_SM))
107+ .child(div().w(px(LABEL_W)).flex_none().min_w_0().child(label))
108+ .child(div().flex_1().min_w_0().child(fill))
109+ .child(
110+ words(
111+ value,
112+ Text::Label,
113+ if bad { Ink::Bad } else { Ink::Paper },
114+ t,
115+ )
116+ .w(px(VALUE_W))
117+ .flex_none()
118+ .text_right(),
198119 )
199- .collect()
200-}
201-
202-fn up_color(palette: Palette) -> Hsla {
203- palette.tokens.hue(Hue::Violet)
204120 }
205121
206-fn down_color(palette: Palette) -> Hsla {
207- palette.tokens.hue(Hue::Teal)
122+fn label(text: &'static str, t: Tokens) -> AnyElement {
123+ words(text, Text::Caption, Ink::Dim, t).into_any_element()
208124 }
209125
210-fn sending_blocks(sending: &[(Kind, LayerStats)], palette: Palette) -> Vec<Div> {
211- [Kind::Screen, Kind::Camera]
212- .into_iter()
213- .filter_map(|kind| {
214- let layers: Vec<&LayerStats> = sending
215- .iter()
216- .filter(|(sent, _)| *sent == kind)
217- .map(|(_, stats)| stats)
218- .collect();
219- (!layers.is_empty()).then(|| sending_block(kind, &layers, palette))
220- })
221- .collect()
222-}
223-
224-fn sending_block(kind: Kind, layers: &[&LayerStats], palette: Palette) -> Div {
225- let color = kind_color(kind, palette);
226- let max = largest(layers.iter().map(|stats| stats.kbps));
227- let engine = layers
228- .last()
229- .map_or("…", |stats| engine_label(stats.engine));
230- div()
231- .flex()
232- .flex_col()
233- .gap(px(space::SM))
234- .child(header(kind_icon(kind), kind_name(kind), color).child(label(engine, color)))
235- .children(
236- layers
237- .iter()
238- .enumerate()
239- .rev()
240- .map(|(index, stats)| layer_row(index, stats, max, kind, palette)),
241- )
242-}
243-
244-fn layer_row(index: usize, stats: &LayerStats, max: f32, kind: Kind, palette: Palette) -> Div {
245- let color = kind_color(kind, palette);
246- div()
247- .flex()
248- .items_center()
249- .gap(px(space::SM))
250- .h(px(size::CONTROL_SM))
251- .px(px(space::SM))
252- .rounded(px(radius::MD))
253- .bg(palette.hover)
254- .text_size(text_size(text::CAPTION))
255- .when(stats.kbps == 0, |this| {
256- this.text_color(palette.tokens.faint())
257- })
258- .child(
259- div()
260- .w(px(size::CHIP))
261- .flex_none()
262- .font_weight(FontWeight::SEMIBOLD)
263- .text_color(color)
264- .child(format!("L{index}")),
265- )
266- .child(
267- div()
268- .w(px(LAYER_W))
269- .flex_none()
270- .text_color(palette.text)
271- .child(resolution_text(stats.layer, stats.fps)),
272- )
273- .child(
274- div()
275- .w(px(size::CONTROL))
276- .flex_none()
277- .text_color(palette.muted)
278- .child(stats.layer.codec.name()),
279- )
280- .child(bar(stats.kbps as f32 / max, color, palette))
126+fn number(value: String, name: &'static str, bad: bool, t: Tokens) -> Div {
127+ stack(space::XXS)
128+ .flex_1()
281129 .child(
282- div()
283- .w(px(RATE_W))
284- .flex_none()
285- .text_right()
286- .text_color(palette.text)
287- .child(rate(stats.kbps)),
130+ words(
131+ value,
132+ Text::Title,
133+ if bad { Ink::Bad } else { Ink::Paper },
134+ t,
135+ )
136+ .font_weight(FontWeight::MEDIUM),
288137 )
138+ .child(words(name, Text::Caption, Ink::Faint, t))
289139 }
290140
291-fn receiving_block(watching: &[(Id, Kind, WatchStats)], chat: &Chat, palette: Palette) -> Div {
292- div()
293- .flex()
294- .flex_col()
295- .gap(px(space::XS))
296- .child(header(IconName::Eye, "Receiving", palette.text))
297- .children(
298- watching
299- .iter()
300- .map(|(user_id, kind, stats)| watch_row(chat, *user_id, *kind, stats, palette)),
141+fn connection(chat: &Chat, t: Tokens) -> Div {
142+ let latest = chat.voice_samples.back();
143+ let quality = latest.map(Quality::of);
144+ let bad = quality == Some(Quality::Poor);
145+ let field = |value: Option<String>| value.unwrap_or_else(|| "…".into());
146+ let ping = latest.map(|sample| sample.ping_ms);
147+ let loss = latest.map(|sample| sample.traffic.loss * 100.);
148+ let word = quality.map(|quality| {
149+ words(
150+ quality.word(),
151+ Text::Caption,
152+ if bad { Ink::Bad } else { Ink::Dim },
153+ t,
301154 )
302-}
155+ });
303156
304-fn watch_row(chat: &Chat, user_id: Id, kind: Kind, stats: &WatchStats, palette: Palette) -> Div {
305- let name = chat
306- .author(user_id)
307- .map_or_else(|| user_id.to_string(), |user| user.username.clone());
308- let color = palette.tinted(user_id);
309- let loss = stats.loss * 100.;
310- let loss_color = Quality::of_loss(loss).color(palette);
311- let latency = stats
312- .latency_ms
313- .map_or("…".to_string(), |ms| format!("{ms} ms"));
314- div()
315- .flex()
316- .items_center()
317- .gap(px(space::XS))
318- .h(px(size::CONTROL))
319- .px(px(space::SM))
320- .rounded(px(radius::MD))
321- .bg(palette.hover)
322- .text_size(text_size(text::CAPTION))
323- .child(avatar_dot(&name, color, palette))
324- .child(
325- div()
326- .flex_1()
327- .min_w_0()
328- .truncate()
329- .font_weight(FontWeight::SEMIBOLD)
330- .text_color(color)
331- .child(name),
332- )
333- .child(
334- Icon::new(kind_icon(kind))
335- .size(px(size::ICON_SM))
336- .flex_none()
337- .text_color(kind_color(kind, palette)),
338- )
339- .child(
340- div()
341- .w(px(WATCH_LAYER_W))
342- .flex_none()
343- .text_color(palette.text)
344- .child(
345- stats
346- .layer
347- .map_or("…".to_string(), |layer| resolution_text(layer, stats.fps)),
348- ),
349- )
157+ stack(space::MD)
158+ .child(title("Connection", String::new(), word, t))
350159 .child(
351- div()
352- .w(px(RATE_W))
353- .flex_none()
354- .text_color(palette.muted)
355- .child(format!(
356- "{} {}",
357- stats.layer.map_or("…", |layer| layer.codec.name()),
358- stats.engine.map_or("…", engine_label)
160+ band(space::LG)
161+ .child(number(
162+ field(ping.map(|ping| format!("{ping:.0}"))),
163+ "ping ms",
164+ ping.is_some_and(|ping| ping > PING_SCALE),
165+ t,
166+ ))
167+ .child(number(
168+ field(latest.map(|sample| format!("{:.0}", sample.traffic.jitter_ms))),
169+ "jitter ms",
170+ false,
171+ t,
172+ ))
173+ .child(number(
174+ field(loss.map(|loss| format!("{loss:.1}"))),
175+ "loss %",
176+ loss.is_some_and(|loss| loss > GOOD_LOSS),
177+ t,
178+ ))
179+ .child(number(
180+ field(latest.map(|sample| format!("{:.0}", sample.traffic.buffer_ms))),
181+ "buffer ms",
182+ false,
183+ t,
359184 )),
360185 )
361186 .child(
362- div()
363- .w(px(size::ROW))
364- .flex_none()
365- .text_right()
366- .text_color(palette.text)
367- .child(rate(stats.kbps)),
368- )
369- .child(
370- div()
371- .w(px(RATE_W))
372- .flex_none()
373- .text_right()
374- .text_color(palette.muted)
375- .child(latency),
187+ div().h(px(size::CONTROL_SM)).child(spark(
188+ chat.voice_samples
189+ .iter()
190+ .map(|sample| (sample.ping_ms / PING_SCALE).clamp(0., 1.))
191+ .collect(),
192+ SAMPLE_HISTORY,
193+ if bad { t.bad() } else { t.paper() },
194+ )),
376195 )
377- .child(chip(format!("{loss:.1}%"), loss_color, palette))
378196 }
379197
380-fn usage_block(usage: &Usage, palette: Palette) -> Div {
381- let memory = usage.memory;
382- let total_mb = memory.total_mb.max(1) as f32;
383- let cpu = column()
384- .child(model_header(
385- IconName::Cpu,
386- "CPU",
387- &usage.cpu_model,
388- palette,
198+fn traffic(chat: &Chat, t: Tokens) -> Div {
199+ let up: Vec<f32> = chat.traffic.iter().map(|(up, _)| *up).collect();
200+ let down: Vec<f32> = chat.traffic.iter().map(|(_, down)| *down).collect();
201+ let max = up.iter().chain(&down).copied().fold(1., f32::max);
202+ let line = |values: &[f32], ink: Hsla| {
203+ div()
204+ .h(px(space::MD))
205+ .child(spark(
206+ values.iter().map(|value| value / max).collect(),
207+ SAMPLE_HISTORY,
208+ ink,
209+ ))
210+ .into_any_element()
211+ };
212+ let latest = |values: &[f32]| rate(values.last().copied().unwrap_or_default() as u32);
213+
214+ stack(space::XS)
215+ .child(title("Traffic", String::new(), None, t))
216+ .child(line_row(
217+ label("up", t),
218+ line(&up, t.paper()),
219+ latest(&up),
220+ false,
221+ t,
389222 ))
390- .child(dual(
391- "total",
392- usage.total,
393- usage.machine,
394- palette.text,
395- palette,
223+ .child(line_row(
224+ label("down", t),
225+ line(&down, t.dim()),
226+ latest(&down),
227+ false,
228+ t,
396229 ))
397- .children(
398- usage
399- .threads
400- .map(|threads| {
401- [
402- meter("gui", threads.gui, palette.accent, palette),
403- meter("camera", threads.camera, palette.camera, palette),
404- meter("encode", threads.encode, palette.screen, palette),
405- meter("decode", threads.decode, palette.ok, palette),
406- ]
407- })
408- .into_iter()
409- .flatten(),
410- )
411- .child(dual_value(
412- "ram",
413- format!("{} / {}", gb(memory.own_mb), gb(memory.used_mb)),
414- memory.own_mb as f32 / total_mb,
415- memory.used_mb as f32 / total_mb,
416- palette.muted,
417- palette,
418- ));
419- div()
420- .flex()
421- .gap(px(space::XL))
422- .child(cpu)
423- .children(usage.gpu.as_ref().map(|gpu| gpu_column(gpu, palette)))
424-}
425-
426-fn column() -> Div {
427- div()
428- .flex()
429- .flex_col()
430- .gap(px(space::SM))
431- .flex_1()
432- .min_w_0()
433-}
434-
435-fn model_header(icon: IconName, title: &'static str, model: &str, palette: Palette) -> Div {
436- div()
437- .flex()
438- .flex_col()
439- .gap(px(space::XXS))
440- .child(header(icon, title, palette.text))
441- .child(
442- div()
443- .text_size(text_size(text::CAPTION))
444- .text_color(palette.muted)
445- .truncate()
446- .child(model.to_string()),
447- )
448230 }
449231
450-fn gpu_column(gpu: &Gpu, palette: Palette) -> Div {
451- let machine = gpu.machine;
452- let vram_total = machine.vram_total_mb.max(machine.vram_used_mb).max(1) as f32;
453- column()
454- .child(model_header(
455- IconName::MemoryStick,
456- "GPU",
457- &gpu.model,
458- palette,
459- ))
460- .child(dual("3d", gpu.gfx, machine.gfx, palette.accent, palette))
461- .child(dual(
462- "video",
463- gpu.video,
464- machine.video,
465- palette.screen,
466- palette,
232+fn machine(usage: &Usage, t: Tokens) -> Div {
233+ let memory = usage.memory;
234+ let total_mb = memory.total_mb.max(1) as f32;
235+ let over = |own: f32, total: f32| track(Fill::Over { own, total }, false, t).into_any_element();
236+ let model = match usage.gpu.as_ref() {
237+ Some(gpu) => format!("{} · {}", usage.cpu_model, gpu.model),
238+ None => usage.cpu_model.to_string(),
239+ };
240+
241+ stack(space::XS)
242+ .child(title("This machine", model, None, t))
243+ .child(line_row(
244+ label("CPU", t),
245+ over(usage.total / 100., usage.machine / 100.),
246+ format!("{:.0} / {:.0} %", usage.total, usage.machine),
247+ false,
248+ t,
467249 ))
468- .child(dual_value(
469- "vram",
470- format!("{} / {}", gb(gpu.vram_mb), gb(machine.vram_used_mb)),
471- gpu.vram_mb as f32 / vram_total,
472- machine.vram_used_mb as f32 / vram_total,
473- palette.muted,
474- palette,
250+ .children(usage.threads.map(|threads| {
251+ band(space::MD).children(
252+ [
253+ ("gui", threads.gui),
254+ ("camera", threads.camera),
255+ ("encode", threads.encode),
256+ ("decode", threads.decode),
257+ ]
258+ .map(|(name, value)| {
259+ words(format!("{name} {value:.0} %"), Text::Caption, Ink::Faint, t)
260+ }),
261+ )
262+ }))
263+ .child(line_row(
264+ label("memory", t),
265+ over(
266+ memory.own_mb as f32 / total_mb,
267+ memory.used_mb as f32 / total_mb,
268+ ),
269+ format!("{} / {}", gb(memory.own_mb), gb(memory.total_mb)),
270+ false,
271+ t,
475272 ))
273+ .children(usage.gpu.as_ref().map(|gpu| {
274+ let machine = gpu.machine;
275+ let vram_total = machine.vram_total_mb.max(machine.vram_used_mb).max(1) as f32;
276+ stack(space::XS)
277+ .child(line_row(
278+ label("GPU 3d", t),
279+ over(gpu.gfx / 100., machine.gfx / 100.),
280+ format!("{:.0} / {:.0} %", gpu.gfx, machine.gfx),
281+ false,
282+ t,
283+ ))
284+ .child(line_row(
285+ label("video", t),
286+ over(gpu.video / 100., machine.video / 100.),
287+ format!("{:.0} / {:.0} %", gpu.video, machine.video),
288+ false,
289+ t,
290+ ))
291+ .child(line_row(
292+ label("vram", t),
293+ over(
294+ gpu.vram_mb as f32 / vram_total,
295+ machine.vram_used_mb as f32 / vram_total,
296+ ),
297+ format!("{} / {}", gb(gpu.vram_mb), gb(machine.vram_total_mb)),
298+ false,
299+ t,
300+ ))
301+ }))
302+}
303+
304+fn sending(sending: &[(Kind, LayerStats)], t: Tokens) -> Vec<Div> {
305+ [Kind::Screen, Kind::Camera]
306+ .into_iter()
307+ .filter_map(|kind| {
308+ let layers: Vec<&LayerStats> = sending
309+ .iter()
310+ .filter(|(sent, _)| *sent == kind)
311+ .map(|(_, stats)| stats)
312+ .collect();
313+ let last = layers.last()?;
314+ let max = largest(layers.iter().map(|stats| stats.kbps));
315+ let name = match kind {
316+ Kind::Screen => "Sending screen",
317+ Kind::Camera => "Sending camera",
318+ };
319+ Some(
320+ stack(space::XS)
321+ .child(title(
322+ name,
323+ format!(
324+ "{} · {}",
325+ last.layer.codec.name(),
326+ engine_label(last.engine)
327+ ),
328+ None,
329+ t,
330+ ))
331+ .children(layers.iter().rev().map(|stats| {
332+ line_row(
333+ words(
334+ resolution_text(stats.layer, stats.fps),
335+ Text::Caption,
336+ Ink::Dim,
337+ t,
338+ )
339+ .into_any_element(),
340+ track(Fill::Part(stats.kbps as f32 / max), false, t).into_any_element(),
341+ rate(stats.kbps),
342+ false,
343+ t,
344+ )
345+ })),
346+ )
347+ })
348+ .collect()
476349 }
477350
478-fn gb(mb: u32) -> String {
479- match mb {
480- 0..1000 => format!("{mb} M"),
481- _ => format!("{:.1} G", mb as f32 / 1024.),
351+fn watching(watching: &[(Id, Kind, WatchStats)], chat: &Chat, t: Tokens) -> Option<Div> {
352+ if watching.is_empty() {
353+ return None;
482354 }
483-}
484-
485-fn dual(label: &'static str, own: f32, machine: f32, color: Hsla, palette: Palette) -> Div {
486- dual_value(
487- label,
488- format!("{own:.0} / {machine:.0} %"),
489- own / 100.,
490- machine / 100.,
491- color,
492- palette,
493- )
494-}
495-
496-fn dual_value(
497- label: &'static str,
498- value: String,
499- own: f32,
500- machine: f32,
501- color: Hsla,
502- palette: Palette,
503-) -> Div {
504- row(
505- label,
506- value,
507- dual_bar(own, machine, color, palette),
508- palette,
509- )
510-}
511-
512-fn meter(label: &'static str, percent: f32, color: Hsla, palette: Palette) -> Div {
513- meter_value(
514- label,
515- format!("{percent:.1} %"),
516- percent / 100.,
517- color,
518- palette,
355+ let max = largest(watching.iter().map(|(_, _, stats)| stats.kbps));
356+ let latency = watching
357+ .iter()
358+ .filter_map(|(_, _, stats)| stats.latency_ms)
359+ .max();
360+ let loss = watching
361+ .iter()
362+ .map(|(_, _, stats)| stats.loss)
363+ .fold(0., f32::max)
364+ * 100.;
365+ let keyframes: u32 = watching.iter().map(|(_, _, stats)| stats.keyframes).sum();
366+ let nacks: u32 = watching.iter().map(|(_, _, stats)| stats.nacks).sum();
367+ let count = watching.len();
368+
369+ Some(
370+ stack(space::XS)
371+ .child(title(
372+ "Watching",
373+ format!("{count} {}", if count == 1 { "stream" } else { "streams" }),
374+ None,
375+ t,
376+ ))
377+ .children(watching.iter().map(|(user_id, kind, stats)| {
378+ let name = chat
379+ .author(*user_id)
380+ .map_or_else(|| user_id.to_string(), |user| user.username.clone());
381+ let detail = format!(
382+ "{} · {}",
383+ kind_word(*kind),
384+ stats
385+ .layer
386+ .map_or("…".to_string(), |layer| resolution_text(layer, stats.fps))
387+ );
388+ let bad = Quality::of_loss(stats.loss * 100.) == Quality::Poor;
389+ line_row(
390+ band(space::XS)
391+ .child(
392+ words(name, Text::Label, Ink::Paper, t)
393+ .text_color(t.person(*user_id))
394+ .flex_none(),
395+ )
396+ .child(words(detail, Text::Caption, Ink::Faint, t))
397+ .into_any_element(),
398+ track(Fill::Part(stats.kbps as f32 / max), bad, t).into_any_element(),
399+ rate(stats.kbps),
400+ bad,
401+ t,
402+ )
403+ }))
404+ .child(
405+ band(space::MD)
406+ .child(words(
407+ format!(
408+ "latency {}",
409+ latency.map_or("…".into(), |ms| format!("{ms} ms"))
410+ ),
411+ Text::Caption,
412+ Ink::Faint,
413+ t,
414+ ))
415+ .child(words(
416+ format!("loss {loss:.1} %"),
417+ Text::Caption,
418+ if loss > GOOD_LOSS {
419+ Ink::Bad
420+ } else {
421+ Ink::Faint
422+ },
423+ t,
424+ ))
425+ .child(words(
426+ format!("keyframes {keyframes}"),
427+ Text::Caption,
428+ Ink::Faint,
429+ t,
430+ ))
431+ .child(words(
432+ format!("NACKs {nacks}"),
433+ Text::Caption,
434+ Ink::Faint,
435+ t,
436+ )),
437+ ),
519438 )
520439 }
521440
522-fn meter_value(
523- label: &'static str,
524- value: String,
525- fraction: f32,
526- color: Hsla,
527- palette: Palette,
528-) -> Div {
529- row(label, value, bar(fraction, color, palette), palette)
530-}
531-
532-fn row(label: &'static str, value: String, bar: Div, palette: Palette) -> Div {
533- div()
534- .flex()
535- .items_center()
536- .gap(px(space::SM))
537- .text_size(text_size(text::CAPTION))
538- .child(
539- div()
540- .w(px(size::ROW))
541- .flex_none()
542- .text_color(palette.muted)
543- .child(label),
544- )
545- .child(bar)
546- .child(
547- div()
548- .w(px(VALUE_W))
549- .flex_none()
550- .text_right()
551- .text_color(palette.text)
552- .child(value),
553- )
554-}
555-
556-fn kind_color(kind: Kind, palette: Palette) -> Hsla {
441+fn kind_word(kind: Kind) -> &'static str {
557442 match kind {
558- Kind::Camera => palette.camera,
559- Kind::Screen => palette.screen,
443+ Kind::Camera => "camera",
444+ Kind::Screen => "screen",
560445 }
561446 }
562447
563-fn kind_name(kind: Kind) -> &'static str {
564- match kind {
565- Kind::Camera => "Camera",
566- Kind::Screen => "Screen",
448+fn gb(mb: u32) -> String {
449+ match mb {
450+ 0..1000 => format!("{mb} MB"),
451+ _ => format!("{:.1} GB", mb as f32 / 1024.),
567452 }
568453 }
569454
@@ -573,132 +458,22 @@ fn largest(values: impl Iterator<Item = u32>) -> f32 {
573458
574459 pub fn rate(kbps: u32) -> String {
575460 match kbps {
576- 0..1000 => format!("{kbps} kbps"),
577- _ => format!("{:.1} Mbps", kbps as f32 / 1000.),
461+ 0..1000 => format!("{kbps} kb/s"),
462+ _ => format!("{:.1} Mb/s", kbps as f32 / 1000.),
578463 }
579464 }
580465
581466 fn engine_label(engine: Engine) -> &'static str {
582467 match engine {
583- Engine::Hardware => "HW",
584- Engine::Software => "SW",
468+ Engine::Hardware => "hardware",
469+ Engine::Software => "software",
585470 }
586471 }
587472
588473 fn resolution_text(layer: Layer, fps: f32) -> String {
589474 format!(
590- "{}p{}",
475+ "{}p {}",
591476 layer.quality.resolution.height(),
592477 fps.round() as u32
593478 )
594479 }
595-
596-fn header(icon: IconName, title: &'static str, color: Hsla) -> Div {
597- div()
598- .flex()
599- .items_center()
600- .gap(px(space::SM))
601- .child(
602- Icon::new(icon)
603- .size(px(size::ICON_SM))
604- .flex_none()
605- .text_color(color),
606- )
607- .child(
608- div()
609- .font_weight(FontWeight::SEMIBOLD)
610- .text_size(text_size(text::CAPTION))
611- .text_color(color)
612- .child(title),
613- )
614- .child(div().flex_1())
615-}
616-
617-fn label(value: &'static str, color: Hsla) -> Div {
618- div()
619- .text_size(text_size(text::CAPTION))
620- .text_color(color)
621- .child(value)
622-}
623-
624-fn chip(value: impl gpui_kit::IntoElement, color: Hsla, palette: Palette) -> Div {
625- div()
626- .flex_none()
627- .px(px(space::SM))
628- .py(px(space::XXS))
629- .rounded(px(radius::SM))
630- .bg(palette.hover)
631- .text_size(text_size(text::CAPTION))
632- .text_color(color)
633- .child(value)
634-}
635-
636-fn stat_cell(label: &'static str, value: String, color: Hsla, palette: Palette) -> Div {
637- div()
638- .flex_1()
639- .min_w_0()
640- .flex()
641- .flex_col()
642- .gap(px(space::XXS))
643- .child(
644- div()
645- .text_size(text_size(text::CAPTION))
646- .text_color(palette.muted)
647- .child(label),
648- )
649- .child(
650- div()
651- .text_size(text_size(text::UI))
652- .text_color(color)
653- .child(value),
654- )
655-}
656-
657-fn avatar_dot(name: &str, color: Hsla, palette: Palette) -> Div {
658- let initial = name
659- .chars()
660- .next()
661- .map_or('?', |letter| letter.to_ascii_uppercase());
662- div()
663- .size(px(size::CHIP))
664- .flex_none()
665- .rounded_full()
666- .flex()
667- .items_center()
668- .justify_center()
669- .bg(color)
670- .text_size(text_size(text::CAPTION))
671- .font_weight(FontWeight::BOLD)
672- .text_color(palette.on_accent)
673- .child(initial.to_string())
674-}
675-
676-fn dual_bar(own: f32, machine: f32, color: Hsla, palette: Palette) -> Div {
677- bar(machine, palette.tokens.faint(), palette).child(
678- div()
679- .absolute()
680- .top_0()
681- .left_0()
682- .h_full()
683- .w(relative(own.clamp(0., 1.)))
684- .rounded_full()
685- .bg(color),
686- )
687-}
688-
689-fn bar(fraction: f32, color: Hsla, palette: Palette) -> Div {
690- div()
691- .relative()
692- .flex_1()
693- .min_w_0()
694- .h(px(space::XS))
695- .rounded_full()
696- .bg(palette.border)
697- .child(
698- div()
699- .h_full()
700- .w(relative(fraction.clamp(0., 1.)))
701- .rounded_full()
702- .bg(color),
703- )
704-}
crates/client/src/usage/drm.rsmodified+4 -4
@@ -167,10 +167,10 @@ fn machine_clients(pdev: &str) -> Vec<Client> {
167167 let Ok(info) = fs::read_to_string(path.join("fdinfo").join(fd.file_name())) else {
168168 continue;
169169 };
170- if let Some(client) = client(&info) {
171- if client.pdev == pdev {
172- clients.push(client);
173- }
170+ if let Some(client) = client(&info)
171+ && client.pdev == pdev
172+ {
173+ clients.push(client);
174174 }
175175 }
176176 }
crates/common/src/call.rsmodified+7 -0
@@ -3,6 +3,7 @@ use bitcode::{Decode, DecodeOwned, Encode};
33 use crate::{
44 constant::{MAXIMUM_AVATAR_BYTES, MAXIMUM_MESSAGE_LENGTH},
55 error::Error,
6+ model::Hue,
67 model::{
78 Account, AdminActionKind, AdminLogEntry, AttachmentInfo, BackupInfo, Ban, BanScope,
89 Community, CommunitySummary, CommunityUsage, DayStat, Friends, Id, Invitation, InviteCode,
@@ -80,6 +81,11 @@ pub struct UpdateStatus {
8081 pub status: String,
8182 }
8283
84+#[derive(Debug, Clone, Encode, Decode)]
85+pub struct UpdateHue {
86+ pub hue: Option<Hue>,
87+}
88+
8389 #[derive(Debug, Clone, Encode, Decode)]
8490 pub struct UpdatePresence {
8591 pub presence: Presence,
@@ -635,6 +641,7 @@ calls! {
635641 GetUser: User -> User;
636642 UpdateUser: User -> User, |c| validate_username(&c.username);
637643 UpdateStatus: User -> User, |c| validate_status(&c.status);
644+ UpdateHue: User -> User;
638645 UpdatePresence: User -> ();
639646 ListPresences: User -> Vec<(Id, Presence)>;
640647 UpdateAvatar: User -> User, |c| validate_avatar_size(&c.image, MAXIMUM_AVATAR_BYTES as u64);
crates/common/src/model.rsmodified+1 -0
@@ -127,6 +127,7 @@ pub struct User {
127127 pub username: String,
128128 pub role: Role,
129129 pub status: String,
130+ pub hue: Option<Hue>,
130131 pub avatar_id: Option<Id>,
131132 pub created_at: u64,
132133 }
crates/server/src/call/mod.rsmodified+1 -0
@@ -110,6 +110,7 @@ pub(crate) async fn dispatch(request: Request, cx: &mut Cx<'_>) -> Vec<u8> {
110110 Request::GetUser(call) => serve(call, cx).await,
111111 Request::UpdateUser(call) => serve(call, cx).await,
112112 Request::UpdateStatus(call) => serve(call, cx).await,
113+ Request::UpdateHue(call) => serve(call, cx).await,
113114 Request::UpdatePresence(call) => serve(call, cx).await,
114115 Request::ListPresences(call) => serve(call, cx).await,
115116 Request::UpdateAvatar(call) => serve(call, cx).await,
crates/server/src/call/user.rsmodified+11 -1
@@ -1,7 +1,7 @@
11 use common::{
22 call::{
33 GetAvatar, GetSettings, GetUser, ListPresences, ListSessions, RemoveAvatar, RevokeSession,
4- UpdateAvatar, UpdatePresence, UpdateStatus, UpdateUser,
4+ UpdateAvatar, UpdateHue, UpdatePresence, UpdateStatus, UpdateUser,
55 },
66 event::Event,
77 model::{AdminAction, Id, Presence, ServerSettings, SessionInfo, User},
@@ -54,6 +54,16 @@ impl Handle for UpdateStatus {
5454 }
5555 }
5656
57+impl Handle for UpdateHue {
58+ async fn handle(self, me: Me, cx: &mut Cx<'_>) -> Result<User, ServerError> {
59+ let me = me.user()?;
60+ let user = db::user::update_hue(me.id, self.hue, cx.db).await?;
61+ user_updated(&user, cx);
62+
63+ Ok(user)
64+ }
65+}
66+
5767 impl Handle for UpdatePresence {
5868 async fn handle(self, me: Me, cx: &mut Cx<'_>) -> Result<(), ServerError> {
5969 let me = me.user()?;
crates/server/src/db/schema.sqlmodified+1 -0
@@ -4,6 +4,7 @@ CREATE TABLE user (
44 password_hash TEXT NOT NULL,
55 role TEXT NOT NULL,
66 status TEXT NOT NULL DEFAULT '',
7+ hue TEXT,
78 presence TEXT NOT NULL,
89 suspended INTEGER NOT NULL DEFAULT 0,
910 suspended_until INTEGER,
crates/server/src/db/user.rsmodified+16 -2
@@ -1,6 +1,6 @@
11 use common::{
22 error::Error,
3- model::{Account, Id, Presence, Role, User},
3+ model::{Account, Hue, Id, Presence, Role, User},
44 permission,
55 time::now_ms,
66 };
@@ -8,7 +8,7 @@ use common::{
88 use super::{Connection, Reader, all, maybe, one, run};
99 use crate::error::{ServerError, ensure_with};
1010
11-pub const COLUMNS: &str = "user.id, user.username, user.role, user.status, (SELECT avatar.id FROM avatar WHERE avatar.user_id = user.id), user.created_at";
11+pub const COLUMNS: &str = "user.id, user.username, user.role, user.status, user.hue, (SELECT avatar.id FROM avatar WHERE avatar.user_id = user.id), user.created_at";
1212
1313 pub fn row(r: &mut Reader) -> Result<User, ServerError> {
1414 Ok(User {
@@ -16,6 +16,9 @@ pub fn row(r: &mut Reader) -> Result<User, ServerError> {
1616 username: r.get()?,
1717 role: r.named()?,
1818 status: r.get()?,
19+ hue: r
20+ .get::<Option<String>>()?
21+ .and_then(|text| Hue::parse(&text)),
1922 avatar_id: r.get()?,
2023 created_at: r.get()?,
2124 })
@@ -92,6 +95,17 @@ pub async fn update(id: Id, username: &str, db: &Connection) -> Result<User, Ser
9295 read(id, db).await
9396 }
9497
98+pub async fn update_hue(id: Id, hue: Option<Hue>, db: &Connection) -> Result<User, ServerError> {
99+ run(
100+ db,
101+ "UPDATE user SET hue = ?2 WHERE id = ?1",
102+ (id, hue.map(|hue| hue.as_str())),
103+ )
104+ .await?;
105+
106+ read(id, db).await
107+}
108+
95109 pub async fn update_status(id: Id, status: &str, db: &Connection) -> Result<User, ServerError> {
96110 run(
97111 db,