diff --git a/crates/client/src/gui.rs b/crates/client/src/gui.rs index 12b7f09..74689d9 100644 --- a/crates/client/src/gui.rs +++ b/crates/client/src/gui.rs @@ -304,7 +304,7 @@ pub fn millis_time(millis: u64, format: &str) -> String { .to_string() } -pub use parts::{motion, pop_in, swap_in}; +pub use parts::motion; pub fn hoverable(id: impl Into, element: Div, palette: Palette) -> Stateful
{ hoverable_with(id, element, palette.hover) @@ -655,6 +655,7 @@ impl Yumush { self.accounts.sign_in(&user, token); self.request_user_avatar(&user, cx); self.chat.muted = mutes::load(user.id); + style::remember(&[&user]); self.user = Some(user); self.change_page(Route::Chat, window, cx); self.load_communities(window, cx); diff --git a/crates/client/src/gui/camera_view.rs b/crates/client/src/gui/camera_view.rs index 3b0a41e..cbf3ff7 100644 --- a/crates/client/src/gui/camera_view.rs +++ b/crates/client/src/gui/camera_view.rs @@ -226,24 +226,26 @@ impl Yumush { .into_iter() .map(|source| stage_tile(entity, self, palette, source)) .collect(); - if tiles.is_empty() { - return Some(self.voices(palette).into_any_element()); - } - - Some( + let strip = (!tiles.is_empty()).then(|| { div() .id("stage_strip") .flex() .flex_shrink_0() .h(px(STRIP_H)) .gap(px(space::SM)) - .p(px(space::SM)) - .bg(palette.window) + .px(px(space::XL)) + .pb(px(space::SM)) .overflow_x_scroll() - .border_b_1() - .border_color(palette.border) .children(tiles) - .into_any_element(), + }); + + Some( + div() + .flex() + .flex_col() + .flex_shrink_0() + .child(self.voices(palette)) + .children(strip), ) } @@ -254,7 +256,7 @@ impl Yumush { .voice_community() .map(|community_id| self.chat.voice_ids(community_id)) .unwrap_or_default() - .into_iter() + .iter() .filter_map(|id| self.chat.author(*id)) .map(|user| { let speaking = self.chat.waves.speaking.contains(&user.id); diff --git a/crates/client/src/gui/chat.rs b/crates/client/src/gui/chat.rs index 71bef73..9af485d 100644 --- a/crates/client/src/gui/chat.rs +++ b/crates/client/src/gui/chat.rs @@ -1,4 +1,4 @@ -use super::style::{radius, size, space, stroke, text}; +use super::style::{self, radius, size, space, stroke, text}; use super::text; use crate::gui::CLOCK; use std::{ @@ -19,7 +19,7 @@ use crate::gui::{ composer::{self, Composer}, entity_action, hoverable, media_view::{self, Media}, - message_actions, millis_time, new_input, notify_error, palette, poll, pop_in, presence_avatar, + message_actions, millis_time, new_input, notify_error, palette, poll, presence_avatar, primary_button, profile::profile_popover, rank_tag, @@ -145,6 +145,7 @@ pub struct Chat { pub(super) found: Option, pub(super) invite: InviteLookup, pub(super) sidebar_collapsed: bool, + pub(super) sidebar_toggled: Option, pub(super) composer: Composer, pub(super) drafts: HashMap, pub(super) poll_question: Entity, @@ -390,6 +391,7 @@ impl Chat { found: None, invite: InviteLookup::Idle, sidebar_collapsed: false, + sidebar_toggled: None, view: View::Chat, section: 0, username_input: editable_input("Username...", Yumush::save_username, window, cx), @@ -617,7 +619,17 @@ impl Chat { Event::CommunityUpdated(community) | Event::CommunityAdded(community) => { self.insert_community(community) } - Event::FriendsUpdated(friends) => self.friends = friends, + Event::FriendsUpdated(friends) => { + style::remember( + &friends + .friends + .iter() + .chain(&friends.incoming) + .chain(&friends.outgoing) + .collect::>(), + ); + self.friends = friends; + } Event::InvitationsUpdated(invitations) => self.invitations = invitations, Event::CommunityDeleted { community_id } | Event::Removed { community_id, .. } => { self.remove_community(community_id) @@ -882,6 +894,7 @@ impl Chat { } fn insert_member(&mut self, member: Member) { + style::remember(&[&member.user]); self.remove_member(member.user.id); self.members.push(member); self.members.sort_by_key(|member| member.user.id); @@ -995,6 +1008,7 @@ impl Chat { } pub fn update_member(&mut self, user: &User) { + style::remember(&[user]); let peers = self .communities .iter_mut() @@ -1322,6 +1336,7 @@ impl Yumush { .min_w_0() .flex() .flex_col() + .relative() .bg(palette.window) .overflow_hidden() .children(self.announcement_banner(entity, palette)) @@ -1343,40 +1358,42 @@ impl Yumush { .children(self.stage_strip(entity, themed)) .children(self.unread_bar(entity, themed)) .children(self.poll_banner(entity, themed)) - .child( - div() - .flex_1() - .min_h_0() - .flex() - .child(div().flex_1().min_w_0().flex().flex_col().map(|panel| { - match self.inline_viewer(entity, themed) { - Some(viewer) => panel.child(viewer), - None => match self.stage_grid(entity, themed) { - Some(grid) => panel.child(grid), - None => panel - .child(self.message_area(entity, themed)) - .child(self.composer(entity, themed, cx)), - }, - } - })) - .children(self.stats_side(palette)), - ), + .child(div().flex_1().min_h_0().flex().child( + div().flex_1().min_w_0().flex().flex_col().map(|panel| { + match self.inline_viewer(entity, themed) { + Some(viewer) => panel.child(viewer), + None => match self.stage_grid(entity, themed) { + Some(grid) => panel.child(grid), + None => panel + .child(self.message_area(entity, themed)) + .child(self.composer(entity, themed, cx)), + }, + } + }), + )), None => panel.child(empty_state(palette)), }, }) + .children(self.stats_sheet(palette)) .children(self.dock(entity, palette, cx)) } - fn stats_side(&self, palette: Palette) -> Option { - (self.chat.stats_open && self.in_stage_chat()).then(|| { + fn stats_sheet(&self, palette: Palette) -> Option { + (self.chat.stats_open && self.chat.voice_community().is_some()).then(|| { div() - .id("stats_side") - .w(px(size::SHEET)) - .flex_shrink_0() - .p(px(space::MD)) - .border_l_1() - .border_color(palette.border) + .id("stats_sheet") + .absolute() + .right(px(space::LG)) + .bottom(px(size::ROW + space::MD + space::SM)) + .max_w(relative(0.95)) + .max_h(relative(0.8)) .overflow_y_scroll() + .p(px(space::XL)) + .rounded(px(radius::LG)) + .border_1() + .border_color(palette.border) + .bg(palette.tokens.raise()) + .shadow_lg() .child(voice_stats::stats_panel(&self.chat, palette)) }) } @@ -1835,6 +1852,12 @@ impl Yumush { .users .insert(member.user.id, member.user.clone()); } + style::remember( + &members + .iter() + .map(|member| &member.user) + .collect::>(), + ); let old = std::mem::replace(&mut yumush.chat.members, members); yumush .chat @@ -1864,6 +1887,7 @@ impl Yumush { }; let _ = this.update(cx, |yumush, cx| { yumush.request_user_avatar(&user, cx); + style::remember(&[&user]); yumush.chat.users.insert(user.id, user); cx.notify(); }); @@ -2662,88 +2686,84 @@ fn members_popover(entity: &Entity, yumush: &Yumush, palette: Palette) - .content(move |_, _, _| { let entity = entity.clone(); - pop_in( - "members_list", - div() - .w(px(size::SIDEBAR)) - .p(px(space::XS)) - .flex() - .flex_col() - .rounded(px(radius::LG)) - .bg(palette.field) - .children(members.iter().map( - |MemberRow { - user, - rank, - in_voice, - muted, - presence, - }| { - profile_popover( - format!("member_{}", user.id), - Anchor::TopRight, - user, - &entity, - hoverable( - format!("member_trigger_{}", user.id), - div() - .h(px(size::CONTROL)) - .px(px(space::SM)) - .flex() - .items_center() - .gap(px(space::SM)) - .rounded(px(radius::MD)) - .child(presence_avatar( - avatar( - palette, - user, - px(size::ICON), - text(text::CAPTION), - &avatars, - ), - *presence, - px(size::ICON), + div() + .w(px(size::SIDEBAR)) + .p(px(space::XS)) + .flex() + .flex_col() + .rounded(px(radius::LG)) + .bg(palette.field) + .children(members.iter().map( + |MemberRow { + user, + rank, + in_voice, + muted, + presence, + }| { + profile_popover( + format!("member_{}", user.id), + Anchor::TopRight, + user, + &entity, + hoverable( + format!("member_trigger_{}", user.id), + div() + .h(px(size::CONTROL)) + .px(px(space::SM)) + .flex() + .items_center() + .gap(px(space::SM)) + .rounded(px(radius::MD)) + .child(presence_avatar( + avatar( palette, - )) - .child( - div() - .flex_1() - .min_w_0() - .flex() - .flex_col() - .child( - div() - .flex() - .items_center() - .gap(px(space::SM)) - .child(user.username.clone()) - .children(rank_tag(*rank, palette)) - .children(in_voice.then(|| { - Icon::new(IconName::Headphones) - .size(px(size::ICON_SM)) - .text_color(palette.muted) - })) - .children(muted.then(|| { - Icon::new(IconName::MicOff) - .size(px(size::ICON_SM)) - .text_color(palette.danger) - })), - ) - .children((!user.status.is_empty()).then(|| { - div() - .text_size(text(text::CAPTION)) - .text_color(palette.muted) - .truncate() - .child(user.status.clone()) - })), + user, + px(size::ICON), + text(text::CAPTION), + &avatars, ), - palette, - ), - ) - }, - )), - Anchor::TopRight, - ) + *presence, + px(size::ICON), + palette, + )) + .child( + div() + .flex_1() + .min_w_0() + .flex() + .flex_col() + .child( + div() + .flex() + .items_center() + .gap(px(space::SM)) + .child(user.username.clone()) + .children(rank_tag(*rank, palette)) + .children(in_voice.then(|| { + Icon::new(IconName::Headphones) + .size(px(size::ICON_SM)) + .text_color(palette.muted) + })) + .children(muted.then(|| { + Icon::new(IconName::MicOff) + .size(px(size::ICON_SM)) + .text_color(palette.danger) + })), + ) + .children((!user.status.is_empty()).then(|| { + div() + .text_size(text(text::CAPTION)) + .text_color(palette.muted) + .truncate() + .child(user.status.clone()) + })), + ), + palette, + ), + ) + }, + )) }) } diff --git a/crates/client/src/gui/composer.rs b/crates/client/src/gui/composer.rs index 1c47ac9..aa78421 100644 --- a/crates/client/src/gui/composer.rs +++ b/crates/client/src/gui/composer.rs @@ -33,7 +33,7 @@ use gpui_kit::{ use super::{ Palette, Trigger, Yumush, chat::{Chat, TYPING_SEND_INTERVAL}, - clickable, hoverable, new_input, notify_error, pop_in, primary_button, + clickable, hoverable, new_input, notify_error, primary_button, }; actions!(composer, [Bold, Italic, Code, Strike]); @@ -550,35 +550,31 @@ pub fn format_popover(palette: Palette) -> impl IntoElement { palette, )) .content(move |_, _, _| { - pop_in( - "format_list", - panel(palette) - .w(px(size::SHEET)) - .p(px(space::SM)) - .flex() - .flex_col() - .gap(px(space::SM)) - .text_size(text(text::CAPTION)) - .children(FORMAT_ROWS.map(|(syntax, shortcut)| { - div() - .flex() - .items_center() - .gap(px(space::MD)) - .child( - div() - .w(px(size::THUMB)) - .text_color(palette.muted) - .child(syntax), - ) - .child(div().flex_1().child(TextView::markdown(syntax, syntax))) - .child( - div() - .text_color(palette.muted) - .child(shortcut_label(shortcut)), - ) - })), - Anchor::BottomLeft, - ) + panel(palette) + .w(px(size::SHEET)) + .p(px(space::SM)) + .flex() + .flex_col() + .gap(px(space::SM)) + .text_size(text(text::CAPTION)) + .children(FORMAT_ROWS.map(|(syntax, shortcut)| { + div() + .flex() + .items_center() + .gap(px(space::MD)) + .child( + div() + .w(px(size::THUMB)) + .text_color(palette.muted) + .child(syntax), + ) + .child(div().flex_1().child(TextView::markdown(syntax, syntax))) + .child( + div() + .text_color(palette.muted) + .child(shortcut_label(shortcut)), + ) + })) }) } @@ -645,160 +641,148 @@ pub fn plus_popover(chat: &Chat, entity: &Entity, palette: Palette) -> i if entity.read(cx).chat.plus_menu == PlusMenu::Menu { let file = entity.clone(); let poll = entity.clone(); - return pop_in( - "plus_menu", - panel(palette) - .w(px(size::SIDEBAR)) - .p(px(space::XS)) - .flex() - .flex_col() - .gap(px(space::XS)) - .child(plus_row( - "plus_file", - IconName::File, - "File", - palette, - move |window, cx| { - popover.update(cx, |state, cx| state.dismiss(window, cx)); - file.update(cx, |yumush, cx| yumush.attach_files(window, cx)); - }, - )) - .child(plus_row( - "plus_poll", - IconName::ChartBar, - "Poll", - palette, - move |_, cx| { - poll.update(cx, |yumush, cx| { - yumush.chat.plus_menu = PlusMenu::Poll; - cx.notify(); - }) - }, - )), - Anchor::BottomLeft, - ) - .into_any_element(); + return panel(palette) + .w(px(size::SIDEBAR)) + .p(px(space::XS)) + .flex() + .flex_col() + .gap(px(space::XS)) + .child(plus_row( + "plus_file", + IconName::File, + "File", + palette, + move |window, cx| { + popover.update(cx, |state, cx| state.dismiss(window, cx)); + file.update(cx, |yumush, cx| yumush.attach_files(window, cx)); + }, + )) + .child(plus_row( + "plus_poll", + IconName::ChartBar, + "Poll", + palette, + move |_, cx| { + poll.update(cx, |yumush, cx| { + yumush.chat.plus_menu = PlusMenu::Poll; + cx.notify(); + }) + }, + )) + .into_any_element(); } let toggle = entity.clone(); let toggle_public = entity.clone(); let duration_entity = entity.clone(); let submit = entity.clone(); - pop_in( - "poll_form", - panel(palette) - .w(px(size::POPOVER)) - .p(px(space::SM)) - .flex() - .flex_col() - .gap(px(space::SM)) - .text_size(text(text::CAPTION)) - .child(compact_field(palette, &question)) - .children(options.iter().enumerate().map(|(index, option)| { - let remove = entity.clone(); - let trailing_blank = - index + 1 == options.len() && option_text(option, cx).is_empty(); + panel(palette) + .w(px(size::POPOVER)) + .p(px(space::SM)) + .flex() + .flex_col() + .gap(px(space::SM)) + .text_size(text(text::CAPTION)) + .child(compact_field(palette, &question)) + .children(options.iter().enumerate().map(|(index, option)| { + let remove = entity.clone(); + let trailing_blank = + index + 1 == options.len() && option_text(option, cx).is_empty(); + div() + .flex() + .items_center() + .gap(px(space::SM)) + .child( + div() + .flex_1() + .min_w_0() + .child(compact_field(palette, option)), + ) + .children( + (options.len() > MINIMUM_POLL_OPTIONS && !trailing_blank).then(|| { + icon_button( + format!("poll_remove_{index}"), + palette, + IconName::Close, + "Remove option", + move |_, cx| { + remove.update(cx, |yumush, cx| { + yumush.remove_poll_option(index, cx) + }); + }, + ) + }), + ) + })) + .child( + div() + .flex() + .items_center() + .gap(px(space::XS)) + .text_color(palette.muted) + .child(Icon::new(IconName::Timer).size(px(size::ICON_SM))) + .children(POLL_DURATIONS.map(|(label, seconds)| { + let set = duration_entity.clone(); + let active = duration == seconds; + clickable(label, palette, move |_, cx| { + set.update(cx, |yumush, cx| { + yumush.chat.poll_duration = seconds; + cx.notify(); + }) + }) + .px(px(space::SM)) + .py(px(space::XXS)) + .rounded(px(radius::SM)) + .text_color(if active { + palette.accent + } else { + palette.muted + }) + .when(active, |this| this.bg(palette.tokens.press())) + .child(label) + })), + ) + .child( + div().flex().items_center().justify_between().child( div() .flex() .items_center() - .gap(px(space::SM)) + .gap(px(space::MD)) .child( - div() - .flex_1() - .min_w_0() - .child(compact_field(palette, option)), - ) - .children( - (options.len() > MINIMUM_POLL_OPTIONS && !trailing_blank).then( - || { - icon_button( - format!("poll_remove_{index}"), - palette, - IconName::Close, - "Remove option", - move |_, cx| { - remove.update(cx, |yumush, cx| { - yumush.remove_poll_option(index, cx) - }); - }, - ) - }, - ), + Checkbox::new("poll_multiple") + .label("Multiple answers") + .checked(multiple) + .on_click(move |_, _, cx| { + toggle.update(cx, |yumush, cx| { + yumush.chat.poll_multiple = !yumush.chat.poll_multiple; + cx.notify(); + }) + }), ) - })) - .child( - div() - .flex() - .items_center() - .gap(px(space::XS)) - .text_color(palette.muted) - .child(Icon::new(IconName::Timer).size(px(size::ICON_SM))) - .children(POLL_DURATIONS.map(|(label, seconds)| { - let set = duration_entity.clone(); - let active = duration == seconds; - clickable(label, palette, move |_, cx| { - set.update(cx, |yumush, cx| { - yumush.chat.poll_duration = seconds; - cx.notify(); - }) - }) - .px(px(space::SM)) - .py(px(space::XXS)) - .rounded(px(radius::SM)) - .text_color(if active { - palette.accent - } else { - palette.muted - }) - .when(active, |this| this.bg(palette.tokens.press())) - .child(label) - })), - ) - .child( - div().flex().items_center().justify_between().child( - div() - .flex() - .items_center() - .gap(px(space::MD)) - .child( - Checkbox::new("poll_multiple") - .label("Multiple answers") - .checked(multiple) - .on_click(move |_, _, cx| { - toggle.update(cx, |yumush, cx| { - yumush.chat.poll_multiple = - !yumush.chat.poll_multiple; - cx.notify(); - }) - }), - ) - .child( - Checkbox::new("poll_public") - .label("Show voters") - .checked(public) - .on_click(move |_, _, cx| { - toggle_public.update(cx, |yumush, cx| { - yumush.toggle_poll_public(cx) - }) - }), - ), - ), - ) - .child( - primary_button("poll_create", palette, move |window, cx| { - if submit.update(cx, |yumush, cx| yumush.send_poll(window, cx)) { - popover.update(cx, |state, cx| state.dismiss(window, cx)); - } - }) - .h(px(size::CONTROL_SM)) - .flex() - .items_center() - .justify_center() - .rounded(px(radius::MD)) - .child("Create"), + .child( + Checkbox::new("poll_public") + .label("Show voters") + .checked(public) + .on_click(move |_, _, cx| { + toggle_public + .update(cx, |yumush, cx| yumush.toggle_poll_public(cx)) + }), + ), ), - Anchor::BottomLeft, - ) - .into_any_element() + ) + .child( + primary_button("poll_create", palette, move |window, cx| { + if submit.update(cx, |yumush, cx| yumush.send_poll(window, cx)) { + popover.update(cx, |state, cx| state.dismiss(window, cx)); + } + }) + .h(px(size::CONTROL_SM)) + .flex() + .items_center() + .justify_center() + .rounded(px(radius::MD)) + .child("Create"), + ) + .into_any_element() }) } diff --git a/crates/client/src/gui/message_actions.rs b/crates/client/src/gui/message_actions.rs index 9734f5a..a407f2b 100644 --- a/crates/client/src/gui/message_actions.rs +++ b/crates/client/src/gui/message_actions.rs @@ -24,7 +24,7 @@ use super::{ chat::{Chat, ReportTarget}, clickable, composer::trigger_icon, - entity_action, millis_time, notify_error, pop_in, primary_button, sidebar, + entity_action, millis_time, notify_error, primary_button, sidebar, style::{radius, size, space, text}, widget::{field, icon_button, panel, spawn_done}, }; @@ -99,40 +99,31 @@ pub fn react_popover( )) .content(move |_, _, cx| { let popover = cx.entity(); - pop_in( - "react_list", - panel(palette) + panel(palette) + .flex() + .gap(px(space::XXS)) + .p(px(space::XS)) + .children(REACTIONS.map(|emoji| { + let entity = entity.clone(); + let popover = popover.clone(); + clickable( + format!("react_{emoji}_{message_id}"), + palette, + move |window, cx| { + popover.update(cx, |state, cx| state.dismiss(window, cx)); + entity.update(cx, |yumush, cx| { + yumush.toggle_reaction(message_id, emoji.to_string(), window, cx) + }); + }, + ) + .size(px(size::CONTROL_SM)) .flex() - .gap(px(space::XXS)) - .p(px(space::XS)) - .children(REACTIONS.map(|emoji| { - let entity = entity.clone(); - let popover = popover.clone(); - clickable( - format!("react_{emoji}_{message_id}"), - palette, - move |window, cx| { - popover.update(cx, |state, cx| state.dismiss(window, cx)); - entity.update(cx, |yumush, cx| { - yumush.toggle_reaction( - message_id, - emoji.to_string(), - window, - cx, - ) - }); - }, - ) - .size(px(size::CONTROL_SM)) - .flex() - .items_center() - .justify_center() - .rounded(px(radius::MD)) - .text_size(text(text::BODY)) - .child(emoji) - })), - Anchor::TopRight, - ) + .items_center() + .justify_center() + .rounded(px(radius::MD)) + .text_size(text(text::BODY)) + .child(emoji) + })) }) } @@ -295,27 +286,23 @@ pub fn search_popover(chat: &Chat, entity: &Entity, palette: Palette) -> )) .content(move |_, _, cx| { let popover = cx.entity(); - pop_in( - "search_list", - panel(palette) - .w(px(size::POPOVER)) - .p(px(space::XS)) - .flex() - .flex_col() - .gap(px(space::XS)) - .child(sidebar::input_box(&input, palette)) - .children(hits.iter().map(|hit| { - jump_row("search_hit", hit, &entity, &popover, palette) - .children(hit.time.as_ref().map(|time| { - div() - .flex_shrink_0() - .text_color(palette.muted) - .child(time.clone()) - })) - .child(div().flex_1().min_w_0().truncate().child(hit.body.clone())) - })), - Anchor::TopRight, - ) + panel(palette) + .w(px(size::POPOVER)) + .p(px(space::XS)) + .flex() + .flex_col() + .gap(px(space::XS)) + .child(sidebar::input_box(&input, palette)) + .children(hits.iter().map(|hit| { + jump_row("search_hit", hit, &entity, &popover, palette) + .children(hit.time.as_ref().map(|time| { + div() + .flex_shrink_0() + .text_color(palette.muted) + .child(time.clone()) + })) + .child(div().flex_1().min_w_0().truncate().child(hit.body.clone())) + })) }) } @@ -341,26 +328,22 @@ pub fn pins_popover(chat: &Chat, entity: &Entity, palette: Palette) -> i .trigger(trigger_icon("pins_trigger", IconName::Pin, 24., palette)) .content(move |_, _, cx| { let popover = cx.entity(); - pop_in( - "pins_list", - panel(palette) - .w(px(size::POPOVER)) - .p(px(space::XS)) - .flex() - .flex_col() - .gap(px(space::XXS)) - .children(pins.iter().map(|hit| { - jump_row("pin_hit", hit, &entity, &popover, palette).child( - div() - .flex_1() - .min_w_0() - .truncate() - .text_color(palette.muted) - .child(hit.body.clone()), - ) - })), - Anchor::TopRight, - ) + panel(palette) + .w(px(size::POPOVER)) + .p(px(space::XS)) + .flex() + .flex_col() + .gap(px(space::XXS)) + .children(pins.iter().map(|hit| { + jump_row("pin_hit", hit, &entity, &popover, palette).child( + div() + .flex_1() + .min_w_0() + .truncate() + .text_color(palette.muted) + .child(hit.body.clone()), + ) + })) }) } diff --git a/crates/client/src/gui/parts.rs b/crates/client/src/gui/parts.rs index 0468657..6f3e656 100644 --- a/crates/client/src/gui/parts.rs +++ b/crates/client/src/gui/parts.rs @@ -413,38 +413,6 @@ pub fn spark(values: Vec, slots: usize, color: Hsla) -> AnyElement { super::wave::line_of(values, slots, color).into_any_element() } -const MOTION_TRAVEL: f32 = 6.; - pub fn motion() -> gpui_kit::Animation { gpui_kit::Animation::new(Duration::from_millis(160)).with_easing(gpui_kit::ease_out_quint()) } - -pub fn pop_in( - id: impl Into, - element: E, - anchor: gpui_kit::Anchor, -) -> gpui_kit::AnimationElement { - let travel = if anchor.is_bottom() { - MOTION_TRAVEL - } else { - -MOTION_TRAVEL - }; - gpui_kit::AnimationExt::with_animation(element, id, motion(), move |element, delta| { - element.top(px(travel * (1. - delta))).opacity(delta) - }) -} - -pub fn swap_in( - id: impl Into, - element: E, - forward: bool, -) -> gpui_kit::AnimationElement { - let travel = if forward { - MOTION_TRAVEL - } else { - -MOTION_TRAVEL - }; - gpui_kit::AnimationExt::with_animation(element, id, motion(), move |element, delta| { - element.left(px(travel * (1. - delta))).opacity(delta) - }) -} diff --git a/crates/client/src/gui/poll.rs b/crates/client/src/gui/poll.rs index e73524f..2abfc5a 100644 --- a/crates/client/src/gui/poll.rs +++ b/crates/client/src/gui/poll.rs @@ -11,7 +11,7 @@ use gpui_kit::{ use super::{ Palette, Tooltip as _, Trigger, Yumush, avatar, chat::Chat, - clickable, hoverable, pop_in, + clickable, hoverable, style::{radius, size, space, text}, text, widget::{icon_button, panel, spawn_done}, @@ -143,19 +143,15 @@ fn voters_popover(key: &str, poll: &Poll, entity: &Entity, palette: Pale }) })) }); - pop_in( - list.clone(), - panel(palette) - .w(px(size::SIDEBAR)) - .id(list.clone()) - .max_h(px(size::POPOVER)) - .overflow_y_scroll() - .p(px(space::SM)) - .flex() - .flex_col() - .children(rows), - Anchor::BottomLeft, - ) + panel(palette) + .w(px(size::SIDEBAR)) + .id(list.clone()) + .max_h(px(size::POPOVER)) + .overflow_y_scroll() + .p(px(space::SM)) + .flex() + .flex_col() + .children(rows) }) .into_any_element() } diff --git a/crates/client/src/gui/profile.rs b/crates/client/src/gui/profile.rs index e2add24..e0b727f 100644 --- a/crates/client/src/gui/profile.rs +++ b/crates/client/src/gui/profile.rs @@ -27,7 +27,7 @@ use super::style::{radius, size, space, stroke, text}; use super::widget::{panel, spawn_done}; use super::{ DAY_YEAR, Palette, Trigger, Yumush, avatar, clickable, entity_action, input_dialog, - millis_time, notify_error, palette, pop_in, presence_color, rank_tag, swap_in, text, + millis_time, notify_error, palette, presence_color, rank_tag, text, }; const ACCOUNTS_MAX_H: f32 = 180.; @@ -117,11 +117,7 @@ pub(super) fn profile_popover( user: user.clone(), }; - pop_in( - "profile_card", - card.render(&entity, cx.entity(), palette(cx), &yumush.chat.avatars), - anchor, - ) + card.render(&entity, cx.entity(), palette(cx), &yumush.chat.avatars) }) } @@ -302,11 +298,7 @@ impl Card { .then(|| report_bar(&self.reason, entity, palette)), ) .children(divider) - .child(swap_in( - ("profile_rows", self.card_menu as usize), - div().flex().flex_col().gap(px(space::MD)).children(rows), - self.card_menu != CardMenu::Main, - )) + .child(div().flex().flex_col().gap(px(space::MD)).children(rows)) } fn moderation_rows( diff --git a/crates/client/src/gui/settings_page.rs b/crates/client/src/gui/settings_page.rs index 0ba10c3..45f72cd 100644 --- a/crates/client/src/gui/settings_page.rs +++ b/crates/client/src/gui/settings_page.rs @@ -2,8 +2,8 @@ use std::future::Future; use crate::net::Fail; use common::{ - call::{DeleteUser, RemoveAvatar, UpdateAvatar, UpdateStatus, UpdateUser}, - model::User, + call::{DeleteUser, RemoveAvatar, UpdateAvatar, UpdateHue, UpdateStatus, UpdateUser}, + model::{Hue, User}, }; use gpui_kit::{ AnyElement, App, AsyncWindowContext, Context, Div, Entity, FontWeight, Hsla, @@ -21,7 +21,7 @@ use super::{ primary_button, text, widget::field, }; use crate::{ - gui::style::{Theme, radius, size, space, stroke, text}, + gui::style::{self, Theme, radius, size, space, stroke, text}, settings::{self, FontSize}, }; @@ -107,6 +107,14 @@ impl Yumush { Yumush::set_theme, ), ), + row( + "Your hue", + hue_picker( + self.user.as_ref().map(|user| style::hue_of(user.id)), + entity, + palette, + ), + ), row( "Font size", segmented( @@ -180,6 +188,16 @@ impl Yumush { .detach(); } + pub(super) fn save_hue(&mut self, hue: Hue, window: &mut Window, cx: &mut Context) { + let network = self.network.clone(); + + cx.spawn_in(window, async move |this, cx| { + let result = network.call(UpdateHue { hue: Some(hue) }).await; + apply_user(&this, cx, result); + }) + .detach(); + } + pub(super) fn save_status(&mut self, window: &mut Window, cx: &mut Context) { let status = self.chat.status_input.read(cx).text().to_string(); let network = self.network.clone(); @@ -280,6 +298,34 @@ fn apply_user(this: &WeakEntity, cx: &mut AsyncWindowContext, result: Re } } +fn hue_picker(current: Option, entity: &Entity, palette: Palette) -> Div { + let t = palette.tokens; + div() + .flex() + .items_center() + .gap(px(space::XS)) + .children(style::PICKS.iter().map(|&hue| { + let entity = entity.clone(); + let on = current == Some(hue); + div() + .id(hue.as_str()) + .flex() + .items_center() + .h(px(size::CONTROL_SM)) + .px(px(space::XS)) + .cursor_pointer() + .child( + div() + .w(px(size::CHIP)) + .h(px(if on { stroke::LINE * 2. } else { stroke::LINE })) + .bg(t.hue(hue)), + ) + .on_click(move |_, window, cx| { + entity.update(cx, |yumush, cx| yumush.save_hue(hue, window, cx)) + }) + })) +} + pub(super) fn picked_avatar( cx: &App, maximum: u64, diff --git a/crates/client/src/gui/share_view.rs b/crates/client/src/gui/share_view.rs index 472011f..0529542 100644 --- a/crates/client/src/gui/share_view.rs +++ b/crates/client/src/gui/share_view.rs @@ -34,7 +34,7 @@ use super::{ chat::View, clickable, entity_action, media_view::into_render_image, - notify_error, pop_in, + notify_error, settings_page::segmented, stream_stats::{stream_card, watch_stats}, style::{radius, size, space, text}, @@ -504,11 +504,7 @@ impl Yumush { )) .content(move |_, _, cx| { let entity = settings.clone(); - pop_in( - "share_settings_card", - settings_card(&entity, entity.read(cx), palette), - Anchor::BottomRight, - ) + settings_card(&entity, entity.read(cx), palette) }) } diff --git a/crates/client/src/gui/sidebar.rs b/crates/client/src/gui/sidebar.rs index e0c1dcd..b870905 100644 --- a/crates/client/src/gui/sidebar.rs +++ b/crates/client/src/gui/sidebar.rs @@ -48,14 +48,19 @@ impl Yumush { self.expanded_sidebar(entity, palette) }; - div() + let sidebar = div() .h_full() .flex_shrink_0() .overflow_hidden() - .child(content) - .with_animation(id, motion(), move |sidebar, delta| { - sidebar.w(px(from + (to - from) * delta)) - }) + .child(content); + match self.chat.sidebar_toggled { + Some(at) if at.elapsed() < motion().duration => sidebar + .with_animation(id, motion(), move |sidebar, delta| { + sidebar.w(px(from + (to - from) * delta)) + }) + .into_any_element(), + _ => sidebar.w(px(to)).into_any_element(), + } } fn collapsed_sidebar(&self, entity: &Entity, palette: Palette) -> Div { @@ -371,6 +376,7 @@ impl Yumush { tip, entity_action(entity, |yumush, _, cx| { yumush.chat.sidebar_collapsed = !yumush.chat.sidebar_collapsed; + yumush.chat.sidebar_toggled = Some(std::time::Instant::now()); cx.notify(); }), ) @@ -413,12 +419,7 @@ impl Yumush { .gap(px(space::XL)) .child(input_box(&self.chat.search_input, palette)) .children(found.map(|user| self.found_row(entity, user, palette))) - .children( - query - .is_empty() - .then(|| self.requests(entity, palette)) - .flatten(), - ) + .children(self.requests(entity, palette)) .children(group( "Friends", palette, diff --git a/crates/client/src/gui/snippet.rs b/crates/client/src/gui/snippet.rs index d72e5a8..d860f1b 100644 --- a/crates/client/src/gui/snippet.rs +++ b/crates/client/src/gui/snippet.rs @@ -55,6 +55,7 @@ fn snippet_row( username: item.username.clone(), role: Role::User, status: String::new(), + hue: None, avatar_id: item.avatar_id, created_at: item.created_at, }); diff --git a/crates/client/src/gui/social.rs b/crates/client/src/gui/social.rs index 096cb61..7b56db7 100644 --- a/crates/client/src/gui/social.rs +++ b/crates/client/src/gui/social.rs @@ -142,6 +142,14 @@ impl Yumush { }; let _ = this.update(cx, |yumush, cx| { + super::style::remember( + &friends + .friends + .iter() + .chain(&friends.incoming) + .chain(&friends.outgoing) + .collect::>(), + ); yumush.chat.friends = friends; yumush.chat.invitations = invitations; yumush.chat.presences = presences.into_iter().collect(); diff --git a/crates/client/src/gui/style.rs b/crates/client/src/gui/style.rs index 4e14b0d..5d7aa35 100644 --- a/crates/client/src/gui/style.rs +++ b/crates/client/src/gui/style.rs @@ -1,6 +1,6 @@ -use std::hash::{DefaultHasher, Hash, Hasher}; +use std::{cell::RefCell, collections::HashMap}; -use common::model::{Hue, Id}; +use common::model::{Hue, Id, User}; use gpui_kit::{App, Global, Hsla, Rems, rems, rgb}; use crate::settings::FontSize; @@ -104,11 +104,27 @@ impl Tokens { } } +pub const PICKS: &[Hue] = Hue::ALL.split_last().unwrap().1; + +thread_local! { + static CHOSEN: RefCell> = RefCell::default(); +} + +pub fn remember(users: &[&User]) { + CHOSEN.with_borrow_mut(|chosen| { + for user in users { + match user.hue { + Some(hue) => chosen.insert(user.id, hue), + None => chosen.remove(&user.id), + }; + } + }); +} + pub fn hue_of(id: Id) -> Hue { - let mut hasher = DefaultHasher::new(); - id.hash(&mut hasher); - let picks = &Hue::ALL[..Hue::ALL.len() - 1]; - picks[hasher.finish() as usize % picks.len()] + CHOSEN + .with_borrow(|chosen| chosen.get(&id).copied()) + .unwrap_or(PICKS[id.rem_euclid(PICKS.len() as Id) as usize]) } fn color(value: u32) -> Hsla { diff --git a/crates/client/src/gui/voice_stats.rs b/crates/client/src/gui/voice_stats.rs index 28bc8b6..76d7e83 100644 --- a/crates/client/src/gui/voice_stats.rs +++ b/crates/client/src/gui/voice_stats.rs @@ -1,32 +1,26 @@ use std::collections::VecDeque; use common::{ - model::{Hue, Id}, + model::Id, share::{Kind, Layer}, }; -use gpui_kit::{ - Div, FontWeight, Hsla, ParentElement, Styled, assets::IconName, component::Icon, div, - prelude::FluentBuilder as _, px, relative, -}; +use gpui_kit::{AnyElement, Div, FontWeight, Hsla, IntoElement, ParentElement, Styled, div, px}; use super::{ Palette, chat::Chat, - share_view::kind_icon, - style::{radius, size, space, stroke, text}, - text as text_size, wave, + parts::{Fill, Ink, Text, band, grow, spark, stack, track, words}, + style::{Tokens, size, space}, }; use crate::media::decode::Engine; use crate::share::session::{LayerStats, WatchStats}; -use crate::usage::{Gpu, Usage}; +use crate::usage::Usage; use crate::voice::VoiceSample; pub const SAMPLE_HISTORY: usize = 60; -const MIRROR_HALF: f32 = size::CHIP; -const LAYER_W: f32 = 70.; -const WATCH_LAYER_W: f32 = 64.; -const RATE_W: f32 = 52.; -const VALUE_W: f32 = 76.; +const LABEL_W: f32 = size::ROW * 2.; +const VALUE_W: f32 = size::THUMB; +const COLUMN_W: f32 = size::TALK + size::ROW * 2.; const PING_SCALE: f32 = 150.; const GOOD_LOSS: f32 = 2.; const FAIR_LOSS: f32 = 8.; @@ -68,14 +62,6 @@ impl Quality { Self::Poor => "poor", } } - - pub fn color(self, palette: Palette) -> Hsla { - match self { - Self::Good => palette.ok, - Self::Fair => palette.tokens.hue(Hue::Gold), - Self::Poor => palette.danger, - } - } } pub fn quality(samples: &VecDeque) -> Option { @@ -83,487 +69,386 @@ pub fn quality(samples: &VecDeque) -> Option { } pub fn stats_panel(chat: &Chat, palette: Palette) -> Div { + let t = palette.tokens; let share = &chat.share_sample; - div() - .flex() - .flex_col() - .gap(px(space::LG)) - .child(network_block(chat, palette)) - .children(sending_blocks(&share.sending, palette)) - .child(receiving_block(&share.watching, chat, palette)) - .children(chat.usage.as_ref().map(|usage| usage_block(usage, palette))) -} - -fn network_block(chat: &Chat, palette: Palette) -> Div { - let latest = chat.voice_samples.back(); - let color = latest.map_or(palette.ok, |sample| Quality::of(sample).color(palette)); - let word = latest.map_or("…", |sample| Quality::of(sample).word()); - let ping = latest.map_or("…".into(), |sample| format!("{:.0} ms", sample.ping_ms)); - let jitter = latest.map_or("…".into(), |sample| { - format!("{:.0} ms", sample.traffic.jitter_ms) - }); - let loss = latest.map_or("…".into(), |sample| { - format!("{:.1} %", sample.traffic.loss * 100.) - }); - let buffer = latest.map_or("…".into(), |sample| { - format!("{:.0} ms", sample.traffic.buffer_ms) - }); - - div() - .flex() - .flex_col() - .gap(px(space::SM)) - .child(header(IconName::Activity, "Network", color).child(chip(word, color, palette))) + band(space::XXL) + .items_start() + .flex_wrap() .child( - div() - .flex() - .gap(px(space::SM)) - .child(stat_cell("ping", ping, color, palette)) - .child(stat_cell("jitter", jitter, color, palette)) - .child(stat_cell("loss", loss, color, palette)) - .child(stat_cell("buffer", buffer, palette.text, palette)), + stack(space::XL) + .w(px(COLUMN_W)) + .child(connection(chat, t)) + .child(traffic(chat, t)) + .children(chat.usage.as_ref().map(|usage| machine(usage, t))), ) .child( - div() - .h(px(size::CONTROL)) - .p(px(space::XXS)) - .rounded(px(radius::SM)) - .bg(palette.window) - .child(wave::line( - chat.voice_samples - .iter() - .map(|sample| (sample.ping_ms / PING_SCALE).clamp(0., 1.)) - .collect(), - color, - )), + stack(space::XL) + .w(px(COLUMN_W)) + .children(sending(&share.sending, t)) + .children(watching(&share.watching, chat, t)), ) - .child(traffic(chat, palette)) } -fn traffic(chat: &Chat, palette: Palette) -> Div { - let up: Vec = chat.traffic.iter().map(|(up, _)| *up).collect(); - let down: Vec = chat.traffic.iter().map(|(_, down)| *down).collect(); - let up_latest = up.last().copied().unwrap_or_default(); - let down_latest = down.last().copied().unwrap_or_default(); - let max = up.iter().chain(&down).copied().fold(1., f32::max); - - div() - .flex() - .flex_col() - .gap(px(space::XXS)) - .text_size(text_size(text::CAPTION)) +fn title(name: &'static str, sub: String, trailing: Option
, t: Tokens) -> Div { + band(space::SM) .child( - div() - .text_color(up_color(palette)) - .child(format!("↑ {}", rate(up_latest as u32))), - ) - .child( - div() - .h(px(MIRROR_HALF * 2.)) - .flex() - .flex_col() - .child( - div() - .h(px(MIRROR_HALF)) - .flex() - .items_end() - .gap(px(space::XXS)) - .children(bars(&up, max, up_color(palette))), - ) - .child(div().h(px(stroke::LINE)).bg(palette.border)) - .child( - div() - .h(px(MIRROR_HALF)) - .flex() - .items_start() - .gap(px(space::XXS)) - .children(bars(&down, max, down_color(palette))), - ), - ) - .child( - div() - .text_color(down_color(palette)) - .child(format!("↓ {}", rate(down_latest as u32))), + words(name, Text::Label, Ink::Paper, t) + .font_weight(FontWeight::MEDIUM) + .flex_none(), ) + .child(words(sub, Text::Caption, Ink::Faint, t)) + .child(grow()) + .children(trailing) } -fn bars(values: &[f32], max: f32, color: Hsla) -> Vec
{ - let empty = SAMPLE_HISTORY.saturating_sub(values.len()); - (0..empty) - .map(|_| div().flex_1()) - .chain( - values - .iter() - .map(|value| div().flex_1().h(px(value / max * MIRROR_HALF)).bg(color)), +fn line_row(label: AnyElement, fill: AnyElement, value: String, bad: bool, t: Tokens) -> Div { + band(space::MD) + .h(px(size::CONTROL_SM)) + .child(div().w(px(LABEL_W)).flex_none().min_w_0().child(label)) + .child(div().flex_1().min_w_0().child(fill)) + .child( + words( + value, + Text::Label, + if bad { Ink::Bad } else { Ink::Paper }, + t, + ) + .w(px(VALUE_W)) + .flex_none() + .text_right(), ) - .collect() -} - -fn up_color(palette: Palette) -> Hsla { - palette.tokens.hue(Hue::Violet) } -fn down_color(palette: Palette) -> Hsla { - palette.tokens.hue(Hue::Teal) +fn label(text: &'static str, t: Tokens) -> AnyElement { + words(text, Text::Caption, Ink::Dim, t).into_any_element() } -fn sending_blocks(sending: &[(Kind, LayerStats)], palette: Palette) -> Vec
{ - [Kind::Screen, Kind::Camera] - .into_iter() - .filter_map(|kind| { - let layers: Vec<&LayerStats> = sending - .iter() - .filter(|(sent, _)| *sent == kind) - .map(|(_, stats)| stats) - .collect(); - (!layers.is_empty()).then(|| sending_block(kind, &layers, palette)) - }) - .collect() -} - -fn sending_block(kind: Kind, layers: &[&LayerStats], palette: Palette) -> Div { - let color = kind_color(kind, palette); - let max = largest(layers.iter().map(|stats| stats.kbps)); - let engine = layers - .last() - .map_or("…", |stats| engine_label(stats.engine)); - div() - .flex() - .flex_col() - .gap(px(space::SM)) - .child(header(kind_icon(kind), kind_name(kind), color).child(label(engine, color))) - .children( - layers - .iter() - .enumerate() - .rev() - .map(|(index, stats)| layer_row(index, stats, max, kind, palette)), - ) -} - -fn layer_row(index: usize, stats: &LayerStats, max: f32, kind: Kind, palette: Palette) -> Div { - let color = kind_color(kind, palette); - div() - .flex() - .items_center() - .gap(px(space::SM)) - .h(px(size::CONTROL_SM)) - .px(px(space::SM)) - .rounded(px(radius::MD)) - .bg(palette.hover) - .text_size(text_size(text::CAPTION)) - .when(stats.kbps == 0, |this| { - this.text_color(palette.tokens.faint()) - }) - .child( - div() - .w(px(size::CHIP)) - .flex_none() - .font_weight(FontWeight::SEMIBOLD) - .text_color(color) - .child(format!("L{index}")), - ) - .child( - div() - .w(px(LAYER_W)) - .flex_none() - .text_color(palette.text) - .child(resolution_text(stats.layer, stats.fps)), - ) - .child( - div() - .w(px(size::CONTROL)) - .flex_none() - .text_color(palette.muted) - .child(stats.layer.codec.name()), - ) - .child(bar(stats.kbps as f32 / max, color, palette)) +fn number(value: String, name: &'static str, bad: bool, t: Tokens) -> Div { + stack(space::XXS) + .flex_1() .child( - div() - .w(px(RATE_W)) - .flex_none() - .text_right() - .text_color(palette.text) - .child(rate(stats.kbps)), + words( + value, + Text::Title, + if bad { Ink::Bad } else { Ink::Paper }, + t, + ) + .font_weight(FontWeight::MEDIUM), ) + .child(words(name, Text::Caption, Ink::Faint, t)) } -fn receiving_block(watching: &[(Id, Kind, WatchStats)], chat: &Chat, palette: Palette) -> Div { - div() - .flex() - .flex_col() - .gap(px(space::XS)) - .child(header(IconName::Eye, "Receiving", palette.text)) - .children( - watching - .iter() - .map(|(user_id, kind, stats)| watch_row(chat, *user_id, *kind, stats, palette)), +fn connection(chat: &Chat, t: Tokens) -> Div { + let latest = chat.voice_samples.back(); + let quality = latest.map(Quality::of); + let bad = quality == Some(Quality::Poor); + let field = |value: Option| value.unwrap_or_else(|| "…".into()); + let ping = latest.map(|sample| sample.ping_ms); + let loss = latest.map(|sample| sample.traffic.loss * 100.); + let word = quality.map(|quality| { + words( + quality.word(), + Text::Caption, + if bad { Ink::Bad } else { Ink::Dim }, + t, ) -} + }); -fn watch_row(chat: &Chat, user_id: Id, kind: Kind, stats: &WatchStats, palette: Palette) -> Div { - let name = chat - .author(user_id) - .map_or_else(|| user_id.to_string(), |user| user.username.clone()); - let color = palette.tinted(user_id); - let loss = stats.loss * 100.; - let loss_color = Quality::of_loss(loss).color(palette); - let latency = stats - .latency_ms - .map_or("…".to_string(), |ms| format!("{ms} ms")); - div() - .flex() - .items_center() - .gap(px(space::XS)) - .h(px(size::CONTROL)) - .px(px(space::SM)) - .rounded(px(radius::MD)) - .bg(palette.hover) - .text_size(text_size(text::CAPTION)) - .child(avatar_dot(&name, color, palette)) - .child( - div() - .flex_1() - .min_w_0() - .truncate() - .font_weight(FontWeight::SEMIBOLD) - .text_color(color) - .child(name), - ) - .child( - Icon::new(kind_icon(kind)) - .size(px(size::ICON_SM)) - .flex_none() - .text_color(kind_color(kind, palette)), - ) - .child( - div() - .w(px(WATCH_LAYER_W)) - .flex_none() - .text_color(palette.text) - .child( - stats - .layer - .map_or("…".to_string(), |layer| resolution_text(layer, stats.fps)), - ), - ) + stack(space::MD) + .child(title("Connection", String::new(), word, t)) .child( - div() - .w(px(RATE_W)) - .flex_none() - .text_color(palette.muted) - .child(format!( - "{} {}", - stats.layer.map_or("…", |layer| layer.codec.name()), - stats.engine.map_or("…", engine_label) + band(space::LG) + .child(number( + field(ping.map(|ping| format!("{ping:.0}"))), + "ping ms", + ping.is_some_and(|ping| ping > PING_SCALE), + t, + )) + .child(number( + field(latest.map(|sample| format!("{:.0}", sample.traffic.jitter_ms))), + "jitter ms", + false, + t, + )) + .child(number( + field(loss.map(|loss| format!("{loss:.1}"))), + "loss %", + loss.is_some_and(|loss| loss > GOOD_LOSS), + t, + )) + .child(number( + field(latest.map(|sample| format!("{:.0}", sample.traffic.buffer_ms))), + "buffer ms", + false, + t, )), ) .child( - div() - .w(px(size::ROW)) - .flex_none() - .text_right() - .text_color(palette.text) - .child(rate(stats.kbps)), - ) - .child( - div() - .w(px(RATE_W)) - .flex_none() - .text_right() - .text_color(palette.muted) - .child(latency), + div().h(px(size::CONTROL_SM)).child(spark( + chat.voice_samples + .iter() + .map(|sample| (sample.ping_ms / PING_SCALE).clamp(0., 1.)) + .collect(), + SAMPLE_HISTORY, + if bad { t.bad() } else { t.paper() }, + )), ) - .child(chip(format!("{loss:.1}%"), loss_color, palette)) } -fn usage_block(usage: &Usage, palette: Palette) -> Div { - let memory = usage.memory; - let total_mb = memory.total_mb.max(1) as f32; - let cpu = column() - .child(model_header( - IconName::Cpu, - "CPU", - &usage.cpu_model, - palette, +fn traffic(chat: &Chat, t: Tokens) -> Div { + let up: Vec = chat.traffic.iter().map(|(up, _)| *up).collect(); + let down: Vec = chat.traffic.iter().map(|(_, down)| *down).collect(); + let max = up.iter().chain(&down).copied().fold(1., f32::max); + let line = |values: &[f32], ink: Hsla| { + div() + .h(px(space::MD)) + .child(spark( + values.iter().map(|value| value / max).collect(), + SAMPLE_HISTORY, + ink, + )) + .into_any_element() + }; + let latest = |values: &[f32]| rate(values.last().copied().unwrap_or_default() as u32); + + stack(space::XS) + .child(title("Traffic", String::new(), None, t)) + .child(line_row( + label("up", t), + line(&up, t.paper()), + latest(&up), + false, + t, )) - .child(dual( - "total", - usage.total, - usage.machine, - palette.text, - palette, + .child(line_row( + label("down", t), + line(&down, t.dim()), + latest(&down), + false, + t, )) - .children( - usage - .threads - .map(|threads| { - [ - meter("gui", threads.gui, palette.accent, palette), - meter("camera", threads.camera, palette.camera, palette), - meter("encode", threads.encode, palette.screen, palette), - meter("decode", threads.decode, palette.ok, palette), - ] - }) - .into_iter() - .flatten(), - ) - .child(dual_value( - "ram", - format!("{} / {}", gb(memory.own_mb), gb(memory.used_mb)), - memory.own_mb as f32 / total_mb, - memory.used_mb as f32 / total_mb, - palette.muted, - palette, - )); - div() - .flex() - .gap(px(space::XL)) - .child(cpu) - .children(usage.gpu.as_ref().map(|gpu| gpu_column(gpu, palette))) -} - -fn column() -> Div { - div() - .flex() - .flex_col() - .gap(px(space::SM)) - .flex_1() - .min_w_0() -} - -fn model_header(icon: IconName, title: &'static str, model: &str, palette: Palette) -> Div { - div() - .flex() - .flex_col() - .gap(px(space::XXS)) - .child(header(icon, title, palette.text)) - .child( - div() - .text_size(text_size(text::CAPTION)) - .text_color(palette.muted) - .truncate() - .child(model.to_string()), - ) } -fn gpu_column(gpu: &Gpu, palette: Palette) -> Div { - let machine = gpu.machine; - let vram_total = machine.vram_total_mb.max(machine.vram_used_mb).max(1) as f32; - column() - .child(model_header( - IconName::MemoryStick, - "GPU", - &gpu.model, - palette, - )) - .child(dual("3d", gpu.gfx, machine.gfx, palette.accent, palette)) - .child(dual( - "video", - gpu.video, - machine.video, - palette.screen, - palette, +fn machine(usage: &Usage, t: Tokens) -> Div { + let memory = usage.memory; + let total_mb = memory.total_mb.max(1) as f32; + let over = |own: f32, total: f32| track(Fill::Over { own, total }, false, t).into_any_element(); + let model = match usage.gpu.as_ref() { + Some(gpu) => format!("{} · {}", usage.cpu_model, gpu.model), + None => usage.cpu_model.to_string(), + }; + + stack(space::XS) + .child(title("This machine", model, None, t)) + .child(line_row( + label("CPU", t), + over(usage.total / 100., usage.machine / 100.), + format!("{:.0} / {:.0} %", usage.total, usage.machine), + false, + t, )) - .child(dual_value( - "vram", - format!("{} / {}", gb(gpu.vram_mb), gb(machine.vram_used_mb)), - gpu.vram_mb as f32 / vram_total, - machine.vram_used_mb as f32 / vram_total, - palette.muted, - palette, + .children(usage.threads.map(|threads| { + band(space::MD).children( + [ + ("gui", threads.gui), + ("camera", threads.camera), + ("encode", threads.encode), + ("decode", threads.decode), + ] + .map(|(name, value)| { + words(format!("{name} {value:.0} %"), Text::Caption, Ink::Faint, t) + }), + ) + })) + .child(line_row( + label("memory", t), + over( + memory.own_mb as f32 / total_mb, + memory.used_mb as f32 / total_mb, + ), + format!("{} / {}", gb(memory.own_mb), gb(memory.total_mb)), + false, + t, )) + .children(usage.gpu.as_ref().map(|gpu| { + let machine = gpu.machine; + let vram_total = machine.vram_total_mb.max(machine.vram_used_mb).max(1) as f32; + stack(space::XS) + .child(line_row( + label("GPU 3d", t), + over(gpu.gfx / 100., machine.gfx / 100.), + format!("{:.0} / {:.0} %", gpu.gfx, machine.gfx), + false, + t, + )) + .child(line_row( + label("video", t), + over(gpu.video / 100., machine.video / 100.), + format!("{:.0} / {:.0} %", gpu.video, machine.video), + false, + t, + )) + .child(line_row( + label("vram", t), + over( + gpu.vram_mb as f32 / vram_total, + machine.vram_used_mb as f32 / vram_total, + ), + format!("{} / {}", gb(gpu.vram_mb), gb(machine.vram_total_mb)), + false, + t, + )) + })) +} + +fn sending(sending: &[(Kind, LayerStats)], t: Tokens) -> Vec
{ + [Kind::Screen, Kind::Camera] + .into_iter() + .filter_map(|kind| { + let layers: Vec<&LayerStats> = sending + .iter() + .filter(|(sent, _)| *sent == kind) + .map(|(_, stats)| stats) + .collect(); + let last = layers.last()?; + let max = largest(layers.iter().map(|stats| stats.kbps)); + let name = match kind { + Kind::Screen => "Sending screen", + Kind::Camera => "Sending camera", + }; + Some( + stack(space::XS) + .child(title( + name, + format!( + "{} · {}", + last.layer.codec.name(), + engine_label(last.engine) + ), + None, + t, + )) + .children(layers.iter().rev().map(|stats| { + line_row( + words( + resolution_text(stats.layer, stats.fps), + Text::Caption, + Ink::Dim, + t, + ) + .into_any_element(), + track(Fill::Part(stats.kbps as f32 / max), false, t).into_any_element(), + rate(stats.kbps), + false, + t, + ) + })), + ) + }) + .collect() } -fn gb(mb: u32) -> String { - match mb { - 0..1000 => format!("{mb} M"), - _ => format!("{:.1} G", mb as f32 / 1024.), +fn watching(watching: &[(Id, Kind, WatchStats)], chat: &Chat, t: Tokens) -> Option
{ + if watching.is_empty() { + return None; } -} - -fn dual(label: &'static str, own: f32, machine: f32, color: Hsla, palette: Palette) -> Div { - dual_value( - label, - format!("{own:.0} / {machine:.0} %"), - own / 100., - machine / 100., - color, - palette, - ) -} - -fn dual_value( - label: &'static str, - value: String, - own: f32, - machine: f32, - color: Hsla, - palette: Palette, -) -> Div { - row( - label, - value, - dual_bar(own, machine, color, palette), - palette, - ) -} - -fn meter(label: &'static str, percent: f32, color: Hsla, palette: Palette) -> Div { - meter_value( - label, - format!("{percent:.1} %"), - percent / 100., - color, - palette, + let max = largest(watching.iter().map(|(_, _, stats)| stats.kbps)); + let latency = watching + .iter() + .filter_map(|(_, _, stats)| stats.latency_ms) + .max(); + let loss = watching + .iter() + .map(|(_, _, stats)| stats.loss) + .fold(0., f32::max) + * 100.; + let keyframes: u32 = watching.iter().map(|(_, _, stats)| stats.keyframes).sum(); + let nacks: u32 = watching.iter().map(|(_, _, stats)| stats.nacks).sum(); + let count = watching.len(); + + Some( + stack(space::XS) + .child(title( + "Watching", + format!("{count} {}", if count == 1 { "stream" } else { "streams" }), + None, + t, + )) + .children(watching.iter().map(|(user_id, kind, stats)| { + let name = chat + .author(*user_id) + .map_or_else(|| user_id.to_string(), |user| user.username.clone()); + let detail = format!( + "{} · {}", + kind_word(*kind), + stats + .layer + .map_or("…".to_string(), |layer| resolution_text(layer, stats.fps)) + ); + let bad = Quality::of_loss(stats.loss * 100.) == Quality::Poor; + line_row( + band(space::XS) + .child( + words(name, Text::Label, Ink::Paper, t) + .text_color(t.person(*user_id)) + .flex_none(), + ) + .child(words(detail, Text::Caption, Ink::Faint, t)) + .into_any_element(), + track(Fill::Part(stats.kbps as f32 / max), bad, t).into_any_element(), + rate(stats.kbps), + bad, + t, + ) + })) + .child( + band(space::MD) + .child(words( + format!( + "latency {}", + latency.map_or("…".into(), |ms| format!("{ms} ms")) + ), + Text::Caption, + Ink::Faint, + t, + )) + .child(words( + format!("loss {loss:.1} %"), + Text::Caption, + if loss > GOOD_LOSS { + Ink::Bad + } else { + Ink::Faint + }, + t, + )) + .child(words( + format!("keyframes {keyframes}"), + Text::Caption, + Ink::Faint, + t, + )) + .child(words( + format!("NACKs {nacks}"), + Text::Caption, + Ink::Faint, + t, + )), + ), ) } -fn meter_value( - label: &'static str, - value: String, - fraction: f32, - color: Hsla, - palette: Palette, -) -> Div { - row(label, value, bar(fraction, color, palette), palette) -} - -fn row(label: &'static str, value: String, bar: Div, palette: Palette) -> Div { - div() - .flex() - .items_center() - .gap(px(space::SM)) - .text_size(text_size(text::CAPTION)) - .child( - div() - .w(px(size::ROW)) - .flex_none() - .text_color(palette.muted) - .child(label), - ) - .child(bar) - .child( - div() - .w(px(VALUE_W)) - .flex_none() - .text_right() - .text_color(palette.text) - .child(value), - ) -} - -fn kind_color(kind: Kind, palette: Palette) -> Hsla { +fn kind_word(kind: Kind) -> &'static str { match kind { - Kind::Camera => palette.camera, - Kind::Screen => palette.screen, + Kind::Camera => "camera", + Kind::Screen => "screen", } } -fn kind_name(kind: Kind) -> &'static str { - match kind { - Kind::Camera => "Camera", - Kind::Screen => "Screen", +fn gb(mb: u32) -> String { + match mb { + 0..1000 => format!("{mb} MB"), + _ => format!("{:.1} GB", mb as f32 / 1024.), } } @@ -573,132 +458,22 @@ fn largest(values: impl Iterator) -> f32 { pub fn rate(kbps: u32) -> String { match kbps { - 0..1000 => format!("{kbps} kbps"), - _ => format!("{:.1} Mbps", kbps as f32 / 1000.), + 0..1000 => format!("{kbps} kb/s"), + _ => format!("{:.1} Mb/s", kbps as f32 / 1000.), } } fn engine_label(engine: Engine) -> &'static str { match engine { - Engine::Hardware => "HW", - Engine::Software => "SW", + Engine::Hardware => "hardware", + Engine::Software => "software", } } fn resolution_text(layer: Layer, fps: f32) -> String { format!( - "{}p{}", + "{}p {}", layer.quality.resolution.height(), fps.round() as u32 ) } - -fn header(icon: IconName, title: &'static str, color: Hsla) -> Div { - div() - .flex() - .items_center() - .gap(px(space::SM)) - .child( - Icon::new(icon) - .size(px(size::ICON_SM)) - .flex_none() - .text_color(color), - ) - .child( - div() - .font_weight(FontWeight::SEMIBOLD) - .text_size(text_size(text::CAPTION)) - .text_color(color) - .child(title), - ) - .child(div().flex_1()) -} - -fn label(value: &'static str, color: Hsla) -> Div { - div() - .text_size(text_size(text::CAPTION)) - .text_color(color) - .child(value) -} - -fn chip(value: impl gpui_kit::IntoElement, color: Hsla, palette: Palette) -> Div { - div() - .flex_none() - .px(px(space::SM)) - .py(px(space::XXS)) - .rounded(px(radius::SM)) - .bg(palette.hover) - .text_size(text_size(text::CAPTION)) - .text_color(color) - .child(value) -} - -fn stat_cell(label: &'static str, value: String, color: Hsla, palette: Palette) -> Div { - div() - .flex_1() - .min_w_0() - .flex() - .flex_col() - .gap(px(space::XXS)) - .child( - div() - .text_size(text_size(text::CAPTION)) - .text_color(palette.muted) - .child(label), - ) - .child( - div() - .text_size(text_size(text::UI)) - .text_color(color) - .child(value), - ) -} - -fn avatar_dot(name: &str, color: Hsla, palette: Palette) -> Div { - let initial = name - .chars() - .next() - .map_or('?', |letter| letter.to_ascii_uppercase()); - div() - .size(px(size::CHIP)) - .flex_none() - .rounded_full() - .flex() - .items_center() - .justify_center() - .bg(color) - .text_size(text_size(text::CAPTION)) - .font_weight(FontWeight::BOLD) - .text_color(palette.on_accent) - .child(initial.to_string()) -} - -fn dual_bar(own: f32, machine: f32, color: Hsla, palette: Palette) -> Div { - bar(machine, palette.tokens.faint(), palette).child( - div() - .absolute() - .top_0() - .left_0() - .h_full() - .w(relative(own.clamp(0., 1.))) - .rounded_full() - .bg(color), - ) -} - -fn bar(fraction: f32, color: Hsla, palette: Palette) -> Div { - div() - .relative() - .flex_1() - .min_w_0() - .h(px(space::XS)) - .rounded_full() - .bg(palette.border) - .child( - div() - .h_full() - .w(relative(fraction.clamp(0., 1.))) - .rounded_full() - .bg(color), - ) -} diff --git a/crates/client/src/usage/drm.rs b/crates/client/src/usage/drm.rs index b8d4bcf..75699f5 100644 --- a/crates/client/src/usage/drm.rs +++ b/crates/client/src/usage/drm.rs @@ -167,10 +167,10 @@ fn machine_clients(pdev: &str) -> Vec { let Ok(info) = fs::read_to_string(path.join("fdinfo").join(fd.file_name())) else { continue; }; - if let Some(client) = client(&info) { - if client.pdev == pdev { - clients.push(client); - } + if let Some(client) = client(&info) + && client.pdev == pdev + { + clients.push(client); } } } diff --git a/crates/common/src/call.rs b/crates/common/src/call.rs index 665d34e..06f1bfa 100644 --- a/crates/common/src/call.rs +++ b/crates/common/src/call.rs @@ -3,6 +3,7 @@ use bitcode::{Decode, DecodeOwned, Encode}; use crate::{ constant::{MAXIMUM_AVATAR_BYTES, MAXIMUM_MESSAGE_LENGTH}, error::Error, + model::Hue, model::{ Account, AdminActionKind, AdminLogEntry, AttachmentInfo, BackupInfo, Ban, BanScope, Community, CommunitySummary, CommunityUsage, DayStat, Friends, Id, Invitation, InviteCode, @@ -80,6 +81,11 @@ pub struct UpdateStatus { pub status: String, } +#[derive(Debug, Clone, Encode, Decode)] +pub struct UpdateHue { + pub hue: Option, +} + #[derive(Debug, Clone, Encode, Decode)] pub struct UpdatePresence { pub presence: Presence, @@ -635,6 +641,7 @@ calls! { GetUser: User -> User; UpdateUser: User -> User, |c| validate_username(&c.username); UpdateStatus: User -> User, |c| validate_status(&c.status); + UpdateHue: User -> User; UpdatePresence: User -> (); ListPresences: User -> Vec<(Id, Presence)>; UpdateAvatar: User -> User, |c| validate_avatar_size(&c.image, MAXIMUM_AVATAR_BYTES as u64); diff --git a/crates/common/src/model.rs b/crates/common/src/model.rs index d42cce4..463b4eb 100644 --- a/crates/common/src/model.rs +++ b/crates/common/src/model.rs @@ -127,6 +127,7 @@ pub struct User { pub username: String, pub role: Role, pub status: String, + pub hue: Option, pub avatar_id: Option, pub created_at: u64, } diff --git a/crates/server/src/call/mod.rs b/crates/server/src/call/mod.rs index ef0e9a8..286eb75 100644 --- a/crates/server/src/call/mod.rs +++ b/crates/server/src/call/mod.rs @@ -110,6 +110,7 @@ pub(crate) async fn dispatch(request: Request, cx: &mut Cx<'_>) -> Vec { Request::GetUser(call) => serve(call, cx).await, Request::UpdateUser(call) => serve(call, cx).await, Request::UpdateStatus(call) => serve(call, cx).await, + Request::UpdateHue(call) => serve(call, cx).await, Request::UpdatePresence(call) => serve(call, cx).await, Request::ListPresences(call) => serve(call, cx).await, Request::UpdateAvatar(call) => serve(call, cx).await, diff --git a/crates/server/src/call/user.rs b/crates/server/src/call/user.rs index f992053..0178fb3 100644 --- a/crates/server/src/call/user.rs +++ b/crates/server/src/call/user.rs @@ -1,7 +1,7 @@ use common::{ call::{ GetAvatar, GetSettings, GetUser, ListPresences, ListSessions, RemoveAvatar, RevokeSession, - UpdateAvatar, UpdatePresence, UpdateStatus, UpdateUser, + UpdateAvatar, UpdateHue, UpdatePresence, UpdateStatus, UpdateUser, }, event::Event, model::{AdminAction, Id, Presence, ServerSettings, SessionInfo, User}, @@ -54,6 +54,16 @@ impl Handle for UpdateStatus { } } +impl Handle for UpdateHue { + async fn handle(self, me: Me, cx: &mut Cx<'_>) -> Result { + let me = me.user()?; + let user = db::user::update_hue(me.id, self.hue, cx.db).await?; + user_updated(&user, cx); + + Ok(user) + } +} + impl Handle for UpdatePresence { async fn handle(self, me: Me, cx: &mut Cx<'_>) -> Result<(), ServerError> { let me = me.user()?; diff --git a/crates/server/src/db/schema.sql b/crates/server/src/db/schema.sql index fdb4120..2a09c2f 100644 --- a/crates/server/src/db/schema.sql +++ b/crates/server/src/db/schema.sql @@ -4,6 +4,7 @@ CREATE TABLE user ( password_hash TEXT NOT NULL, role TEXT NOT NULL, status TEXT NOT NULL DEFAULT '', + hue TEXT, presence TEXT NOT NULL, suspended INTEGER NOT NULL DEFAULT 0, suspended_until INTEGER, diff --git a/crates/server/src/db/user.rs b/crates/server/src/db/user.rs index 5ddbc20..245d39c 100644 --- a/crates/server/src/db/user.rs +++ b/crates/server/src/db/user.rs @@ -1,6 +1,6 @@ use common::{ error::Error, - model::{Account, Id, Presence, Role, User}, + model::{Account, Hue, Id, Presence, Role, User}, permission, time::now_ms, }; @@ -8,7 +8,7 @@ use common::{ use super::{Connection, Reader, all, maybe, one, run}; use crate::error::{ServerError, ensure_with}; -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"; +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"; pub fn row(r: &mut Reader) -> Result { Ok(User { @@ -16,6 +16,9 @@ pub fn row(r: &mut Reader) -> Result { username: r.get()?, role: r.named()?, status: r.get()?, + hue: r + .get::>()? + .and_then(|text| Hue::parse(&text)), avatar_id: r.get()?, created_at: r.get()?, }) @@ -92,6 +95,17 @@ pub async fn update(id: Id, username: &str, db: &Connection) -> Result, db: &Connection) -> Result { + run( + db, + "UPDATE user SET hue = ?2 WHERE id = ?1", + (id, hue.map(|hue| hue.as_str())), + ) + .await?; + + read(id, db).await +} + pub async fn update_status(id: Id, status: &str, db: &Connection) -> Result { run( db,