@@ -4256,6 +4256,50 @@ function addEventListeners(done)
42564256 done ( ) ;
42574257} //addEventListeners
42584258
4259+ // Mark all windows as remembered
4260+ function rememberAll ( )
4261+ {
4262+ var modified = false ;
4263+ L . log . info ( 'Marking all windows as remembered' )
4264+ try {
4265+ const root = T . treeobj . get_node ( $ . jstree . root ) ;
4266+ root . children . forEach ( ( kid_node_id , kid_idx ) => {
4267+ const val = D . windows . by_node_id ( kid_node_id ) ;
4268+ if ( val && ( val . keep !== K . WIN_KEEP ) ) {
4269+ modified = true ;
4270+ M . remember ( kid_node_id ) ;
4271+ }
4272+ } ) ;
4273+
4274+ } catch ( e ) {
4275+ log . warn ( { 'Failure when trying to auto-remember windows' : e } )
4276+ // But don't throw the error since we still want to save the tree.
4277+ }
4278+
4279+ if ( modified ) {
4280+ saveTree ( ) ;
4281+ }
4282+ } //rememberAll
4283+
4284+ // Timer handler to call rememberAll() and set the next timer.
4285+ function autoRememberAll ( minutes , only_start_timer = false )
4286+ {
4287+ if ( ! only_start_timer ) {
4288+ rememberAll ( ) ;
4289+ }
4290+
4291+ L . log . info ( `Starting autoremember timer for ${ minutes } minute(s)` ) ;
4292+ window . setTimeout ( ( ) => { autoRememberAll ( minutes ) } , minutes * 60 * 1000 ) ;
4293+ } // autoRememberAll
4294+
4295+ function startAutoRememberTimerIfRequested ( done ) {
4296+ const minutes = S . getInt ( S . S_AUTOREMEMBER_MINUTES , 0 ) ;
4297+ if ( minutes > 0 ) {
4298+ autoRememberAll ( minutes , true ) ; // true => just start the timer
4299+ }
4300+ done ( ) ;
4301+ } // startAutoRememberTimerIfRequested()
4302+
42594303/// The last function to be called after all other initialization has
42604304/// completed successfully.
42614305function initTreeFinal ( done )
@@ -4364,6 +4408,8 @@ function main()
43644408 if ( spinner ) spinner . spin ( $ ( '#tabfern-container' ) [ 0 ] ) ;
43654409 } ;
43664410
4411+ // --- Init steps ---
4412+
43674413 s . then ( determine_devel_mode )
43684414 . then ( basicInit )
43694415
@@ -4393,16 +4439,23 @@ function main()
43934439 } )
43944440 . then ( addOpenWindowsToTree )
43954441 . then ( addEventListeners )
4396- . then ( initTreeFinal )
4442+ . then ( initTreeFinal ) // This needs to be the last real init step
4443+
4444+ . val ( check_init_step_count ) // This is a sanity check after initTreeFinal
43974445
4398- . val ( check_init_step_count )
4446+ // --- Post-init steps ---
43994447
44004448 // Stop the spinner, if it started
44014449 . val ( ( ) => {
44024450 spinner . stop ( ) ;
44034451 spinner = null ;
44044452 } )
44054453
4454+ // Start the autoremember timer now that all the state is consistent
4455+ . then ( startAutoRememberTimerIfRequested )
4456+
4457+ // --- Error handling ---
4458+
44064459 . or ( ( err ) => {
44074460 $ ( K . INIT_MSG_SEL ) . text (
44084461 $ ( K . INIT_MSG_SEL ) . text ( ) + "\n" + err
0 commit comments