tauri_plugin_matrix_svelte/matrix/
mod.rs1use matrix_sdk::Client;
2use session::{restore_client_from_session, try_get_session};
3use tauri::{AppHandle, Manager, Runtime};
4
5pub mod emoji_verification;
6pub mod event_preview;
7pub mod events;
8pub mod login;
9pub mod notifications;
10pub mod requests;
11pub mod room;
12pub mod rooms;
13pub mod session;
14pub mod singletons;
15pub mod stores;
16pub mod sync;
17pub mod timeline;
18pub mod user_power_level;
19pub mod user_profile;
20pub mod utils;
21pub mod workers;
22
23pub async fn create_session_to_state<R: Runtime>(
24 app_handle: &AppHandle<R>,
25 request: login::LoginRequest,
26) -> crate::Result<Client> {
27 let snapshot_path = app_handle
28 .state::<crate::stronghold::SnapshotPath>()
29 .0
30 .clone();
31
32 let initial_client =
33 login::get_client_from_new_session(&app_handle, request, &snapshot_path).await?;
34 let client_with_handlers = events::add_event_handlers(initial_client, &app_handle)?;
35 Ok(client_with_handlers)
36}
37
38pub async fn try_restore_session_to_state<R: Runtime>(
39 app_handle: &AppHandle<R>,
40) -> crate::Result<Option<Client>> {
41 let snapshot_path = app_handle
42 .state::<crate::stronghold::SnapshotPath>()
43 .0
44 .clone();
45
46 let session_option = try_get_session(&app_handle, snapshot_path).await?;
47
48 match session_option {
49 Some(session) => {
50 let initial_client = restore_client_from_session(session).await?;
51 let client_with_handlers = events::add_event_handlers(initial_client, &app_handle)?;
52 Ok(Some(client_with_handlers))
53 } None => Ok(None),
55 }
56}