@@ -71,7 +71,7 @@ use crate::{
71
71
tab:: { self , HeadingOptions , ItemMetadata , Location , Tab , HOVER_DURATION } ,
72
72
} ;
73
73
74
- #[ derive( Clone , Debug ) ]
74
+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
75
75
pub enum Mode {
76
76
App ,
77
77
Desktop ,
@@ -297,10 +297,12 @@ pub enum Message {
297
297
Rename ( Option < Entity > ) ,
298
298
ReplaceResult ( ReplaceResult ) ,
299
299
RestoreFromTrash ( Option < Entity > ) ,
300
+ SaveSession ,
300
301
SearchActivate ,
301
302
SearchClear ,
302
303
SearchInput ( String ) ,
303
304
SearchSubmit ,
305
+ SessionConfig ( crate :: config:: Session ) ,
304
306
SystemThemeModeChange ( cosmic_theme:: ThemeMode ) ,
305
307
TabActivate ( Entity ) ,
306
308
TabNext ,
@@ -1127,6 +1129,19 @@ impl App {
1127
1129
)
1128
1130
} )
1129
1131
. into( ) ,
1132
+ widget:: settings:: view_section( fl!( "settings-general" ) )
1133
+ . add(
1134
+ widget:: settings:: item:: builder( fl!( "settings-restore-session" ) ) . toggler(
1135
+ self . config. session. restore,
1136
+ move |restore| {
1137
+ Message :: SessionConfig ( crate :: config:: Session {
1138
+ restore,
1139
+ ..Default :: default ( )
1140
+ } )
1141
+ } ,
1142
+ ) ,
1143
+ )
1144
+ . into( ) ,
1130
1145
] )
1131
1146
. into ( )
1132
1147
}
@@ -2134,6 +2149,24 @@ impl Application for App {
2134
2149
self . operation ( Operation :: Restore { paths } ) ;
2135
2150
}
2136
2151
}
2152
+ Message :: SaveSession => {
2153
+ if self . config . session . restore && self . mode == Mode :: App {
2154
+ let session = crate :: config:: Session {
2155
+ tabs : Some (
2156
+ self . tab_model
2157
+ . iter ( )
2158
+ . filter_map ( |entity| {
2159
+ self . tab_model
2160
+ . data :: < Tab > ( entity)
2161
+ . map ( |tab| tab. location . clone ( ) )
2162
+ } )
2163
+ . collect ( ) ,
2164
+ ) ,
2165
+ ..self . config . session
2166
+ } ;
2167
+ config_set ! ( session, session) ;
2168
+ }
2169
+ }
2137
2170
Message :: SearchActivate => {
2138
2171
self . search_active = true ;
2139
2172
return widget:: text_input:: focus ( self . search_id . clone ( ) ) ;
@@ -2163,6 +2196,9 @@ impl Application for App {
2163
2196
return self . search ( ) ;
2164
2197
}
2165
2198
}
2199
+ Message :: SessionConfig ( session) => {
2200
+ config_set ! ( session, session) ;
2201
+ }
2166
2202
Message :: SystemThemeModeChange ( _theme_mode) => {
2167
2203
return self . update_config ( ) ;
2168
2204
}
@@ -2480,6 +2516,7 @@ impl Application for App {
2480
2516
if let Some ( window_id) = self . window_id_opt . take ( ) {
2481
2517
return Command :: batch ( [
2482
2518
window:: close ( window_id) ,
2519
+ Command :: perform ( async move { message:: app ( Message :: SaveSession ) } , |x| x) ,
2483
2520
Command :: perform ( async move { message:: app ( Message :: MaybeExit ) } , |x| x) ,
2484
2521
] ) ;
2485
2522
}
0 commit comments