accounts are now real

This commit is contained in:
2025-12-03 22:51:57 -05:00
parent 4aa22de61b
commit 24bb65bf7b
15 changed files with 679 additions and 163 deletions

View File

@@ -19,7 +19,6 @@ pub const CLIENT_SOCKET: SocketAddr =
pub struct ConnectInfo {
pub ip: String,
pub username: String,
}
pub struct NetHandle {
@@ -27,27 +26,6 @@ pub struct NetHandle {
pub thread: JoinHandle<()>,
}
#[derive(Default)]
pub enum NetState {
#[default]
None,
Connecting(JoinHandle<()>),
Connected(NetHandle),
}
impl NetState {
pub fn take_connection(&mut self) -> Option<NetHandle> {
match self.take() {
NetState::Connected(net_handle) => Some(net_handle),
_ => None,
}
}
pub fn take(&mut self) -> Self {
std::mem::replace(self, Self::None)
}
}
pub fn connect(handle: AppHandle, info: ConnectInfo) -> JoinHandle<()> {
std::thread::spawn(move || {
if let Err(msg) = connect_the(handle.clone(), info) {
@@ -80,6 +58,17 @@ impl NetSender {
}
}
impl NetHandle {
pub fn send(&self, msg: impl Into<NetCtrlMsg>) {
self.send.send(msg.into());
}
pub fn exit(self) {
self.send(NetCtrlMsg::Exit);
let _ = self.thread.join();
}
}
// async fn connection_cert(addr: SocketAddr) -> NetResult<Connection> {
// let dirs = directories_next::ProjectDirs::from("", "", "openworm").unwrap();
// let mut roots = quinn::rustls::RootCertStore::empty();
@@ -151,7 +140,6 @@ async fn connect_the(handle: AppHandle, info: ConnectInfo) -> NetResult<()> {
let conn_ = conn.clone();
handle.send(ClientEvent::Connect {
username: info.username,
send: NetSender { send },
});