From 51655ad3598d5ed6aeb4eac367ca906947af4925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 28 Nov 2026 23:40:44 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20one=20saved-accounts=20list?= =?UTF-8?q?=20(account=5Flist)=20for=20login=20and=20the=20profile=20switc?= =?UTF-8?q?her:=20recent=20first,=205=20shown,=20find=20field=20past=205,?= =?UTF-8?q?=20avatars=20and=20forget=20in=20both?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/client/lang/en/auth.txt | 1 + crates/client/lang/tr/auth.txt | 1 + crates/client/src/accounts.rs | 24 +++--- crates/client/src/gui.rs | 10 +++ crates/client/src/gui/account_list.rs | 105 ++++++++++++++++++++++++++ crates/client/src/gui/auth.rs | 86 +++------------------ crates/client/src/gui/profile.rs | 94 +++++++---------------- 7 files changed, 168 insertions(+), 153 deletions(-) create mode 100644 crates/client/src/gui/account_list.rs diff --git a/crates/client/lang/en/auth.txt b/crates/client/lang/en/auth.txt index 4250246..7778db2 100644 --- a/crates/client/lang/en/auth.txt +++ b/crates/client/lang/en/auth.txt @@ -7,3 +7,4 @@ register = Register maintenance = Maintenance accept_any_cert = Accept any certificate forget = Forget +find_account = Find account… diff --git a/crates/client/lang/tr/auth.txt b/crates/client/lang/tr/auth.txt index dfaa750..41e2e25 100644 --- a/crates/client/lang/tr/auth.txt +++ b/crates/client/lang/tr/auth.txt @@ -7,3 +7,4 @@ register = Kayıt ol maintenance = Bakım accept_any_cert = Her sertifikayı kabul et forget = Unut +find_account = Hesap bul… diff --git a/crates/client/src/accounts.rs b/crates/client/src/accounts.rs index b84b101..133545d 100644 --- a/crates/client/src/accounts.rs +++ b/crates/client/src/accounts.rs @@ -1,6 +1,9 @@ -use std::sync::Arc; +use std::{cmp::Reverse, sync::Arc}; -use common::model::{Id, User}; +use common::{ + model::{Id, User}, + time::now_ms, +}; use gpui_kit::{Image, ImageFormat}; use crate::{read_config, read_config_bytes, remove_config, write_config}; @@ -11,6 +14,7 @@ pub struct Account { pub username: String, pub token: String, pub picture: Option>, + pub used_ms: u64, } #[derive(Debug, Clone, Default)] @@ -25,10 +29,10 @@ impl Accounts { self.list.iter().find(|account| account.user_id == user_id) } - pub fn others(&self) -> impl Iterator { - self.list - .iter() - .filter(|account| Some(account.user_id) != self.active) + pub fn recent(&self) -> Vec<&Account> { + let mut list: Vec<&Account> = self.list.iter().collect(); + list.sort_by_key(|account| Reverse(account.used_ms)); + list } pub fn sign_in(&mut self, user: &User, token: String) { @@ -38,6 +42,7 @@ impl Accounts { username: user.username.clone(), token, picture: picture(&self.server, user.id), + used_ms: now_ms(), }); self.active = Some(user.id); save(self); @@ -128,13 +133,14 @@ pub fn load(server: &str) -> Accounts { for line in content.lines() { match line.split('\t').collect::>().as_slice() { ["active", user_id] => accounts.active = user_id.parse().ok(), - [user_id, username, token] => { + [user_id, username, token, rest @ ..] => { if let Ok(user_id) = user_id.parse() { accounts.list.push(Account { user_id, username: username.to_string(), token: token.to_string(), picture: picture(server, user_id), + used_ms: rest.first().and_then(|used| used.parse().ok()).unwrap_or(0), }); } } @@ -151,8 +157,8 @@ fn save(accounts: &Accounts) { .iter() .map(|account| { format!( - "{}\t{}\t{}\n", - account.user_id, account.username, account.token + "{}\t{}\t{}\t{}\n", + account.user_id, account.username, account.token, account.used_ms ) }) .collect(); diff --git a/crates/client/src/gui.rs b/crates/client/src/gui.rs index d0cfbd8..6b06cbc 100644 --- a/crates/client/src/gui.rs +++ b/crates/client/src/gui.rs @@ -38,6 +38,7 @@ use crate::{ settings::{Scale, Settings}, }; +mod account_list; mod auth; mod builder; mod call_bar; @@ -595,6 +596,7 @@ pub struct Yumush { dismissed_announcement: Option, settings: Settings, accounts: Accounts, + account_filter: Entity, voice: VoiceControls, focus: gpui_kit::FocusHandle, window: Option, @@ -658,6 +660,13 @@ impl Yumush { let voice = VoiceControls::new(&settings.voice, window, cx); let server = network.server(); + let account_filter = new_input(w().auth.find_account, window, cx); + cx.subscribe(&account_filter, |_, _, event: &InputEvent, cx| { + if matches!(event, InputEvent::Change) { + cx.notify(); + } + }) + .detach(); let mut yumush = Self { user: None, focus: cx.focus_handle(), @@ -670,6 +679,7 @@ impl Yumush { dismissed_announcement: None, settings, accounts: accounts::load(&server.address), + account_filter, voice, window: None, deferred: Vec::new(), diff --git a/crates/client/src/gui/account_list.rs b/crates/client/src/gui/account_list.rs new file mode 100644 index 0000000..878b873 --- /dev/null +++ b/crates/client/src/gui/account_list.rs @@ -0,0 +1,105 @@ +use gpui_kit::{ + AnyElement, App, Div, Entity, IntoElement, ParentElement, StatefulInteractiveElement, Styled, + assets::IconName, component::popover::PopoverState, div, px, +}; + +use super::{ + Palette, Tooltip as _, Yumush, badge, clickable, hoverable, parts, + sidebar::input_box, + style::{radius, size, space, text}, + text, +}; +use crate::accounts::Account; +use crate::lang::w; + +const CAP: usize = 5; + +pub(super) fn account_list( + yumush: &Yumush, + entity: &Entity, + skip_active: bool, + popover: Option>, + palette: Palette, + cx: &App, +) -> Div { + let mut accounts = yumush.accounts.recent(); + if skip_active { + accounts.retain(|account| Some(account.user_id) != yumush.accounts.active); + } + let filtered = accounts.len() > CAP; + let query = super::widget::search_text(&yumush.account_filter, cx); + let rows: Vec = accounts + .into_iter() + .filter(|account| !filtered || account.username.to_lowercase().contains(query.as_str())) + .take(CAP) + .map(|account| row(account, entity, popover.clone(), palette)) + .collect(); + + div() + .flex() + .flex_col() + .gap(px(space::XXS)) + .children(filtered.then(|| input_box(&yumush.account_filter, palette))) + .children(rows) +} + +fn row( + account: &Account, + entity: &Entity, + popover: Option>, + palette: Palette, +) -> AnyElement { + let user_id = account.user_id; + let switch_entity = entity.clone(); + let forget_entity = entity.clone(); + + hoverable( + format!("saved_{user_id}"), + div() + .h(px(size::CONTROL)) + .px(px(space::SM)) + .flex() + .items_center() + .gap(px(space::SM)) + .rounded(px(radius::MD)) + .child(match &account.picture { + Some(picture) => div() + .size(px(size::CHIP)) + .flex_shrink_0() + .rounded_full() + .overflow_hidden() + .child(gpui_kit::img(picture.clone()).size_full()), + None => badge( + palette, + user_id, + &account.username, + px(size::CHIP), + text(text::CAPTION), + ) + .rounded_full(), + }) + .child(div().flex_1().truncate().child(account.username.clone())) + .child( + clickable(format!("forget_{user_id}"), palette, move |_, cx| { + cx.stop_propagation(); + forget_entity.update(cx, |yumush, cx| yumush.forget_account(user_id, cx)); + }) + .tip(w().auth.forget) + .size(px(size::CHIP)) + .flex() + .items_center() + .justify_center() + .rounded(px(radius::SM)) + .text_color(palette.muted) + .child(parts::small_icon(IconName::X)), + ), + palette, + ) + .on_click(move |_, window, cx| { + if let Some(popover) = &popover { + popover.update(cx, |state, cx| state.dismiss(window, cx)); + } + switch_entity.update(cx, |yumush, cx| yumush.switch_account(user_id, window, cx)); + }) + .into_any_element() +} diff --git a/crates/client/src/gui/auth.rs b/crates/client/src/gui/auth.rs index fe0d705..9066d7a 100644 --- a/crates/client/src/gui/auth.rs +++ b/crates/client/src/gui/auth.rs @@ -1,15 +1,16 @@ use gpui_kit::prelude::FluentBuilder as _; use gpui_kit::{ - AnimationExt as _, AnyElement, Context, Div, Entity, FontWeight, IntoElement, ParentElement, - StatefulInteractiveElement, Styled, Window, + AnimationExt as _, App, Context, Div, Entity, FontWeight, IntoElement, ParentElement, Styled, + Window, assets::IconName, component::input::{Input, InputEvent, InputState}, div, px, }; use super::{ - Palette, Route, Tooltip as _, Yumush, badge, clickable, connection_notice, hoverable, - new_input, notify_error, palette, parts, + Palette, Route, Yumush, + account_list::account_list, + clickable, connection_notice, new_input, notify_error, palette, parts, settings_page::{segment, segment_track}, style::{radius, size, space, text}, text, @@ -230,7 +231,7 @@ impl Yumush { .text_color(palette.muted) .child(w().auth.maintenance) })) - .children(self.saved_accounts(&entity, palette)) + .children(self.saved_accounts(&entity, palette, cx)) .child(tabs) .child(field(palette, &self.auth.username_input)) .child(password_field(palette, &self.auth.password_input)) @@ -286,78 +287,9 @@ impl Yumush { ) } - fn saved_accounts(&self, entity: &Entity, palette: Palette) -> Option
{ - if self.accounts.list.is_empty() { - return None; - } - let rows: Vec = self - .accounts - .list - .iter() - .map(|account| { - let switch_entity = entity.clone(); - let forget_entity = entity.clone(); - let switch_id = account.user_id; - let forget_id = account.user_id; - - hoverable( - format!("saved_{}", account.user_id), - div() - .h(px(size::CONTROL)) - .px(px(space::SM)) - .flex() - .items_center() - .gap(px(space::SM)) - .rounded(px(radius::MD)) - .child(match &account.picture { - Some(picture) => div() - .size(px(size::CHIP)) - .flex_shrink_0() - .rounded_full() - .overflow_hidden() - .child(gpui_kit::img(picture.clone()).size_full()), - None => badge( - palette, - account.user_id, - &account.username, - px(size::CHIP), - text(text::CAPTION), - ) - .rounded_full(), - }) - .child(div().flex_1().truncate().child(account.username.clone())) - .child( - clickable( - format!("forget_{}", account.user_id), - palette, - move |_, cx| { - cx.stop_propagation(); - forget_entity.update(cx, |yumush, cx| { - yumush.forget_account(forget_id, cx) - }); - }, - ) - .tip(w().auth.forget) - .size(px(size::CHIP)) - .flex() - .items_center() - .justify_center() - .rounded(px(radius::SM)) - .text_color(palette.muted) - .child(super::parts::small_icon(IconName::X)), - ), - palette, - ) - .on_click(move |_, window, cx| { - switch_entity.update(cx, |yumush, cx| { - yumush.switch_account(switch_id, window, cx) - }) - }) - .into_any_element() - }) - .collect(); - - Some(div().flex().flex_col().gap(px(space::XXS)).children(rows)) + fn saved_accounts(&self, entity: &Entity, palette: Palette, cx: &App) -> Option
{ + (!self.accounts.list.is_empty()) + .then(|| account_list(self, entity, false, None, palette, cx)) } } diff --git a/crates/client/src/gui/profile.rs b/crates/client/src/gui/profile.rs index 6613236..aa55ab3 100644 --- a/crates/client/src/gui/profile.rs +++ b/crates/client/src/gui/profile.rs @@ -1,3 +1,4 @@ +use super::account_list::account_list; use crate::gui::glyph::Fill as _; use crate::lang::{Label as _, w}; use common::model::Id; @@ -11,9 +12,9 @@ use common::{ permission, }; use gpui_kit::{ - Anchor, AnyElement, App, Context, Div, ElementId, Entity, FontWeight, Hsla, Image, - InteractiveElement, IntoElement, ParentElement, SharedString, Stateful, - StatefulInteractiveElement, StyleRefinement, Styled, Window, + Anchor, AnyElement, App, Context, Div, ElementId, Entity, FontWeight, Hsla, Image, IntoElement, + ParentElement, SharedString, Stateful, StatefulInteractiveElement, StyleRefinement, Styled, + Window, assets::IconName, component::{ WindowExt, @@ -37,8 +38,6 @@ use super::{ millis_time, notify_error, palette, text, }; -const ACCOUNTS_MAX_H: f32 = 180.; - #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum Removal { Kick, @@ -112,11 +111,6 @@ pub(super) fn profile_popover( reporting: yumush.chat.report == Some(ReportTarget::User(user.id)), reason: yumush.chat.report_reason.clone(), status: yumush.chat.status_input.clone(), - others: yumush - .accounts - .others() - .map(|account| (account.user_id, account.username.clone())) - .collect(), volume: yumush .chat .user_volume @@ -154,7 +148,6 @@ struct Card { reporting: bool, reason: Entity, status: Entity, - others: Vec<(Id, String)>, volume: Option<(Entity, f32)>, } @@ -395,12 +388,7 @@ impl Card { .truncate(), ) .when(is_self, |name| { - name.child(account_menu( - self.others.clone(), - entity, - &popover, - palette, - )) + name.child(account_menu(entity, &popover, palette)) }), ) .map(|names| { @@ -639,54 +627,7 @@ fn main_self_rows( rows } -fn accounts_rows( - others: &[(Id, String)], - entity: &Entity, - popover: &Entity, - palette: Palette, -) -> Vec { - let accounts = others.iter().map(|&(user_id, ref username)| { - menu_row( - format!("switch_{user_id}"), - username.clone(), - small_icon(IconName::CircleUser), - palette.text, - palette, - yumush_action(entity, popover, move |yumush, window, cx| { - yumush.switch_account(user_id, window, cx) - }), - ) - }); - - vec![ - div() - .id("profile_accounts") - .max_h(px(ACCOUNTS_MAX_H)) - .overflow_y_scroll() - .flex() - .flex_col() - .children(accounts) - .into_any_element(), - menu_row( - "profile_add_account", - w().profile.add_account, - small_icon(IconName::UserPlus), - palette.text, - palette, - yumush_action(entity, popover, |yumush, window, cx| { - yumush.add_account(window, cx) - }), - ) - .into_any_element(), - ] -} - -fn account_menu( - others: Vec<(Id, String)>, - entity: &Entity, - card: &Entity, - palette: Palette, -) -> Popover { +fn account_menu(entity: &Entity, card: &Entity, palette: Palette) -> Popover { let entity = entity.clone(); let card = card.clone(); Popover::new("account_menu") @@ -699,10 +640,29 @@ fn account_menu( .flex_shrink_0() .child(small_icon(IconName::ChevronDown).text_color(palette.muted)), )) - .content(move |_, _, _| { + .content(move |_, _, cx| { + let yumush = entity.read(cx); super::parts::popover(palette.tokens) .p(px(space::XS)) - .children(accounts_rows(&others, &entity, &card, palette)) + .w(px(size::SIDEBAR)) + .child(account_list( + yumush, + &entity, + true, + Some(card.clone()), + palette, + cx, + )) + .child(menu_row( + "profile_add_account", + w().profile.add_account, + small_icon(IconName::UserPlus), + palette.text, + palette, + yumush_action(&entity, &card, |yumush, window, cx| { + yumush.add_account(window, cx) + }), + )) }) }