@@ -209,49 +209,58 @@ function attachOnReadyProcess() {
209209
210210 async function startApp ( attempt = 0 ) {
211211 const data = store . getFromDisk ( )
212- store . updateStore ( data , 'startApp' )
213- log ( 'START APP, retry:' , attempt )
214- if ( ! store . store . connection ) {
215- log ( 'NO CONNECTION' , attempt , store . store )
216- if ( attempt >= 3 )
217- SplashScreenController . instance . window . emit ( IPC_EVENTS . SHOW_NO_CONNECTION )
218- retryAppStart = setTimeout ( ( ) => {
219- startApp ( ++ attempt )
220- } , 1000 )
221- } else {
222- if ( retryAppStart ) {
223- clearTimeout ( retryAppStart )
224- }
225- const auth : AuthAppData | undefined = store . store [ 'auth' ]
226- await getPermissions ( )
227- if ( auth ?. isFirstStart !== undefined && ! auth ?. isFirstStart ) {
228- const isLastUserLogged = await AccountController . instance . autoLogin ( )
229- if ( isLastUserLogged ) {
230- ipcMain . emit ( IPC_EVENTS . LOGIN , undefined , { showNethlink : true } )
212+ if ( checkData ( data ) ) {
213+ store . updateStore ( data , 'startApp' )
214+ log ( 'START APP, retry:' , attempt )
215+ if ( ! store . store . connection ) {
216+ log ( 'NO CONNECTION' , attempt , store . store )
217+ if ( attempt >= 3 )
218+ SplashScreenController . instance . window . emit ( IPC_EVENTS . SHOW_NO_CONNECTION )
219+ retryAppStart = setTimeout ( ( ) => {
220+ startApp ( ++ attempt )
221+ } , 1000 )
222+ } else {
223+ if ( retryAppStart ) {
224+ clearTimeout ( retryAppStart )
225+ }
226+ const auth : AuthAppData | undefined = store . store [ 'auth' ]
227+ await getPermissions ( )
228+ if ( auth ?. isFirstStart !== undefined && ! auth ?. isFirstStart ) {
229+ const isLastUserLogged = await AccountController . instance . autoLogin ( )
230+ if ( isLastUserLogged ) {
231+ ipcMain . emit ( IPC_EVENTS . LOGIN , undefined , { showNethlink : true } )
232+ } else {
233+ store . updateStore ( {
234+ auth : {
235+ ...store . store [ 'auth' ] ! ,
236+ lastUser : undefined ,
237+ lastUserCryptPsw : undefined
238+ } ,
239+ account : undefined ,
240+ theme : 'system' ,
241+ connection : store . store [ 'connection' ] || false ,
242+ } , 'showLogin' )
243+ showLogin ( )
244+ }
231245 } else {
232- store . updateStore ( {
233- auth : {
234- ...store . store [ 'auth' ] ! ,
235- lastUser : undefined ,
236- lastUserCryptPsw : undefined
237- } ,
238- account : undefined ,
239- theme : 'system' ,
240- connection : store . store [ 'connection' ] || false ,
241- } , 'showLogin' )
246+ await resetApp ( )
242247 showLogin ( )
243248 }
244- } else {
245- await resetApp ( )
246- showLogin ( )
249+ SplashScreenController . instance . window . quit ( true )
250+ //once the loading is complete I enable the ability to click on the icon in the tray
251+ TrayController . instance . updateTray ( {
252+ enableShowButton : true
253+ } )
247254 }
255+ } else {
256+ await resetApp ( )
257+ showLogin ( )
248258 SplashScreenController . instance . window . quit ( true )
249259 //once the loading is complete I enable the ability to click on the icon in the tray
250260 TrayController . instance . updateTray ( {
251261 enableShowButton : true
252262 } )
253263 }
254-
255264 }
256265
257266 app . on ( 'window-all-closed' , ( ) => {
@@ -417,7 +426,7 @@ function attachThemeChangeListener() {
417426 store . set ( 'theme' , updatedSystemTheme )
418427 }
419428 //update theme state on the store
420- TrayController . instance . changeIconByTheme ( updatedSystemTheme )
429+ TrayController . instance ? .changeIconByTheme ( updatedSystemTheme )
421430 } )
422431}
423432/**
@@ -485,5 +494,14 @@ async function checkForUpdate() {
485494 }
486495}
487496
497+ function checkData ( data : any ) : boolean {
498+ log ( { data } )
499+ return data . hasOwnProperty ( 'account' ) &&
500+ data . hasOwnProperty ( 'auth' ) &&
501+ data . hasOwnProperty ( 'theme' ) &&
502+ data . hasOwnProperty ( 'connection' )
503+ }
504+
488505//BEGIN APP
489506startup ( )
507+
0 commit comments