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 {
304 .to_string()304 .to_string()
305 }305 }
306 306
307-pub use parts::{motion, pop_in, swap_in};307+pub use parts::motion;
308 308
309 pub fn hoverable(id: impl Into<ElementId>, element: Div, palette: Palette) -> Stateful<Div> {309 pub fn hoverable(id: impl Into<ElementId>, element: Div, palette: Palette) -> Stateful<Div> {
310 hoverable_with(id, element, palette.hover)310 hoverable_with(id, element, palette.hover)
@@ -655,6 +655,7 @@ impl Yumush {
655 self.accounts.sign_in(&user, token);655 self.accounts.sign_in(&user, token);
656 self.request_user_avatar(&user, cx);656 self.request_user_avatar(&user, cx);
657 self.chat.muted = mutes::load(user.id);657 self.chat.muted = mutes::load(user.id);
658+ style::remember(&[&user]);
658 self.user = Some(user);659 self.user = Some(user);
659 self.change_page(Route::Chat, window, cx);660 self.change_page(Route::Chat, window, cx);
660 self.load_communities(window, cx);661 self.load_communities(window, cx);
crates/client/src/gui/camera_view.rsmodified+13 -11
@@ -226,24 +226,26 @@ impl Yumush {
226 .into_iter()226 .into_iter()
227 .map(|source| stage_tile(entity, self, palette, source))227 .map(|source| stage_tile(entity, self, palette, source))
228 .collect();228 .collect();
229- if tiles.is_empty() {229+ let strip = (!tiles.is_empty()).then(|| {
230- return Some(self.voices(palette).into_any_element());
231- }
232-
233- Some(
234 div()230 div()
235 .id("stage_strip")231 .id("stage_strip")
236 .flex()232 .flex()
237 .flex_shrink_0()233 .flex_shrink_0()
238 .h(px(STRIP_H))234 .h(px(STRIP_H))
239 .gap(px(space::SM))235 .gap(px(space::SM))
240- .p(px(space::SM))236+ .px(px(space::XL))
241- .bg(palette.window)237+ .pb(px(space::SM))
242 .overflow_x_scroll()238 .overflow_x_scroll()
243- .border_b_1()
244- .border_color(palette.border)
245 .children(tiles)239 .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),
247 )249 )
248 }250 }
249 251
@@ -254,7 +256,7 @@ impl Yumush {
254 .voice_community()256 .voice_community()
255 .map(|community_id| self.chat.voice_ids(community_id))257 .map(|community_id| self.chat.voice_ids(community_id))
256 .unwrap_or_default()258 .unwrap_or_default()
257- .into_iter()259+ .iter()
258 .filter_map(|id| self.chat.author(*id))260 .filter_map(|id| self.chat.author(*id))
259 .map(|user| {261 .map(|user| {
260 let speaking = self.chat.waves.speaking.contains(&user.id);262 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};
2 use super::text;2 use super::text;
3 use crate::gui::CLOCK;3 use crate::gui::CLOCK;
4 use std::{4 use std::{
@@ -19,7 +19,7 @@ use crate::gui::{
19 composer::{self, Composer},19 composer::{self, Composer},
20 entity_action, hoverable,20 entity_action, hoverable,
21 media_view::{self, Media},21 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,
23 primary_button,23 primary_button,
24 profile::profile_popover,24 profile::profile_popover,
25 rank_tag,25 rank_tag,
@@ -145,6 +145,7 @@ pub struct Chat {
145 pub(super) found: Option<User>,145 pub(super) found: Option<User>,
146 pub(super) invite: InviteLookup,146 pub(super) invite: InviteLookup,
147 pub(super) sidebar_collapsed: bool,147 pub(super) sidebar_collapsed: bool,
148+ pub(super) sidebar_toggled: Option<std::time::Instant>,
148 pub(super) composer: Composer,149 pub(super) composer: Composer,
149 pub(super) drafts: HashMap<Id, String>,150 pub(super) drafts: HashMap<Id, String>,
150 pub(super) poll_question: Entity<InputState>,151 pub(super) poll_question: Entity<InputState>,
@@ -390,6 +391,7 @@ impl Chat {
390 found: None,391 found: None,
391 invite: InviteLookup::Idle,392 invite: InviteLookup::Idle,
392 sidebar_collapsed: false,393 sidebar_collapsed: false,
394+ sidebar_toggled: None,
393 view: View::Chat,395 view: View::Chat,
394 section: 0,396 section: 0,
395 username_input: editable_input("Username...", Yumush::save_username, window, cx),397 username_input: editable_input("Username...", Yumush::save_username, window, cx),
@@ -617,7 +619,17 @@ impl Chat {
617 Event::CommunityUpdated(community) | Event::CommunityAdded(community) => {619 Event::CommunityUpdated(community) | Event::CommunityAdded(community) => {
618 self.insert_community(community)620 self.insert_community(community)
619 }621 }
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+ }
621 Event::InvitationsUpdated(invitations) => self.invitations = invitations,633 Event::InvitationsUpdated(invitations) => self.invitations = invitations,
622 Event::CommunityDeleted { community_id } | Event::Removed { community_id, .. } => {634 Event::CommunityDeleted { community_id } | Event::Removed { community_id, .. } => {
623 self.remove_community(community_id)635 self.remove_community(community_id)
@@ -882,6 +894,7 @@ impl Chat {
882 }894 }
883 895
884 fn insert_member(&mut self, member: Member) {896 fn insert_member(&mut self, member: Member) {
897+ style::remember(&[&member.user]);
885 self.remove_member(member.user.id);898 self.remove_member(member.user.id);
886 self.members.push(member);899 self.members.push(member);
887 self.members.sort_by_key(|member| member.user.id);900 self.members.sort_by_key(|member| member.user.id);
@@ -995,6 +1008,7 @@ impl Chat {
995 }1008 }
996 1009
997 pub fn update_member(&mut self, user: &User) {1010 pub fn update_member(&mut self, user: &User) {
1011+ style::remember(&[user]);
998 let peers = self1012 let peers = self
999 .communities1013 .communities
1000 .iter_mut()1014 .iter_mut()
@@ -1322,6 +1336,7 @@ impl Yumush {
1322 .min_w_0()1336 .min_w_0()
1323 .flex()1337 .flex()
1324 .flex_col()1338 .flex_col()
1339+ .relative()
1325 .bg(palette.window)1340 .bg(palette.window)
1326 .overflow_hidden()1341 .overflow_hidden()
1327 .children(self.announcement_banner(entity, palette))1342 .children(self.announcement_banner(entity, palette))
@@ -1343,40 +1358,42 @@ impl Yumush {
1343 .children(self.stage_strip(entity, themed))1358 .children(self.stage_strip(entity, themed))
1344 .children(self.unread_bar(entity, themed))1359 .children(self.unread_bar(entity, themed))
1345 .children(self.poll_banner(entity, themed))1360 .children(self.poll_banner(entity, themed))
1346- .child(1361+ .child(div().flex_1().min_h_0().flex().child(
1347- div()1362+ div().flex_1().min_w_0().flex().flex_col().map(|panel| {
1348- .flex_1()1363+ match self.inline_viewer(entity, themed) {
1349- .min_h_0()1364+ Some(viewer) => panel.child(viewer),
1350- .flex()1365+ None => match self.stage_grid(entity, themed) {
1351- .child(div().flex_1().min_w_0().flex().flex_col().map(|panel| {1366+ Some(grid) => panel.child(grid),
1352- match self.inline_viewer(entity, themed) {1367+ None => panel
1353- Some(viewer) => panel.child(viewer),1368+ .child(self.message_area(entity, themed))
1354- None => match self.stage_grid(entity, themed) {1369+ .child(self.composer(entity, themed, cx)),
1355- Some(grid) => panel.child(grid),1370+ },
1356- None => panel1371+ }
1357- .child(self.message_area(entity, themed))1372+ }),
1358- .child(self.composer(entity, themed, cx)),1373+ )),
1359- },
1360- }
1361- }))
1362- .children(self.stats_side(palette)),
1363- ),
1364 None => panel.child(empty_state(palette)),1374 None => panel.child(empty_state(palette)),
1365 },1375 },
1366 })1376 })
1377+ .children(self.stats_sheet(palette))
1367 .children(self.dock(entity, palette, cx))1378 .children(self.dock(entity, palette, cx))
1368 }1379 }
1369 1380
1370- fn stats_side(&self, palette: Palette) -> Option<impl IntoElement> {1381+ fn stats_sheet(&self, palette: Palette) -> Option<impl IntoElement> {
1371- (self.chat.stats_open && self.in_stage_chat()).then(|| {1382+ (self.chat.stats_open && self.chat.voice_community().is_some()).then(|| {
1372 div()1383 div()
1373- .id("stats_side")1384+ .id("stats_sheet")
1374- .w(px(size::SHEET))1385+ .absolute()
1375- .flex_shrink_0()1386+ .right(px(space::LG))
1376- .p(px(space::MD))1387+ .bottom(px(size::ROW + space::MD + space::SM))
1377- .border_l_1()1388+ .max_w(relative(0.95))
1378- .border_color(palette.border)1389+ .max_h(relative(0.8))
1379 .overflow_y_scroll()1390 .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()
1380 .child(voice_stats::stats_panel(&self.chat, palette))1397 .child(voice_stats::stats_panel(&self.chat, palette))
1381 })1398 })
1382 }1399 }
@@ -1835,6 +1852,12 @@ impl Yumush {
1835 .users1852 .users
1836 .insert(member.user.id, member.user.clone());1853 .insert(member.user.id, member.user.clone());
1837 }1854 }
1855+ style::remember(
1856+ &members
1857+ .iter()
1858+ .map(|member| &member.user)
1859+ .collect::<Vec<_>>(),
1860+ );
1838 let old = std::mem::replace(&mut yumush.chat.members, members);1861 let old = std::mem::replace(&mut yumush.chat.members, members);
1839 yumush1862 yumush
1840 .chat1863 .chat
@@ -1864,6 +1887,7 @@ impl Yumush {
1864 };1887 };
1865 let _ = this.update(cx, |yumush, cx| {1888 let _ = this.update(cx, |yumush, cx| {
1866 yumush.request_user_avatar(&user, cx);1889 yumush.request_user_avatar(&user, cx);
1890+ style::remember(&[&user]);
1867 yumush.chat.users.insert(user.id, user);1891 yumush.chat.users.insert(user.id, user);
1868 cx.notify();1892 cx.notify();
1869 });1893 });
@@ -2662,88 +2686,84 @@ fn members_popover(entity: &Entity<Yumush>, yumush: &Yumush, palette: Palette) -
2662 .content(move |_, _, _| {2686 .content(move |_, _, _| {
2663 let entity = entity.clone();2687 let entity = entity.clone();
2664 2688
2665- pop_in(2689+ div()
2666- "members_list",2690+ .w(px(size::SIDEBAR))
2667- div()2691+ .p(px(space::XS))
2668- .w(px(size::SIDEBAR))2692+ .flex()
2669- .p(px(space::XS))2693+ .flex_col()
2670- .flex()2694+ .rounded(px(radius::LG))
2671- .flex_col()2695+ .bg(palette.field)
2672- .rounded(px(radius::LG))2696+ .children(members.iter().map(
2673- .bg(palette.field)2697+ |MemberRow {
2674- .children(members.iter().map(2698+ user,
2675- |MemberRow {2699+ rank,
2676- user,2700+ in_voice,
2677- rank,2701+ muted,
2678- in_voice,2702+ presence,
2679- muted,2703+ }| {
2680- presence,2704+ profile_popover(
2681- }| {2705+ format!("member_{}", user.id),
2682- profile_popover(2706+ Anchor::TopRight,
2683- format!("member_{}", user.id),2707+ user,
2684- Anchor::TopRight,2708+ &entity,
2685- user,2709+ hoverable(
2686- &entity,2710+ format!("member_trigger_{}", user.id),
2687- hoverable(2711+ div()
2688- format!("member_trigger_{}", user.id),2712+ .h(px(size::CONTROL))
2689- div()2713+ .px(px(space::SM))
2690- .h(px(size::CONTROL))2714+ .flex()
2691- .px(px(space::SM))2715+ .items_center()
2692- .flex()2716+ .gap(px(space::SM))
2693- .items_center()2717+ .rounded(px(radius::MD))
2694- .gap(px(space::SM))2718+ .child(presence_avatar(
2695- .rounded(px(radius::MD))2719+ avatar(
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),
2706 palette,2720 palette,
2707- ))2721+ user,
2708- .child(2722+ px(size::ICON),
2709- div()2723+ text(text::CAPTION),
2710- .flex_1()2724+ &avatars,
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- })),
2739 ),2725 ),
2740- palette,2726+ *presence,
2741- ),2727+ px(size::ICON),
2742- )2728+ palette,
2743- },2729+ ))
2744- )),2730+ .child(
2745- Anchor::TopRight,2731+ div()
2746- )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+ ))
2747 })2767 })
2748 }2768 }
2749 2769
crates/client/src/gui/composer.rsmodified+157 -173
@@ -33,7 +33,7 @@ use gpui_kit::{
33 use super::{33 use super::{
34 Palette, Trigger, Yumush,34 Palette, Trigger, Yumush,
35 chat::{Chat, TYPING_SEND_INTERVAL},35 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,
37 };37 };
38 38
39 actions!(composer, [Bold, Italic, Code, Strike]);39 actions!(composer, [Bold, Italic, Code, Strike]);
@@ -550,35 +550,31 @@ pub fn format_popover(palette: Palette) -> impl IntoElement {
550 palette,550 palette,
551 ))551 ))
552 .content(move |_, _, _| {552 .content(move |_, _, _| {
553- pop_in(553+ panel(palette)
554- "format_list",554+ .w(px(size::SHEET))
555- panel(palette)555+ .p(px(space::SM))
556- .w(px(size::SHEET))556+ .flex()
557- .p(px(space::SM))557+ .flex_col()
558- .flex()558+ .gap(px(space::SM))
559- .flex_col()559+ .text_size(text(text::CAPTION))
560- .gap(px(space::SM))560+ .children(FORMAT_ROWS.map(|(syntax, shortcut)| {
561- .text_size(text(text::CAPTION))561+ div()
562- .children(FORMAT_ROWS.map(|(syntax, shortcut)| {562+ .flex()
563- div()563+ .items_center()
564- .flex()564+ .gap(px(space::MD))
565- .items_center()565+ .child(
566- .gap(px(space::MD))566+ div()
567- .child(567+ .w(px(size::THUMB))
568- div()568+ .text_color(palette.muted)
569- .w(px(size::THUMB))569+ .child(syntax),
570- .text_color(palette.muted)570+ )
571- .child(syntax),571+ .child(div().flex_1().child(TextView::markdown(syntax, syntax)))
572- )572+ .child(
573- .child(div().flex_1().child(TextView::markdown(syntax, syntax)))573+ div()
574- .child(574+ .text_color(palette.muted)
575- div()575+ .child(shortcut_label(shortcut)),
576- .text_color(palette.muted)576+ )
577- .child(shortcut_label(shortcut)),577+ }))
578- )
579- })),
580- Anchor::BottomLeft,
581- )
582 })578 })
583 }579 }
584 580
@@ -645,160 +641,148 @@ pub fn plus_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> i
645 if entity.read(cx).chat.plus_menu == PlusMenu::Menu {641 if entity.read(cx).chat.plus_menu == PlusMenu::Menu {
646 let file = entity.clone();642 let file = entity.clone();
647 let poll = entity.clone();643 let poll = entity.clone();
648- return pop_in(644+ return panel(palette)
649- "plus_menu",645+ .w(px(size::SIDEBAR))
650- panel(palette)646+ .p(px(space::XS))
651- .w(px(size::SIDEBAR))647+ .flex()
652- .p(px(space::XS))648+ .flex_col()
653- .flex()649+ .gap(px(space::XS))
654- .flex_col()650+ .child(plus_row(
655- .gap(px(space::XS))651+ "plus_file",
656- .child(plus_row(652+ IconName::File,
657- "plus_file",653+ "File",
658- IconName::File,654+ palette,
659- "File",655+ move |window, cx| {
660- palette,656+ popover.update(cx, |state, cx| state.dismiss(window, cx));
661- move |window, cx| {657+ file.update(cx, |yumush, cx| yumush.attach_files(window, cx));
662- popover.update(cx, |state, cx| state.dismiss(window, cx));658+ },
663- file.update(cx, |yumush, cx| yumush.attach_files(window, cx));659+ ))
664- },660+ .child(plus_row(
665- ))661+ "plus_poll",
666- .child(plus_row(662+ IconName::ChartBar,
667- "plus_poll",663+ "Poll",
668- IconName::ChartBar,664+ palette,
669- "Poll",665+ move |_, cx| {
670- palette,666+ poll.update(cx, |yumush, cx| {
671- move |_, cx| {667+ yumush.chat.plus_menu = PlusMenu::Poll;
672- poll.update(cx, |yumush, cx| {668+ cx.notify();
673- yumush.chat.plus_menu = PlusMenu::Poll;669+ })
674- cx.notify();670+ },
675- })671+ ))
676- },672+ .into_any_element();
677- )),
678- Anchor::BottomLeft,
679- )
680- .into_any_element();
681 }673 }
682 let toggle = entity.clone();674 let toggle = entity.clone();
683 let toggle_public = entity.clone();675 let toggle_public = entity.clone();
684 let duration_entity = entity.clone();676 let duration_entity = entity.clone();
685 let submit = entity.clone();677 let submit = entity.clone();
686- pop_in(678+ panel(palette)
687- "poll_form",679+ .w(px(size::POPOVER))
688- panel(palette)680+ .p(px(space::SM))
689- .w(px(size::POPOVER))681+ .flex()
690- .p(px(space::SM))682+ .flex_col()
691- .flex()683+ .gap(px(space::SM))
692- .flex_col()684+ .text_size(text(text::CAPTION))
693- .gap(px(space::SM))685+ .child(compact_field(palette, &question))
694- .text_size(text(text::CAPTION))686+ .children(options.iter().enumerate().map(|(index, option)| {
695- .child(compact_field(palette, &question))687+ let remove = entity.clone();
696- .children(options.iter().enumerate().map(|(index, option)| {688+ let trailing_blank =
697- let remove = entity.clone();689+ index + 1 == options.len() && option_text(option, cx).is_empty();
698- let trailing_blank =690+ div()
699- index + 1 == options.len() && option_text(option, cx).is_empty();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(
700 div()746 div()
701 .flex()747 .flex()
702 .items_center()748 .items_center()
703- .gap(px(space::SM))749+ .gap(px(space::MD))
704 .child(750 .child(
705- div()751+ Checkbox::new("poll_multiple")
706- .flex_1()752+ .label("Multiple answers")
707- .min_w_0()753+ .checked(multiple)
708- .child(compact_field(palette, option)),754+ .on_click(move |_, _, cx| {
709- )755+ toggle.update(cx, |yumush, cx| {
710- .children(756+ yumush.chat.poll_multiple = !yumush.chat.poll_multiple;
711- (options.len() > MINIMUM_POLL_OPTIONS && !trailing_blank).then(757+ cx.notify();
712- || {758+ })
713- icon_button(759+ }),
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- ),
726 )760 )
727- }))761+ .child(
728- .child(762+ Checkbox::new("poll_public")
729- div()763+ .label("Show voters")
730- .flex()764+ .checked(public)
731- .items_center()765+ .on_click(move |_, _, cx| {
732- .gap(px(space::XS))766+ toggle_public
733- .text_color(palette.muted)767+ .update(cx, |yumush, cx| yumush.toggle_poll_public(cx))
734- .child(Icon::new(IconName::Timer).size(px(size::ICON_SM)))768+ }),
735- .children(POLL_DURATIONS.map(|(label, seconds)| {769+ ),
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"),
798 ),770 ),
799- Anchor::BottomLeft,771+ )
800- )772+ .child(
801- .into_any_element()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()
802 })786 })
803 }787 }
804 788
crates/client/src/gui/message_actions.rsmodified+58 -75
@@ -24,7 +24,7 @@ use super::{
24 chat::{Chat, ReportTarget},24 chat::{Chat, ReportTarget},
25 clickable,25 clickable,
26 composer::trigger_icon,26 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,
28 style::{radius, size, space, text},28 style::{radius, size, space, text},
29 widget::{field, icon_button, panel, spawn_done},29 widget::{field, icon_button, panel, spawn_done},
30 };30 };
@@ -99,40 +99,31 @@ pub fn react_popover(
99 ))99 ))
100 .content(move |_, _, cx| {100 .content(move |_, _, cx| {
101 let popover = cx.entity();101 let popover = cx.entity();
102- pop_in(102+ panel(palette)
103- "react_list",103+ .flex()
104- panel(palette)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))
105 .flex()120 .flex()
106- .gap(px(space::XXS))121+ .items_center()
107- .p(px(space::XS))122+ .justify_center()
108- .children(REACTIONS.map(|emoji| {123+ .rounded(px(radius::MD))
109- let entity = entity.clone();124+ .text_size(text(text::BODY))
110- let popover = popover.clone();125+ .child(emoji)
111- clickable(126+ }))
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- )
136 })127 })
137 }128 }
138 129
@@ -295,27 +286,23 @@ pub fn search_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) ->
295 ))286 ))
296 .content(move |_, _, cx| {287 .content(move |_, _, cx| {
297 let popover = cx.entity();288 let popover = cx.entity();
298- pop_in(289+ panel(palette)
299- "search_list",290+ .w(px(size::POPOVER))
300- panel(palette)291+ .p(px(space::XS))
301- .w(px(size::POPOVER))292+ .flex()
302- .p(px(space::XS))293+ .flex_col()
303- .flex()294+ .gap(px(space::XS))
304- .flex_col()295+ .child(sidebar::input_box(&input, palette))
305- .gap(px(space::XS))296+ .children(hits.iter().map(|hit| {
306- .child(sidebar::input_box(&input, palette))297+ jump_row("search_hit", hit, &entity, &popover, palette)
307- .children(hits.iter().map(|hit| {298+ .children(hit.time.as_ref().map(|time| {
308- jump_row("search_hit", hit, &entity, &popover, palette)299+ div()
309- .children(hit.time.as_ref().map(|time| {300+ .flex_shrink_0()
310- div()301+ .text_color(palette.muted)
311- .flex_shrink_0()302+ .child(time.clone())
312- .text_color(palette.muted)303+ }))
313- .child(time.clone())304+ .child(div().flex_1().min_w_0().truncate().child(hit.body.clone()))
314- }))305+ }))
315- .child(div().flex_1().min_w_0().truncate().child(hit.body.clone()))
316- })),
317- Anchor::TopRight,
318- )
319 })306 })
320 }307 }
321 308
@@ -341,26 +328,22 @@ pub fn pins_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> i
341 .trigger(trigger_icon("pins_trigger", IconName::Pin, 24., palette))328 .trigger(trigger_icon("pins_trigger", IconName::Pin, 24., palette))
342 .content(move |_, _, cx| {329 .content(move |_, _, cx| {
343 let popover = cx.entity();330 let popover = cx.entity();
344- pop_in(331+ panel(palette)
345- "pins_list",332+ .w(px(size::POPOVER))
346- panel(palette)333+ .p(px(space::XS))
347- .w(px(size::POPOVER))334+ .flex()
348- .p(px(space::XS))335+ .flex_col()
349- .flex()336+ .gap(px(space::XXS))
350- .flex_col()337+ .children(pins.iter().map(|hit| {
351- .gap(px(space::XXS))338+ jump_row("pin_hit", hit, &entity, &popover, palette).child(
352- .children(pins.iter().map(|hit| {339+ div()
353- jump_row("pin_hit", hit, &entity, &popover, palette).child(340+ .flex_1()
354- div()341+ .min_w_0()
355- .flex_1()342+ .truncate()
356- .min_w_0()343+ .text_color(palette.muted)
357- .truncate()344+ .child(hit.body.clone()),
358- .text_color(palette.muted)345+ )
359- .child(hit.body.clone()),346+ }))
360- )
361- })),
362- Anchor::TopRight,
363- )
364 })347 })
365 }348 }
366 349
crates/client/src/gui/parts.rsmodified+0 -32
@@ -413,38 +413,6 @@ pub fn spark(values: Vec<f32>, slots: usize, color: Hsla) -> AnyElement {
413 super::wave::line_of(values, slots, color).into_any_element()413 super::wave::line_of(values, slots, color).into_any_element()
414 }414 }
415 415
416-const MOTION_TRAVEL: f32 = 6.;
417-
418 pub fn motion() -> gpui_kit::Animation {416 pub fn motion() -> gpui_kit::Animation {
419 gpui_kit::Animation::new(Duration::from_millis(160)).with_easing(gpui_kit::ease_out_quint())417 gpui_kit::Animation::new(Duration::from_millis(160)).with_easing(gpui_kit::ease_out_quint())
420 }418 }
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::{
11 use super::{11 use super::{
12 Palette, Tooltip as _, Trigger, Yumush, avatar,12 Palette, Tooltip as _, Trigger, Yumush, avatar,
13 chat::Chat,13 chat::Chat,
14- clickable, hoverable, pop_in,14+ clickable, hoverable,
15 style::{radius, size, space, text},15 style::{radius, size, space, text},
16 text,16 text,
17 widget::{icon_button, panel, spawn_done},17 widget::{icon_button, panel, spawn_done},
@@ -143,19 +143,15 @@ fn voters_popover(key: &str, poll: &Poll, entity: &Entity<Yumush>, palette: Pale
143 })143 })
144 }))144 }))
145 });145 });
146- pop_in(146+ panel(palette)
147- list.clone(),147+ .w(px(size::SIDEBAR))
148- panel(palette)148+ .id(list.clone())
149- .w(px(size::SIDEBAR))149+ .max_h(px(size::POPOVER))
150- .id(list.clone())150+ .overflow_y_scroll()
151- .max_h(px(size::POPOVER))151+ .p(px(space::SM))
152- .overflow_y_scroll()152+ .flex()
153- .p(px(space::SM))153+ .flex_col()
154- .flex()154+ .children(rows)
155- .flex_col()
156- .children(rows),
157- Anchor::BottomLeft,
158- )
159 })155 })
160 .into_any_element()156 .into_any_element()
161 }157 }
crates/client/src/gui/profile.rsmodified+3 -11
@@ -27,7 +27,7 @@ use super::style::{radius, size, space, stroke, text};
27 use super::widget::{panel, spawn_done};27 use super::widget::{panel, spawn_done};
28 use super::{28 use super::{
29 DAY_YEAR, Palette, Trigger, Yumush, avatar, clickable, entity_action, input_dialog,29 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,
31 };31 };
32 32
33 const ACCOUNTS_MAX_H: f32 = 180.;33 const ACCOUNTS_MAX_H: f32 = 180.;
@@ -117,11 +117,7 @@ pub(super) fn profile_popover(
117 user: user.clone(),117 user: user.clone(),
118 };118 };
119 119
120- pop_in(120+ card.render(&entity, cx.entity(), palette(cx), &yumush.chat.avatars)
121- "profile_card",
122- card.render(&entity, cx.entity(), palette(cx), &yumush.chat.avatars),
123- anchor,
124- )
125 })121 })
126 }122 }
127 123
@@ -302,11 +298,7 @@ impl Card {
302 .then(|| report_bar(&self.reason, entity, palette)),298 .then(|| report_bar(&self.reason, entity, palette)),
303 )299 )
304 .children(divider)300 .children(divider)
305- .child(swap_in(301+ .child(div().flex().flex_col().gap(px(space::MD)).children(rows))
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- ))
310 }302 }
311 303
312 fn moderation_rows(304 fn moderation_rows(
crates/client/src/gui/settings_page.rsmodified+49 -3
@@ -2,8 +2,8 @@ use std::future::Future;
2 2
3 use crate::net::Fail;3 use crate::net::Fail;
4 use common::{4 use common::{
5- call::{DeleteUser, RemoveAvatar, UpdateAvatar, UpdateStatus, UpdateUser},5+ call::{DeleteUser, RemoveAvatar, UpdateAvatar, UpdateHue, UpdateStatus, UpdateUser},
6- model::User,6+ model::{Hue, User},
7 };7 };
8 use gpui_kit::{8 use gpui_kit::{
9 AnyElement, App, AsyncWindowContext, Context, Div, Entity, FontWeight, Hsla,9 AnyElement, App, AsyncWindowContext, Context, Div, Entity, FontWeight, Hsla,
@@ -21,7 +21,7 @@ use super::{
21 primary_button, text, widget::field,21 primary_button, text, widget::field,
22 };22 };
23 use crate::{23 use crate::{
24- gui::style::{Theme, radius, size, space, stroke, text},24+ gui::style::{self, Theme, radius, size, space, stroke, text},
25 settings::{self, FontSize},25 settings::{self, FontSize},
26 };26 };
27 27
@@ -107,6 +107,14 @@ impl Yumush {
107 Yumush::set_theme,107 Yumush::set_theme,
108 ),108 ),
109 ),109 ),
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+ ),
110 row(118 row(
111 "Font size",119 "Font size",
112 segmented(120 segmented(
@@ -180,6 +188,16 @@ impl Yumush {
180 .detach();188 .detach();
181 }189 }
182 190
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+
183 pub(super) fn save_status(&mut self, window: &mut Window, cx: &mut Context<Self>) {201 pub(super) fn save_status(&mut self, window: &mut Window, cx: &mut Context<Self>) {
184 let status = self.chat.status_input.read(cx).text().to_string();202 let status = self.chat.status_input.read(cx).text().to_string();
185 let network = self.network.clone();203 let network = self.network.clone();
@@ -280,6 +298,34 @@ fn apply_user(this: &WeakEntity<Yumush>, cx: &mut AsyncWindowContext, result: Re
280 }298 }
281 }299 }
282 300
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+
283 pub(super) fn picked_avatar(329 pub(super) fn picked_avatar(
284 cx: &App,330 cx: &App,
285 maximum: u64,331 maximum: u64,
crates/client/src/gui/share_view.rsmodified+2 -6
@@ -34,7 +34,7 @@ use super::{
34 chat::View,34 chat::View,
35 clickable, entity_action,35 clickable, entity_action,
36 media_view::into_render_image,36 media_view::into_render_image,
37- notify_error, pop_in,37+ notify_error,
38 settings_page::segmented,38 settings_page::segmented,
39 stream_stats::{stream_card, watch_stats},39 stream_stats::{stream_card, watch_stats},
40 style::{radius, size, space, text},40 style::{radius, size, space, text},
@@ -504,11 +504,7 @@ impl Yumush {
504 ))504 ))
505 .content(move |_, _, cx| {505 .content(move |_, _, cx| {
506 let entity = settings.clone();506 let entity = settings.clone();
507- pop_in(507+ settings_card(&entity, entity.read(cx), palette)
508- "share_settings_card",
509- settings_card(&entity, entity.read(cx), palette),
510- Anchor::BottomRight,
511- )
512 })508 })
513 }509 }
514 510
crates/client/src/gui/sidebar.rsmodified+12 -11
@@ -48,14 +48,19 @@ impl Yumush {
48 self.expanded_sidebar(entity, palette)48 self.expanded_sidebar(entity, palette)
49 };49 };
50 50
51- div()51+ let sidebar = div()
52 .h_full()52 .h_full()
53 .flex_shrink_0()53 .flex_shrink_0()
54 .overflow_hidden()54 .overflow_hidden()
55- .child(content)55+ .child(content);
56- .with_animation(id, motion(), move |sidebar, delta| {56+ match self.chat.sidebar_toggled {
57- sidebar.w(px(from + (to - from) * delta))57+ Some(at) if at.elapsed() < motion().duration => sidebar
58- })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+ }
59 }64 }
60 65
61 fn collapsed_sidebar(&self, entity: &Entity<Self>, palette: Palette) -> Div {66 fn collapsed_sidebar(&self, entity: &Entity<Self>, palette: Palette) -> Div {
@@ -371,6 +376,7 @@ impl Yumush {
371 tip,376 tip,
372 entity_action(entity, |yumush, _, cx| {377 entity_action(entity, |yumush, _, cx| {
373 yumush.chat.sidebar_collapsed = !yumush.chat.sidebar_collapsed;378 yumush.chat.sidebar_collapsed = !yumush.chat.sidebar_collapsed;
379+ yumush.chat.sidebar_toggled = Some(std::time::Instant::now());
374 cx.notify();380 cx.notify();
375 }),381 }),
376 )382 )
@@ -413,12 +419,7 @@ impl Yumush {
413 .gap(px(space::XL))419 .gap(px(space::XL))
414 .child(input_box(&self.chat.search_input, palette))420 .child(input_box(&self.chat.search_input, palette))
415 .children(found.map(|user| self.found_row(entity, user, palette)))421 .children(found.map(|user| self.found_row(entity, user, palette)))
416- .children(422+ .children(self.requests(entity, palette))
417- query
418- .is_empty()
419- .then(|| self.requests(entity, palette))
420- .flatten(),
421- )
422 .children(group(423 .children(group(
423 "Friends",424 "Friends",
424 palette,425 palette,
crates/client/src/gui/snippet.rsmodified+1 -0
@@ -55,6 +55,7 @@ fn snippet_row(
55 username: item.username.clone(),55 username: item.username.clone(),
56 role: Role::User,56 role: Role::User,
57 status: String::new(),57 status: String::new(),
58+ hue: None,
58 avatar_id: item.avatar_id,59 avatar_id: item.avatar_id,
59 created_at: item.created_at,60 created_at: item.created_at,
60 });61 });
crates/client/src/gui/social.rsmodified+8 -0
@@ -142,6 +142,14 @@ impl Yumush {
142 };142 };
143 143
144 let _ = this.update(cx, |yumush, cx| {144 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+ );
145 yumush.chat.friends = friends;153 yumush.chat.friends = friends;
146 yumush.chat.invitations = invitations;154 yumush.chat.invitations = invitations;
147 yumush.chat.presences = presences.into_iter().collect();155 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};
2 2
3-use common::model::{Hue, Id};3+use common::model::{Hue, Id, User};
4 use gpui_kit::{App, Global, Hsla, Rems, rems, rgb};4 use gpui_kit::{App, Global, Hsla, Rems, rems, rgb};
5 5
6 use crate::settings::FontSize;6 use crate::settings::FontSize;
@@ -104,11 +104,27 @@ impl Tokens {
104 }104 }
105 }105 }
106 106
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+
107 pub fn hue_of(id: Id) -> Hue {124 pub fn hue_of(id: Id) -> Hue {
108- let mut hasher = DefaultHasher::new();125+ CHOSEN
109- id.hash(&mut hasher);126+ .with_borrow(|chosen| chosen.get(&id).copied())
110- let picks = &Hue::ALL[..Hue::ALL.len() - 1];127+ .unwrap_or(PICKS[id.rem_euclid(PICKS.len() as Id) as usize])
111- picks[hasher.finish() as usize % picks.len()]
112 }128 }
113 129
114 fn color(value: u32) -> Hsla {130 fn color(value: u32) -> Hsla {
crates/client/src/gui/voice_stats.rsmodified+348 -573
@@ -1,32 +1,26 @@
1 use std::collections::VecDeque;1 use std::collections::VecDeque;
2 2
3 use common::{3 use common::{
4- model::{Hue, Id},4+ model::Id,
5 share::{Kind, Layer},5 share::{Kind, Layer},
6 };6 };
7-use gpui_kit::{7+use gpui_kit::{AnyElement, Div, FontWeight, Hsla, IntoElement, ParentElement, Styled, div, px};
8- Div, FontWeight, Hsla, ParentElement, Styled, assets::IconName, component::Icon, div,
9- prelude::FluentBuilder as _, px, relative,
10-};
11 8
12 use super::{9 use super::{
13 Palette,10 Palette,
14 chat::Chat,11 chat::Chat,
15- share_view::kind_icon,12+ parts::{Fill, Ink, Text, band, grow, spark, stack, track, words},
16- style::{radius, size, space, stroke, text},13+ style::{Tokens, size, space},
17- text as text_size, wave,
18 };14 };
19 use crate::media::decode::Engine;15 use crate::media::decode::Engine;
20 use crate::share::session::{LayerStats, WatchStats};16 use crate::share::session::{LayerStats, WatchStats};
21-use crate::usage::{Gpu, Usage};17+use crate::usage::Usage;
22 use crate::voice::VoiceSample;18 use crate::voice::VoiceSample;
23 19
24 pub const SAMPLE_HISTORY: usize = 60;20 pub const SAMPLE_HISTORY: usize = 60;
25-const MIRROR_HALF: f32 = size::CHIP;21+const LABEL_W: f32 = size::ROW * 2.;
26-const LAYER_W: f32 = 70.;22+const VALUE_W: f32 = size::THUMB;
27-const WATCH_LAYER_W: f32 = 64.;23+const COLUMN_W: f32 = size::TALK + size::ROW * 2.;
28-const RATE_W: f32 = 52.;
29-const VALUE_W: f32 = 76.;
30 const PING_SCALE: f32 = 150.;24 const PING_SCALE: f32 = 150.;
31 const GOOD_LOSS: f32 = 2.;25 const GOOD_LOSS: f32 = 2.;
32 const FAIR_LOSS: f32 = 8.;26 const FAIR_LOSS: f32 = 8.;
@@ -68,14 +62,6 @@ impl Quality {
68 Self::Poor => "poor",62 Self::Poor => "poor",
69 }63 }
70 }64 }
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- }
79 }65 }
80 66
81 pub fn quality(samples: &VecDeque<VoiceSample>) -> Option<Quality> {67 pub fn quality(samples: &VecDeque<VoiceSample>) -> Option<Quality> {
@@ -83,487 +69,386 @@ pub fn quality(samples: &VecDeque<VoiceSample>) -> Option<Quality> {
83 }69 }
84 70
85 pub fn stats_panel(chat: &Chat, palette: Palette) -> Div {71 pub fn stats_panel(chat: &Chat, palette: Palette) -> Div {
72+ let t = palette.tokens;
86 let share = &chat.share_sample;73 let share = &chat.share_sample;
87- div()74+ band(space::XXL)
88- .flex()75+ .items_start()
89- .flex_col()76+ .flex_wrap()
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)))
117 .child(77 .child(
118- div()78+ stack(space::XL)
119- .flex()79+ .w(px(COLUMN_W))
120- .gap(px(space::SM))80+ .child(connection(chat, t))
121- .child(stat_cell("ping", ping, color, palette))81+ .child(traffic(chat, t))
122- .child(stat_cell("jitter", jitter, color, palette))82+ .children(chat.usage.as_ref().map(|usage| machine(usage, t))),
123- .child(stat_cell("loss", loss, color, palette))
124- .child(stat_cell("buffer", buffer, palette.text, palette)),
125 )83 )
126 .child(84 .child(
127- div()85+ stack(space::XL)
128- .h(px(size::CONTROL))86+ .w(px(COLUMN_W))
129- .p(px(space::XXS))87+ .children(sending(&share.sending, t))
130- .rounded(px(radius::SM))88+ .children(watching(&share.watching, chat, t)),
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- )),
139 )89 )
140- .child(traffic(chat, palette))
141 }90 }
142 91
143-fn traffic(chat: &Chat, palette: Palette) -> Div {92+fn title(name: &'static str, sub: String, trailing: Option<Div>, t: Tokens) -> Div {
144- let up: Vec<f32> = chat.traffic.iter().map(|(up, _)| *up).collect();93+ band(space::SM)
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))
155 .child(94 .child(
156- div()95+ words(name, Text::Label, Ink::Paper, t)
157- .text_color(up_color(palette))96+ .font_weight(FontWeight::MEDIUM)
158- .child(format!("↑ {}", rate(up_latest as u32))),97+ .flex_none(),
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))),
187 )98 )
99+ .child(words(sub, Text::Caption, Ink::Faint, t))
100+ .child(grow())
101+ .children(trailing)
188 }102 }
189 103
190-fn bars(values: &[f32], max: f32, color: Hsla) -> Vec<Div> {104+fn line_row(label: AnyElement, fill: AnyElement, value: String, bad: bool, t: Tokens) -> Div {
191- let empty = SAMPLE_HISTORY.saturating_sub(values.len());105+ band(space::MD)
192- (0..empty)106+ .h(px(size::CONTROL_SM))
193- .map(|_| div().flex_1())107+ .child(div().w(px(LABEL_W)).flex_none().min_w_0().child(label))
194- .chain(108+ .child(div().flex_1().min_w_0().child(fill))
195- values109+ .child(
196- .iter()110+ words(
197- .map(|value| div().flex_1().h(px(value / max * MIRROR_HALF)).bg(color)),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(),
198 )119 )
199- .collect()
200-}
201-
202-fn up_color(palette: Palette) -> Hsla {
203- palette.tokens.hue(Hue::Violet)
204 }120 }
205 121
206-fn down_color(palette: Palette) -> Hsla {122+fn label(text: &'static str, t: Tokens) -> AnyElement {
207- palette.tokens.hue(Hue::Teal)123+ words(text, Text::Caption, Ink::Dim, t).into_any_element()
208 }124 }
209 125
210-fn sending_blocks(sending: &[(Kind, LayerStats)], palette: Palette) -> Vec<Div> {126+fn number(value: String, name: &'static str, bad: bool, t: Tokens) -> Div {
211- [Kind::Screen, Kind::Camera]127+ stack(space::XXS)
212- .into_iter()128+ .flex_1()
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))
281 .child(129 .child(
282- div()130+ words(
283- .w(px(RATE_W))131+ value,
284- .flex_none()132+ Text::Title,
285- .text_right()133+ if bad { Ink::Bad } else { Ink::Paper },
286- .text_color(palette.text)134+ t,
287- .child(rate(stats.kbps)),135+ )
136+ .font_weight(FontWeight::MEDIUM),
288 )137 )
138+ .child(words(name, Text::Caption, Ink::Faint, t))
289 }139 }
290 140
291-fn receiving_block(watching: &[(Id, Kind, WatchStats)], chat: &Chat, palette: Palette) -> Div {141+fn connection(chat: &Chat, t: Tokens) -> Div {
292- div()142+ let latest = chat.voice_samples.back();
293- .flex()143+ let quality = latest.map(Quality::of);
294- .flex_col()144+ let bad = quality == Some(Quality::Poor);
295- .gap(px(space::XS))145+ let field = |value: Option<String>| value.unwrap_or_else(|| "…".into());
296- .child(header(IconName::Eye, "Receiving", palette.text))146+ let ping = latest.map(|sample| sample.ping_ms);
297- .children(147+ let loss = latest.map(|sample| sample.traffic.loss * 100.);
298- watching148+ let word = quality.map(|quality| {
299- .iter()149+ words(
300- .map(|(user_id, kind, stats)| watch_row(chat, *user_id, *kind, stats, palette)),150+ quality.word(),
151+ Text::Caption,
152+ if bad { Ink::Bad } else { Ink::Dim },
153+ t,
301 )154 )
302-}155+ });
303 156
304-fn watch_row(chat: &Chat, user_id: Id, kind: Kind, stats: &WatchStats, palette: Palette) -> Div {157+ stack(space::MD)
305- let name = chat158+ .child(title("Connection", String::new(), word, t))
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- )
350 .child(159 .child(
351- div()160+ band(space::LG)
352- .w(px(RATE_W))161+ .child(number(
353- .flex_none()162+ field(ping.map(|ping| format!("{ping:.0}"))),
354- .text_color(palette.muted)163+ "ping ms",
355- .child(format!(164+ ping.is_some_and(|ping| ping > PING_SCALE),
356- "{} {}",165+ t,
357- stats.layer.map_or("…", |layer| layer.codec.name()),166+ ))
358- stats.engine.map_or("…", engine_label)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,
359 )),184 )),
360 )185 )
361 .child(186 .child(
362- div()187+ div().h(px(size::CONTROL_SM)).child(spark(
363- .w(px(size::ROW))188+ chat.voice_samples
364- .flex_none()189+ .iter()
365- .text_right()190+ .map(|sample| (sample.ping_ms / PING_SCALE).clamp(0., 1.))
366- .text_color(palette.text)191+ .collect(),
367- .child(rate(stats.kbps)),192+ SAMPLE_HISTORY,
368- )193+ if bad { t.bad() } else { t.paper() },
369- .child(194+ )),
370- div()
371- .w(px(RATE_W))
372- .flex_none()
373- .text_right()
374- .text_color(palette.muted)
375- .child(latency),
376 )195 )
377- .child(chip(format!("{loss:.1}%"), loss_color, palette))
378 }196 }
379 197
380-fn usage_block(usage: &Usage, palette: Palette) -> Div {198+fn traffic(chat: &Chat, t: Tokens) -> Div {
381- let memory = usage.memory;199+ let up: Vec<f32> = chat.traffic.iter().map(|(up, _)| *up).collect();
382- let total_mb = memory.total_mb.max(1) as f32;200+ let down: Vec<f32> = chat.traffic.iter().map(|(_, down)| *down).collect();
383- let cpu = column()201+ let max = up.iter().chain(&down).copied().fold(1., f32::max);
384- .child(model_header(202+ let line = |values: &[f32], ink: Hsla| {
385- IconName::Cpu,203+ div()
386- "CPU",204+ .h(px(space::MD))
387- &usage.cpu_model,205+ .child(spark(
388- palette,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,
389 ))222 ))
390- .child(dual(223+ .child(line_row(
391- "total",224+ label("down", t),
392- usage.total,225+ line(&down, t.dim()),
393- usage.machine,226+ latest(&down),
394- palette.text,227+ false,
395- palette,228+ t,
396 ))229 ))
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- )
448 }230 }
449 231
450-fn gpu_column(gpu: &Gpu, palette: Palette) -> Div {232+fn machine(usage: &Usage, t: Tokens) -> Div {
451- let machine = gpu.machine;233+ let memory = usage.memory;
452- let vram_total = machine.vram_total_mb.max(machine.vram_used_mb).max(1) as f32;234+ let total_mb = memory.total_mb.max(1) as f32;
453- column()235+ let over = |own: f32, total: f32| track(Fill::Over { own, total }, false, t).into_any_element();
454- .child(model_header(236+ let model = match usage.gpu.as_ref() {
455- IconName::MemoryStick,237+ Some(gpu) => format!("{} · {}", usage.cpu_model, gpu.model),
456- "GPU",238+ None => usage.cpu_model.to_string(),
457- &gpu.model,239+ };
458- palette,240+
459- ))241+ stack(space::XS)
460- .child(dual("3d", gpu.gfx, machine.gfx, palette.accent, palette))242+ .child(title("This machine", model, None, t))
461- .child(dual(243+ .child(line_row(
462- "video",244+ label("CPU", t),
463- gpu.video,245+ over(usage.total / 100., usage.machine / 100.),
464- machine.video,246+ format!("{:.0} / {:.0} %", usage.total, usage.machine),
465- palette.screen,247+ false,
466- palette,248+ t,
467 ))249 ))
468- .child(dual_value(250+ .children(usage.threads.map(|threads| {
469- "vram",251+ band(space::MD).children(
470- format!("{} / {}", gb(gpu.vram_mb), gb(machine.vram_used_mb)),252+ [
471- gpu.vram_mb as f32 / vram_total,253+ ("gui", threads.gui),
472- machine.vram_used_mb as f32 / vram_total,254+ ("camera", threads.camera),
473- palette.muted,255+ ("encode", threads.encode),
474- palette,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,
475 ))272 ))
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()
476 }349 }
477 350
478-fn gb(mb: u32) -> String {351+fn watching(watching: &[(Id, Kind, WatchStats)], chat: &Chat, t: Tokens) -> Option<Div> {
479- match mb {352+ if watching.is_empty() {
480- 0..1000 => format!("{mb} M"),353+ return None;
481- _ => format!("{:.1} G", mb as f32 / 1024.),
482 }354 }
483-}355+ let max = largest(watching.iter().map(|(_, _, stats)| stats.kbps));
484-356+ let latency = watching
485-fn dual(label: &'static str, own: f32, machine: f32, color: Hsla, palette: Palette) -> Div {357+ .iter()
486- dual_value(358+ .filter_map(|(_, _, stats)| stats.latency_ms)
487- label,359+ .max();
488- format!("{own:.0} / {machine:.0} %"),360+ let loss = watching
489- own / 100.,361+ .iter()
490- machine / 100.,362+ .map(|(_, _, stats)| stats.loss)
491- color,363+ .fold(0., f32::max)
492- palette,364+ * 100.;
493- )365+ let keyframes: u32 = watching.iter().map(|(_, _, stats)| stats.keyframes).sum();
494-}366+ let nacks: u32 = watching.iter().map(|(_, _, stats)| stats.nacks).sum();
495-367+ let count = watching.len();
496-fn dual_value(368+
497- label: &'static str,369+ Some(
498- value: String,370+ stack(space::XS)
499- own: f32,371+ .child(title(
500- machine: f32,372+ "Watching",
501- color: Hsla,373+ format!("{count} {}", if count == 1 { "stream" } else { "streams" }),
502- palette: Palette,374+ None,
503-) -> Div {375+ t,
504- row(376+ ))
505- label,377+ .children(watching.iter().map(|(user_id, kind, stats)| {
506- value,378+ let name = chat
507- dual_bar(own, machine, color, palette),379+ .author(*user_id)
508- palette,380+ .map_or_else(|| user_id.to_string(), |user| user.username.clone());
509- )381+ let detail = format!(
510-}382+ "{} · {}",
511-383+ kind_word(*kind),
512-fn meter(label: &'static str, percent: f32, color: Hsla, palette: Palette) -> Div {384+ stats
513- meter_value(385+ .layer
514- label,386+ .map_or("…".to_string(), |layer| resolution_text(layer, stats.fps))
515- format!("{percent:.1} %"),387+ );
516- percent / 100.,388+ let bad = Quality::of_loss(stats.loss * 100.) == Quality::Poor;
517- color,389+ line_row(
518- palette,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+ ),
519 )438 )
520 }439 }
521 440
522-fn meter_value(441+fn kind_word(kind: Kind) -> &'static str {
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 {
557 match kind {442 match kind {
558- Kind::Camera => palette.camera,443+ Kind::Camera => "camera",
559- Kind::Screen => palette.screen,444+ Kind::Screen => "screen",
560 }445 }
561 }446 }
562 447
563-fn kind_name(kind: Kind) -> &'static str {448+fn gb(mb: u32) -> String {
564- match kind {449+ match mb {
565- Kind::Camera => "Camera",450+ 0..1000 => format!("{mb} MB"),
566- Kind::Screen => "Screen",451+ _ => format!("{:.1} GB", mb as f32 / 1024.),
567 }452 }
568 }453 }
569 454
@@ -573,132 +458,22 @@ fn largest(values: impl Iterator<Item = u32>) -> f32 {
573 458
574 pub fn rate(kbps: u32) -> String {459 pub fn rate(kbps: u32) -> String {
575 match kbps {460 match kbps {
576- 0..1000 => format!("{kbps} kbps"),461+ 0..1000 => format!("{kbps} kb/s"),
577- _ => format!("{:.1} Mbps", kbps as f32 / 1000.),462+ _ => format!("{:.1} Mb/s", kbps as f32 / 1000.),
578 }463 }
579 }464 }
580 465
581 fn engine_label(engine: Engine) -> &'static str {466 fn engine_label(engine: Engine) -> &'static str {
582 match engine {467 match engine {
583- Engine::Hardware => "HW",468+ Engine::Hardware => "hardware",
584- Engine::Software => "SW",469+ Engine::Software => "software",
585 }470 }
586 }471 }
587 472
588 fn resolution_text(layer: Layer, fps: f32) -> String {473 fn resolution_text(layer: Layer, fps: f32) -> String {
589 format!(474 format!(
590- "{}p{}",475+ "{}p {}",
591 layer.quality.resolution.height(),476 layer.quality.resolution.height(),
592 fps.round() as u32477 fps.round() as u32
593 )478 )
594 }479 }
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> {
167 let Ok(info) = fs::read_to_string(path.join("fdinfo").join(fd.file_name())) else {167 let Ok(info) = fs::read_to_string(path.join("fdinfo").join(fd.file_name())) else {
168 continue;168 continue;
169 };169 };
170- if let Some(client) = client(&info) {170+ if let Some(client) = client(&info)
171- if client.pdev == pdev {171+ && client.pdev == pdev
172- clients.push(client);172+ {
173- }173+ clients.push(client);
174 }174 }
175 }175 }
176 }176 }
crates/common/src/call.rsmodified+7 -0
@@ -3,6 +3,7 @@ use bitcode::{Decode, DecodeOwned, Encode};
3 use crate::{3 use crate::{
4 constant::{MAXIMUM_AVATAR_BYTES, MAXIMUM_MESSAGE_LENGTH},4 constant::{MAXIMUM_AVATAR_BYTES, MAXIMUM_MESSAGE_LENGTH},
5 error::Error,5 error::Error,
6+ model::Hue,
6 model::{7 model::{
7 Account, AdminActionKind, AdminLogEntry, AttachmentInfo, BackupInfo, Ban, BanScope,8 Account, AdminActionKind, AdminLogEntry, AttachmentInfo, BackupInfo, Ban, BanScope,
8 Community, CommunitySummary, CommunityUsage, DayStat, Friends, Id, Invitation, InviteCode,9 Community, CommunitySummary, CommunityUsage, DayStat, Friends, Id, Invitation, InviteCode,
@@ -80,6 +81,11 @@ pub struct UpdateStatus {
80 pub status: String,81 pub status: String,
81 }82 }
82 83
84+#[derive(Debug, Clone, Encode, Decode)]
85+pub struct UpdateHue {
86+ pub hue: Option<Hue>,
87+}
88+
83 #[derive(Debug, Clone, Encode, Decode)]89 #[derive(Debug, Clone, Encode, Decode)]
84 pub struct UpdatePresence {90 pub struct UpdatePresence {
85 pub presence: Presence,91 pub presence: Presence,
@@ -635,6 +641,7 @@ calls! {
635 GetUser: User -> User;641 GetUser: User -> User;
636 UpdateUser: User -> User, |c| validate_username(&c.username);642 UpdateUser: User -> User, |c| validate_username(&c.username);
637 UpdateStatus: User -> User, |c| validate_status(&c.status);643 UpdateStatus: User -> User, |c| validate_status(&c.status);
644+ UpdateHue: User -> User;
638 UpdatePresence: User -> ();645 UpdatePresence: User -> ();
639 ListPresences: User -> Vec<(Id, Presence)>;646 ListPresences: User -> Vec<(Id, Presence)>;
640 UpdateAvatar: User -> User, |c| validate_avatar_size(&c.image, MAXIMUM_AVATAR_BYTES as u64);647 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 {
127 pub username: String,127 pub username: String,
128 pub role: Role,128 pub role: Role,
129 pub status: String,129 pub status: String,
130+ pub hue: Option<Hue>,
130 pub avatar_id: Option<Id>,131 pub avatar_id: Option<Id>,
131 pub created_at: u64,132 pub created_at: u64,
132 }133 }
crates/server/src/call/mod.rsmodified+1 -0
@@ -110,6 +110,7 @@ pub(crate) async fn dispatch(request: Request, cx: &mut Cx<'_>) -> Vec<u8> {
110 Request::GetUser(call) => serve(call, cx).await,110 Request::GetUser(call) => serve(call, cx).await,
111 Request::UpdateUser(call) => serve(call, cx).await,111 Request::UpdateUser(call) => serve(call, cx).await,
112 Request::UpdateStatus(call) => serve(call, cx).await,112 Request::UpdateStatus(call) => serve(call, cx).await,
113+ Request::UpdateHue(call) => serve(call, cx).await,
113 Request::UpdatePresence(call) => serve(call, cx).await,114 Request::UpdatePresence(call) => serve(call, cx).await,
114 Request::ListPresences(call) => serve(call, cx).await,115 Request::ListPresences(call) => serve(call, cx).await,
115 Request::UpdateAvatar(call) => serve(call, cx).await,116 Request::UpdateAvatar(call) => serve(call, cx).await,
crates/server/src/call/user.rsmodified+11 -1
@@ -1,7 +1,7 @@
1 use common::{1 use common::{
2 call::{2 call::{
3 GetAvatar, GetSettings, GetUser, ListPresences, ListSessions, RemoveAvatar, RevokeSession,3 GetAvatar, GetSettings, GetUser, ListPresences, ListSessions, RemoveAvatar, RevokeSession,
4- UpdateAvatar, UpdatePresence, UpdateStatus, UpdateUser,4+ UpdateAvatar, UpdateHue, UpdatePresence, UpdateStatus, UpdateUser,
5 },5 },
6 event::Event,6 event::Event,
7 model::{AdminAction, Id, Presence, ServerSettings, SessionInfo, User},7 model::{AdminAction, Id, Presence, ServerSettings, SessionInfo, User},
@@ -54,6 +54,16 @@ impl Handle for UpdateStatus {
54 }54 }
55 }55 }
56 56
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+
57 impl Handle for UpdatePresence {67 impl Handle for UpdatePresence {
58 async fn handle(self, me: Me, cx: &mut Cx<'_>) -> Result<(), ServerError> {68 async fn handle(self, me: Me, cx: &mut Cx<'_>) -> Result<(), ServerError> {
59 let me = me.user()?;69 let me = me.user()?;
crates/server/src/db/schema.sqlmodified+1 -0
@@ -4,6 +4,7 @@ CREATE TABLE user (
4 password_hash TEXT NOT NULL,4 password_hash TEXT NOT NULL,
5 role TEXT NOT NULL,5 role TEXT NOT NULL,
6 status TEXT NOT NULL DEFAULT '',6 status TEXT NOT NULL DEFAULT '',
7+ hue TEXT,
7 presence TEXT NOT NULL,8 presence TEXT NOT NULL,
8 suspended INTEGER NOT NULL DEFAULT 0,9 suspended INTEGER NOT NULL DEFAULT 0,
9 suspended_until INTEGER,10 suspended_until INTEGER,
crates/server/src/db/user.rsmodified+16 -2
@@ -1,6 +1,6 @@
1 use common::{1 use common::{
2 error::Error,2 error::Error,
3- model::{Account, Id, Presence, Role, User},3+ model::{Account, Hue, Id, Presence, Role, User},
4 permission,4 permission,
5 time::now_ms,5 time::now_ms,
6 };6 };
@@ -8,7 +8,7 @@ use common::{
8 use super::{Connection, Reader, all, maybe, one, run};8 use super::{Connection, Reader, all, maybe, one, run};
9 use crate::error::{ServerError, ensure_with};9 use crate::error::{ServerError, ensure_with};
10 10
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";
12 12
13 pub fn row(r: &mut Reader) -> Result<User, ServerError> {13 pub fn row(r: &mut Reader) -> Result<User, ServerError> {
14 Ok(User {14 Ok(User {
@@ -16,6 +16,9 @@ pub fn row(r: &mut Reader) -> Result<User, ServerError> {
16 username: r.get()?,16 username: r.get()?,
17 role: r.named()?,17 role: r.named()?,
18 status: r.get()?,18 status: r.get()?,
19+ hue: r
20+ .get::<Option<String>>()?
21+ .and_then(|text| Hue::parse(&text)),
19 avatar_id: r.get()?,22 avatar_id: r.get()?,
20 created_at: r.get()?,23 created_at: r.get()?,
21 })24 })
@@ -92,6 +95,17 @@ pub async fn update(id: Id, username: &str, db: &Connection) -> Result<User, Ser
92 read(id, db).await95 read(id, db).await
93 }96 }
94 97
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+
95 pub async fn update_status(id: Id, status: &str, db: &Connection) -> Result<User, ServerError> {109 pub async fn update_status(id: Id, status: &str, db: &Connection) -> Result<User, ServerError> {
96 run(110 run(
97 db,111 db,