@@ -20,11 +20,7 @@ use crate::{
20
20
JoinLeaveRoomModalWidgetRefExt ,
21
21
} ,
22
22
login:: login_screen:: LoginAction ,
23
- persistent_state:: {
24
- load_window_state,
25
- save_app_state,
26
- save_window_state,
27
- } ,
23
+ persistence,
28
24
shared:: callout_tooltip:: {
29
25
CalloutTooltipOptions ,
30
26
CalloutTooltipWidgetRefExt ,
@@ -41,7 +37,6 @@ use crate::{
41
37
VerificationModalWidgetRefExt ,
42
38
} ,
43
39
} ;
44
- use serde:: { self , Deserialize , Serialize } ;
45
40
46
41
live_design ! {
47
42
use link:: theme:: * ;
@@ -116,7 +111,7 @@ live_design! {
116
111
// but behind the verification modal.
117
112
new_message_context_menu = <NewMessageContextMenu > { }
118
113
119
- // We want the verification modal to always show up on top of
114
+ // We want the verification modal to always show up in front of
120
115
// all other elements when an incoming verification request is received.
121
116
verification_modal = <Modal > {
122
117
content: {
@@ -153,6 +148,8 @@ impl LiveRegister for App {
153
148
// then other modules widgets.
154
149
makepad_widgets:: live_design ( cx) ;
155
150
crate :: shared:: live_design ( cx) ;
151
+ #[ cfg( feature = "tsp" ) ]
152
+ crate :: tsp:: live_design ( cx) ;
156
153
crate :: settings:: live_design ( cx) ;
157
154
crate :: room:: live_design ( cx) ;
158
155
crate :: join_leave_room_modal:: live_design ( cx) ;
@@ -181,13 +178,20 @@ impl MatchEvent for App {
181
178
// such that background threads/tasks will be able to can access it.
182
179
let _app_data_dir = crate :: app_data_dir ( ) ;
183
180
log ! ( "App::handle_startup(): app_data_dir: {:?}" , _app_data_dir) ;
184
- self . update_login_visibility ( cx) ;
185
181
186
- log ! ( "App::handle_startup(): starting matrix sdk loop" ) ;
187
- crate :: sliding_sync:: start_matrix_tokio ( ) . unwrap ( ) ;
188
- if let Err ( e) = load_window_state ( self . ui . window ( id ! ( main_window) ) , cx) {
182
+ if let Err ( e) = persistence:: load_window_state ( self . ui . window ( id ! ( main_window) ) , cx) {
189
183
error ! ( "Failed to load window state: {}" , e) ;
190
184
}
185
+
186
+ self . update_login_visibility ( cx) ;
187
+
188
+ log ! ( "App::Startup: starting matrix sdk loop" ) ;
189
+ let _tokio_rt = crate :: sliding_sync:: start_matrix_tokio ( ) . unwrap ( ) ;
190
+
191
+ #[ cfg( feature = "tsp" ) ] {
192
+ log ! ( "App::Startup: initializing TSP (Trust Spanning Protocol) module." ) ;
193
+ crate :: tsp:: tsp_init ( _tokio_rt) . unwrap ( ) ;
194
+ }
191
195
}
192
196
193
197
fn handle_actions ( & mut self , cx : & mut Cx , actions : & Actions ) {
@@ -353,13 +357,34 @@ impl AppMain for App {
353
357
354
358
if let Event :: Shutdown = event {
355
359
let window_ref = self . ui . window ( id ! ( main_window) ) ;
356
- if let Err ( e) = save_window_state ( window_ref, cx) {
357
- error ! ( "Failed to save window state. Error details : {}" , e ) ;
360
+ if let Err ( e) = persistence :: save_window_state ( window_ref, cx) {
361
+ error ! ( "Failed to save window state. Error: {e}" ) ;
358
362
}
359
363
if let Some ( user_id) = current_user_id ( ) {
360
364
let app_state = self . app_state . clone ( ) ;
361
- if let Err ( e) = save_app_state ( app_state, user_id) {
362
- error ! ( "Failed to save app state. Error details: {}" , e) ;
365
+ if let Err ( e) = persistence:: save_app_state ( app_state, user_id) {
366
+ error ! ( "Failed to save app state. Error: {e}" ) ;
367
+ }
368
+ }
369
+ #[ cfg( feature = "tsp" ) ] {
370
+ // Save the TSP wallet state, if it exists, with a 3-second timeout.
371
+ let tsp_state = std:: mem:: take ( & mut * crate :: tsp:: tsp_state_ref ( ) . lock ( ) . unwrap ( ) ) ;
372
+ if tsp_state. has_content ( ) {
373
+ let res = crate :: sliding_sync:: block_on_async_with_timeout (
374
+ Some ( std:: time:: Duration :: from_secs ( 3 ) ) ,
375
+ async move {
376
+ match tsp_state. close_and_serialize ( ) . await {
377
+ Ok ( saved_state) => match persistence:: save_tsp_state_async ( saved_state) . await {
378
+ Ok ( _) => { }
379
+ Err ( e) => error ! ( "Failed to save TSP wallet state. Error: {e}" ) ,
380
+ }
381
+ Err ( e) => error ! ( "Failed to close and serialize TSP wallet state. Error: {e}" ) ,
382
+ }
383
+ } ,
384
+ ) ;
385
+ if let Err ( _e) = res {
386
+ error ! ( "Failed to save TSP wallet state before app shutdown. Error: Timed Out." ) ;
387
+ }
363
388
}
364
389
}
365
390
}
@@ -517,14 +542,3 @@ pub enum AppStateAction {
517
542
RoomLoadedSuccessfully ( OwnedRoomId ) ,
518
543
None ,
519
544
}
520
-
521
- #[ derive( Default , Debug , Clone , PartialEq , Serialize , Deserialize ) ]
522
- /// The state of the window geometry
523
- pub struct WindowGeomState {
524
- /// A tuple containing the window's width and height.
525
- pub inner_size : ( f64 , f64 ) ,
526
- /// A tuple containing the window's x and y position.
527
- pub position : ( f64 , f64 ) ,
528
- /// Maximise fullscreen if true.
529
- pub is_fullscreen : bool ,
530
- }
0 commit comments