use std::sync::{Arc, Mutex, MutexGuard}; use iris::prelude::*; use openworm::net::UserId; use crate::{Rsc, net::NetHandle, ui::UserCache}; // TODO: this really should not be async... // I mean it could be used async but all widgets // are sync so I don't really think it makes sense to be... #[derive(Clone)] pub struct Session(Arc>); pub struct SessionInner { pub con: NetHandle, pub user_id: UserId, pub cache: UserCache, } impl Session { pub fn new(con: NetHandle, user_id: UserId) -> Self { Self(Arc::new(Mutex::new(SessionInner { cache: UserCache::new(con.clone()), con, user_id, }))) } pub fn con(&self) -> NetHandle { self.get().con.clone() } pub fn get(&self) -> MutexGuard<'_, SessionInner> { self.0.try_lock().unwrap() } pub fn reactive_span(&self, rsc: &mut Rsc) -> WeakWidget { let span = Span::empty(Dir::DOWN).add(rsc); span } }