♻️ Replace flume with tokio and share Matrix client infos to chats

- 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).
This commit is contained in:
2023-12-25 23:14:43 +01:00
parent d7ba8130d3
commit ddeb94e887
8 changed files with 223 additions and 192 deletions

View File

@@ -9,7 +9,7 @@ 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;
use crate::components::chats_window::chats_window::{ChatsWindow, ChatsWindowProps};
use crate::components::main_window::MainWindow;
mod base;
@@ -23,47 +23,63 @@ fn App(cx: Scope) -> Element {
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 sync_rooms_coro = use_coroutine(cx, |rx| {
sync_rooms(rx, app_settings_ref.clone(), rooms_ref.clone())
});
let mut sync_rooms_coro = None;
let is_logged = session_ref.read().is_logged;
login_coro.send(is_logged);
if is_logged {
sync_rooms_coro.send(is_logged);
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())
}));
}
let chats_win_state = use_state(cx, || None);
if is_logged && chats_win_state.is_none() {
let chats_window = dioxus_desktop::use_window(cx);
let chats_dom = VirtualDom::new(ChatsWindow);
let window_cfg = Config::default().with_custom_head(
r#"
<style type="text/css">
html, body {
height: 100%;
width: 100%;
margin: 0;
if !session_ref.read().is_logged {
login_coro.send(false);
} else {
if let Some(coro) = sync_rooms_coro {
coro.send(true);
}
#main, #bodywrap {
height: 100%;
width: 100%;
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));
}
</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! {