119 lines
2.9 KiB
Rust
119 lines
2.9 KiB
Rust
#![allow(non_snake_case)]
|
|
|
|
mod components;
|
|
mod data;
|
|
mod matrix_interface;
|
|
mod utils;
|
|
|
|
use dioxus::prelude::*;
|
|
use tokio::time::{sleep, Duration};
|
|
use tracing::{debug, Level};
|
|
|
|
use crate::base::{login, sync_rooms};
|
|
use crate::base::{APP_SETTINGS, ROOMS, SESSION};
|
|
use crate::components::loading::LoadingPage;
|
|
use crate::components::login::Login;
|
|
use crate::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");
|
|
sleep(Duration::from_secs(3)).await;
|
|
// 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#"
|
|
// <style type="text/css">
|
|
// html, body {
|
|
// height: 100%;
|
|
// width: 100%;
|
|
|
|
// margin: 0;
|
|
// }
|
|
// #main, #bodywrap {
|
|
// height: 100%;
|
|
// width: 100%;
|
|
// }
|
|
// </style>
|
|
// "#
|
|
// .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() {
|
|
tracing_subscriber::fmt()
|
|
// .pretty()
|
|
.with_max_level(Level::DEBUG)
|
|
.init();
|
|
|
|
launch(app);
|
|
}
|