#![allow(non_snake_case)] mod domain; mod infrastructure; mod ui; mod utils; use std::time::Duration; use async_std::task; use dioxus::prelude::*; #[cfg(feature = "desktop")] use dioxus::desktop::Config; use tracing::debug; use tracing_subscriber::prelude::*; #[cfg(feature = "web")] use tracing_web::MakeWebConsoleWriter; use crate::base::{login, sync_rooms}; use crate::base::{APP_SETTINGS, ROOMS, SESSION}; use crate::ui::components::loading::LoadingPage; use crate::ui::components::login::Login; use crate::ui::components::main_window::MainWindow; mod base; fn app() -> Element { debug!("*** App rendering ***"); let mut ready = use_signal(|| false); // Dummy timer simulating the loading of the application let _: Coroutine<()> = use_coroutine(|_: UnboundedReceiver<_>| async move { debug!("Not ready"); task::sleep(Duration::from_secs(3)).await; // task::sleep(Duration::from_secs(0)).await; debug!("Ready"); ready.set(true); }); let login_coro = use_coroutine(|rx| login(rx, &APP_SETTINGS, &SESSION)); let mut sync_rooms_coro = None; if let Some(requester) = &APP_SETTINGS.read().requester { sync_rooms_coro = Some(use_coroutine(|rx| { sync_rooms(rx, requester.borrow().receivers.clone(), &ROOMS) })); } if !SESSION.read().is_logged { login_coro.send(false); } else { if let Some(coro) = sync_rooms_coro { coro.send(true); } // if chats_win_state.read().is_none() { // let chats_window = dioxus_desktop::use_window(cx); // let receivers = app_settings // .read() // .requester // .as_ref() // .unwrap() // .borrow() // .receivers // .clone(); // let chats_props = ChatsWindowProps { // receivers, // interface: chats_win_interface_ref.clone(), // }; // let chats_dom = VirtualDom::new_with_props(ChatsWindow, chats_props); // let window_cfg = Config::default().with_custom_head( // r#" // // "# // .to_owned(), // ); // let chats_window_desktop_service = chats_window.new_window(chats_dom, window_cfg); // chats_win_state.set(Some(chats_window_desktop_service)); // } } if *ready.read() { if SESSION.read().is_logged { debug!("Should render the MainWindow component"); rsx! { MainWindow {}, } } else { rsx! { Login {}, } } } else { rsx! { LoadingPage {}, } } } fn main() { #[cfg(feature = "desktop")] { let fmt_layer = tracing_subscriber::fmt::layer() .with_filter(tracing::level_filters::LevelFilter::DEBUG); tracing_subscriber::registry().with(fmt_layer).init(); let config = Config::new().with_menu(None); let builder = LaunchBuilder::new().with_cfg(config); builder.launch(app); } #[cfg(feature = "web")] { let fmt_layer = tracing_subscriber::fmt::layer() .with_ansi(false) // Only partially supported across browsers .without_time() // std::time is not available in browsers, see note below .with_writer(MakeWebConsoleWriter::new()) // write events to the console .with_filter(tracing::level_filters::LevelFilter::INFO); tracing_subscriber::registry().with(fmt_layer).init(); // Install these as subscribers to tracing events let builder = LaunchBuilder::new(); builder.launch(app); } }