use eframe::{egui, epi}; use crate::matrix; pub mod login; pub mod session; /// Application state #[derive(Debug, Default)] pub struct App { view: View, } impl epi::App for App { fn name(&self) -> &str { "retrix" } fn update(&mut self, ctx: &egui::CtxRef, _frame: &mut epi::Frame<'_>) { match self.view { View::Login(ref mut login) => { if login.update(ctx) { let client = match matrix::login(&login.homeserver, &login.username, &login.password) { Ok(client) => client, Err(e) => { login.error = Some(e.to_string()); return; } }; self.view = View::Main(session::App::with_client(client.clone())); std::thread::spawn(move || { let rt = tokio::runtime::Runtime::new().unwrap(); rt.block_on(client.sync(Default::default())) }); } } View::Main(ref mut view) => view.update(ctx), }; } } /// Which view is currectly open #[derive(Debug)] pub enum View { Login(login::Login), Main(session::App), } impl Default for View { fn default() -> Self { View::Login(login::Login::default()) } } #[derive(Debug, Clone, Copy, Hash)] pub enum Id { RoomPanel, }