IP
This commit is contained in:
@@ -27,13 +27,12 @@ pub fn main_view(ui: &mut Ui, network: NetSender) -> WidgetId<AnyWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn login_screen(ui: &mut Ui, handle: AppHandle) -> WidgetId<AnyWidget> {
|
fn login_screen(ui: &mut Ui, handle: AppHandle) -> WidgetId<AnyWidget> {
|
||||||
let field = |name| text(name).editable().size(20);
|
let mut field = |name| text(name).editable().size(20).add(ui);
|
||||||
let ip = field("ip");
|
let ip = field("ip");
|
||||||
// let username = field("username");
|
// let username = field("username");
|
||||||
// let password = field("password");
|
// let password = field("password");
|
||||||
|
|
||||||
let mut fbx = |field: TextBuilder<TextEditOutput>| {
|
let fbx = |field: WidgetId<TextEdit>| {
|
||||||
let field = field.add(ui);
|
|
||||||
field
|
field
|
||||||
.clone()
|
.clone()
|
||||||
.pad(10)
|
.pad(10)
|
||||||
@@ -41,12 +40,14 @@ fn login_screen(ui: &mut Ui, handle: AppHandle) -> WidgetId<AnyWidget> {
|
|||||||
.on(CursorSense::click(), focus(field))
|
.on(CursorSense::click(), focus(field))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let ip_ = ip.clone();
|
||||||
let color = Color::GREEN;
|
let color = Color::GREEN;
|
||||||
let submit = rect(color)
|
let submit = rect(color)
|
||||||
.radius(15)
|
.radius(15)
|
||||||
.id_on(CursorSense::click(), move |id, client: &mut Client, _| {
|
.id_on(CursorSense::click(), move |id, client: &mut Client, _| {
|
||||||
client.ui[id].color = color.darker(0.3);
|
client.ui[id].color = color.darker(0.3);
|
||||||
connect(handle.clone());
|
let ip = client.ui[&ip_].content();
|
||||||
|
connect(handle.clone(), ip);
|
||||||
})
|
})
|
||||||
.height(40);
|
.height(40);
|
||||||
(
|
(
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ use std::{
|
|||||||
};
|
};
|
||||||
use tokio::sync::mpsc::UnboundedSender;
|
use tokio::sync::mpsc::UnboundedSender;
|
||||||
|
|
||||||
pub fn connect(handle: AppHandle) {
|
pub fn connect(handle: AppHandle, ip: String) {
|
||||||
std::thread::spawn(|| {
|
std::thread::spawn(|| {
|
||||||
connect_the(handle).unwrap();
|
connect_the(handle, ip).unwrap();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ pub enum NetCmd {
|
|||||||
pub type NetSender = UnboundedSender<NetCmd>;
|
pub type NetSender = UnboundedSender<NetCmd>;
|
||||||
|
|
||||||
#[tokio::main]
|
#[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 dirs = directories_next::ProjectDirs::from("", "", "openworm").unwrap();
|
||||||
let mut roots = quinn::rustls::RootCertStore::empty();
|
let mut roots = quinn::rustls::RootCertStore::empty();
|
||||||
match fs::read(dirs.data_local_dir().join("cert.der")) {
|
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)?));
|
quinn::ClientConfig::new(Arc::new(QuicClientConfig::try_from(client_crypto)?));
|
||||||
let mut endpoint = quinn::Endpoint::client(SocketAddr::from_str("[::]:0").unwrap())?;
|
let mut endpoint = quinn::Endpoint::client(SocketAddr::from_str("[::]:0").unwrap())?;
|
||||||
endpoint.set_default_client_config(client_config);
|
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 host = "localhost";
|
||||||
let conn = endpoint
|
let conn = endpoint
|
||||||
.connect(remote, host)?
|
.connect(remote, host)?
|
||||||
@@ -64,7 +65,9 @@ async fn connect_the(handle: AppHandle) -> anyhow::Result<()> {
|
|||||||
|
|
||||||
drop(recv);
|
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.finish().unwrap();
|
||||||
send.stopped().await.unwrap();
|
send.stopped().await.unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user