diff --git a/crates/client/src/gui/auth.rs b/crates/client/src/gui/auth.rs index 5d9da9d..6f5f2b8 100644 --- a/crates/client/src/gui/auth.rs +++ b/crates/client/src/gui/auth.rs @@ -21,6 +21,7 @@ use super::{ pub struct Auth { server_input: Entity, any_cert: bool, + server_open: bool, username_input: Entity, password_input: Entity, invite_input: Entity, @@ -54,6 +55,7 @@ impl Auth { Self { server_input, any_cert: server.any_cert, + server_open: false, username_input, password_input, invite_input, @@ -118,6 +120,39 @@ fn submit(this: &mut Yumush, window: &mut Window, cx: &mut Context) { .detach(); } +fn server_toggle( + entity: &Entity, + address: &str, + open: bool, + palette: Palette, +) -> impl IntoElement { + let entity = entity.clone(); + clickable("server_toggle", palette, move |_, cx| { + entity.update(cx, |yumush, cx| { + yumush.auth.server_open = !yumush.auth.server_open; + cx.notify(); + }) + }) + .self_center() + .px(px(space::SM)) + .py(px(space::XXS)) + .rounded(px(radius::MD)) + .flex() + .items_center() + .gap(px(space::XS)) + .text_size(text(text::CAPTION)) + .text_color(palette.muted) + .child(address.to_string()) + .child( + Icon::new(if open { + IconName::ChevronDown + } else { + IconName::ChevronRight + }) + .size(px(size::ICON_SM)), + ) +} + fn password_field(palette: Palette, input: &Entity) -> Div { frame(palette, Input::new(input).mask_toggle()) } @@ -179,37 +214,49 @@ impl Yumush { .text_color(palette.muted) .child("Maintenance") })) - .child(field(palette, &self.auth.server_input)) - .child( - div() - .flex() - .items_center() - .justify_between() - .text_size(text(text::CAPTION)) - .text_color(palette.muted) - .child("Accept any certificate") - .child(super::parts::toggle( - "any_cert_switch", - self.auth.any_cert, - palette.tokens, - { - let entity = entity.clone(); - move |_, cx| { - entity.update(cx, |yumush, cx| { - yumush.auth.any_cert = !yumush.auth.any_cert; - apply_server(yumush, cx); - cx.notify(); - }) - } - }, - )), - ) .children(self.saved_accounts(&entity, palette)) .child(tabs) .child(field(palette, &self.auth.username_input)) .child(password_field(palette, &self.auth.password_input)) .children(invite) .child(action_button) + .child(server_toggle( + &entity, + &self.network.server().address, + self.auth.server_open, + palette, + )) + .children(self.auth.server_open.then(|| { + div() + .flex() + .flex_col() + .gap(px(space::SM)) + .child(field(palette, &self.auth.server_input)) + .child( + div() + .flex() + .items_center() + .justify_between() + .text_size(text(text::CAPTION)) + .text_color(palette.muted) + .child("Accept any certificate") + .child(super::parts::toggle( + "any_cert_switch", + self.auth.any_cert, + palette.tokens, + { + let entity = entity.clone(); + move |_, cx| { + entity.update(cx, |yumush, cx| { + yumush.auth.any_cert = !yumush.auth.any_cert; + apply_server(yumush, cx); + cx.notify(); + }) + } + }, + )), + ) + })) .children(connection_notice(&self.connection, palette)), ) } diff --git a/crates/client/src/lib.rs b/crates/client/src/lib.rs index f84d98c..3f0614d 100644 --- a/crates/client/src/lib.rs +++ b/crates/client/src/lib.rs @@ -67,9 +67,10 @@ impl Server { pub fn load() -> Self { let saved = read_config("server"); let mut lines = saved.as_deref().unwrap_or_default().lines().map(str::trim); + let saved_address = lines.next(); let address = std::env::var("YUMUSH_SERVER_ADDRESS") .ok() - .or_else(|| lines.next().map(str::to_string)) + .or_else(|| saved_address.map(str::to_string)) .filter(|address| !address.is_empty()) .unwrap_or_else(|| { Config::parse(CLIENT_CONFIG_FILE_CONTENT)