- Remove of the flume dependency. - Add the capability to share data provided by the Matrix client to the ChatsWindow. Indeed, until the 0.6 Dioxus release, each window runs in a separate virtual DOM so the context and Fermi states are completely seperate (cf. https://discord.com/channels/899851952891002890/1188206938215948378).
102 lines
2.6 KiB
Rust
102 lines
2.6 KiB
Rust
#![allow(non_snake_case)]
|
|
|
|
use dioxus::prelude::*;
|
|
use dioxus_desktop::Config;
|
|
use fermi::*;
|
|
use tracing::{debug, Level};
|
|
|
|
pub mod components;
|
|
pub mod matrix_interface;
|
|
|
|
use crate::base::{login, sync_rooms, APP_SETTINGS, ROOMS, SESSION};
|
|
use crate::components::chats_window::chats_window::{ChatsWindow, ChatsWindowProps};
|
|
use crate::components::main_window::MainWindow;
|
|
|
|
mod base;
|
|
|
|
fn App(cx: Scope) -> Element {
|
|
debug!("*** App rendering ***");
|
|
|
|
use_init_atom_root(cx);
|
|
|
|
let app_settings_ref = use_atom_ref(cx, &APP_SETTINGS);
|
|
let session_ref = use_atom_ref(cx, &SESSION);
|
|
let rooms_ref = use_atom_ref(cx, &ROOMS);
|
|
|
|
let chats_win_state = use_state(cx, || None);
|
|
|
|
let login_coro = use_coroutine(cx, |rx| {
|
|
login(rx, app_settings_ref.clone(), session_ref.clone())
|
|
});
|
|
|
|
let mut sync_rooms_coro = None;
|
|
|
|
if let Some(requester) = &app_settings_ref.read().requester {
|
|
sync_rooms_coro = Some(use_coroutine(cx, |rx| {
|
|
sync_rooms(rx, requester.borrow().receivers.clone(), rooms_ref.clone())
|
|
}));
|
|
}
|
|
|
|
if !session_ref.read().is_logged {
|
|
login_coro.send(false);
|
|
} else {
|
|
if let Some(coro) = sync_rooms_coro {
|
|
coro.send(true);
|
|
}
|
|
|
|
if chats_win_state.is_none() {
|
|
let chats_window = dioxus_desktop::use_window(cx);
|
|
|
|
let receivers = app_settings_ref
|
|
.read()
|
|
.requester
|
|
.as_ref()
|
|
.unwrap()
|
|
.borrow()
|
|
.receivers
|
|
.clone();
|
|
let chats_props = ChatsWindowProps { receivers };
|
|
|
|
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));
|
|
}
|
|
}
|
|
|
|
cx.render(rsx! {
|
|
MainWindow {}
|
|
})
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> anyhow::Result<()> {
|
|
tracing_subscriber::fmt()
|
|
// .pretty()
|
|
.with_max_level(Level::DEBUG)
|
|
.init();
|
|
|
|
dioxus_desktop::launch(App);
|
|
// dioxus_web::launch(App);
|
|
|
|
Ok(())
|
|
}
|