@@ -2,17 +2,22 @@ import { AppState, EVENTS } from './config.js';
22import { mathChannels } from './mathchannels.js' ;
33import { messenger } from './bus.js' ;
44import { dbManager } from './dbmanager.js' ;
5+ import { Preferences } from './preferences.js' ;
56
67class ProjectManager {
78 #currentProject;
89 #isReplaying;
910 #libraryContainer;
1011
1112 constructor ( ) {
12- this . #currentProject =
13- this . #loadFromStorage( ) || this . #createEmptyProject( ) ;
1413 this . #isReplaying = false ;
1514 this . #libraryContainer = null ;
15+ this . #currentProject = this . #createEmptyProject( ) ;
16+ }
17+
18+ init ( ) {
19+ this . #currentProject =
20+ this . #loadFromStorage( ) || this . #createEmptyProject( ) ;
1621
1722 dbManager . init ( ) . then ( async ( ) => {
1823 await this . #hydrateActiveFiles( ) ;
@@ -185,6 +190,8 @@ class ProjectManager {
185190
186191 messenger . emit ( 'ui:set-loading' , { message : 'Restoring Session...' } ) ;
187192
193+ let actuallyLoaded = false ;
194+
188195 for ( const res of activeResources ) {
189196 if ( res . dbId && ! AppState . files . some ( ( f ) => f . dbId === res . dbId ) ) {
190197 const signals = await dbManager . getFileSignals ( res . dbId ) ;
@@ -202,13 +209,26 @@ class ProjectManager {
202209 size : meta . size ,
203210 metadata : meta . metadata ,
204211 } ) ;
212+ actuallyLoaded = true ;
213+ } else {
214+ res . isActive = false ;
205215 }
206216 }
207217 }
208218
209- if ( AppState . files . length > 0 ) {
219+ if ( actuallyLoaded ) {
210220 messenger . emit ( 'dataprocessor:batch-load-completed' , { } ) ;
221+
222+ requestAnimationFrame ( ( ) => {
223+ this . replayHistory ( ) ;
224+ } ) ;
225+ } else {
226+ messenger . emit ( 'dataprocessor:batch-load-completed' , { } ) ;
227+ messenger . emit ( 'ui:updateDataLoadedState' , { status : false } ) ;
211228 }
229+ messenger . emit ( 'dataprocessor:batch-load-completed' , { } ) ;
230+
231+ this . #saveToStorage( ) ;
212232 }
213233
214234 registerFile ( file ) {
@@ -284,8 +304,23 @@ class ProjectManager {
284304 }
285305
286306 #loadFromStorage( ) {
287- const data = localStorage . getItem ( 'current_project' ) ;
288- return data ? JSON . parse ( data ) : null ;
307+ if ( Preferences . prefs . rememberFiles ) {
308+ const data = localStorage . getItem ( 'current_project' ) ;
309+ return data ? JSON . parse ( data ) : null ;
310+ } else {
311+ const data = localStorage . getItem ( 'current_project' ) ;
312+ if ( data ) {
313+ const project = JSON . parse ( data ) ;
314+
315+ if ( project && project . resources ) {
316+ project . resources . forEach ( ( resource ) => {
317+ resource . isActive = false ;
318+ } ) ;
319+ }
320+
321+ return project ;
322+ }
323+ }
289324 }
290325
291326 #saveToStorage( ) {
0 commit comments