From b7f2d8b7c384504b81ad318908f4d37291d54001 Mon Sep 17 00:00:00 2001 From: Shadow Cat Date: Sat, 15 Nov 2025 02:23:32 -0500 Subject: [PATCH] IP --- src/client/ui.rs | 9 +++++---- src/net/client.rs | 13 ++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/client/ui.rs b/src/client/ui.rs index 79bc378..d92a6ea 100644 --- a/src/client/ui.rs +++ b/src/client/ui.rs @@ -27,13 +27,12 @@ pub fn main_view(ui: &mut Ui, network: NetSender) -> WidgetId { } fn login_screen(ui: &mut Ui, handle: AppHandle) -> WidgetId { - let field = |name| text(name).editable().size(20); + let mut field = |name| text(name).editable().size(20).add(ui); let ip = field("ip"); // let username = field("username"); // let password = field("password"); - let mut fbx = |field: TextBuilder| { - let field = field.add(ui); + let fbx = |field: WidgetId| { field .clone() .pad(10) @@ -41,12 +40,14 @@ fn login_screen(ui: &mut Ui, handle: AppHandle) -> WidgetId { .on(CursorSense::click(), focus(field)) }; + let ip_ = ip.clone(); let color = Color::GREEN; let submit = rect(color) .radius(15) .id_on(CursorSense::click(), move |id, client: &mut Client, _| { client.ui[id].color = color.darker(0.3); - connect(handle.clone()); + let ip = client.ui[&ip_].content(); + connect(handle.clone(), ip); }) .height(40); ( diff --git a/src/net/client.rs b/src/net/client.rs index b0ba85d..27512aa 100644 --- a/src/net/client.rs +++ b/src/net/client.rs @@ -9,9 +9,9 @@ use std::{ }; use tokio::sync::mpsc::UnboundedSender; -pub fn connect(handle: AppHandle) { +pub fn connect(handle: AppHandle, ip: String) { std::thread::spawn(|| { - connect_the(handle).unwrap(); + connect_the(handle, ip).unwrap(); }); } @@ -22,7 +22,7 @@ pub enum NetCmd { pub type NetSender = UnboundedSender; #[tokio::main] -async fn connect_the(handle: AppHandle) -> anyhow::Result<()> { +async fn connect_the(handle: AppHandle, ip: String) -> anyhow::Result<()> { let dirs = directories_next::ProjectDirs::from("", "", "openworm").unwrap(); let mut roots = quinn::rustls::RootCertStore::empty(); match fs::read(dirs.data_local_dir().join("cert.der")) { @@ -43,7 +43,8 @@ async fn connect_the(handle: AppHandle) -> anyhow::Result<()> { quinn::ClientConfig::new(Arc::new(QuicClientConfig::try_from(client_crypto)?)); let mut endpoint = quinn::Endpoint::client(SocketAddr::from_str("[::]:0").unwrap())?; endpoint.set_default_client_config(client_config); - let remote = SocketAddr::new(IpAddr::V6(Ipv6Addr::LOCALHOST), 4433); + let remote = SocketAddr::from_str(&ip).unwrap(); + // let remote = SocketAddr::new(IpAddr::V6(Ipv6Addr::LOCALHOST), 4433); let host = "localhost"; let conn = endpoint .connect(remote, host)? @@ -64,7 +65,9 @@ async fn connect_the(handle: AppHandle) -> anyhow::Result<()> { drop(recv); - send.write_all(content.as_bytes()).await.expect("failed to send"); + send.write_all(content.as_bytes()) + .await + .expect("failed to send"); send.finish().unwrap(); send.stopped().await.unwrap(); }