@@ -647,35 +647,47 @@ function initApp(dispatch: AppDispatch) {
647647 } ;
648648
649649 // Load FPFSS user info and check that profile works
650- ( ( ) => {
651- const userBase64 = localStorage . getItem ( 'fpfss_user' ) ;
652- if ( userBase64 ) {
653- try {
654- const user = JSON . parse ( Buffer . from ( userBase64 , 'base64' ) . toString ( 'utf-8' ) ) as FpfssUser ;
655- // Test profile uri
656- const profileUrl = `${ window . Shared . initialPreferences . fpfssBaseUrl } /api/profile` ;
657- axios . get ( profileUrl , {
658- headers : {
659- 'Authorization' : `Bearer ${ user . accessToken } `
660- }
661- } )
662- . then ( ( res ) => {
663- // Success, use most recent info and save to storage and state
664- user . username = res . data [ 'Username' ] ;
665- user . avatarUrl = res . data [ 'AvatarURL' ] ;
666- user . roles = res . data [ 'Roles' ] ;
667- dispatch ( setFpfssUser ( user ) ) ;
668- } )
669- . catch ( ( ) => {
670- // Failed auth
671- localStorage . removeItem ( 'fpfss_user' ) ;
672- } ) ;
673- } catch ( err ) {
674- log . error ( 'Launcher' , 'Fpfss saved auth was invalid, clearing...' ) ;
650+ const userBase64 = localStorage . getItem ( 'fpfss_user' ) ;
651+ if ( userBase64 ) {
652+ try {
653+ const user = JSON . parse ( Buffer . from ( userBase64 , 'base64' ) . toString ( 'utf-8' ) ) as FpfssUser ;
654+ // Test profile uri
655+ const profileUrl = `${ window . Shared . initialPreferences . fpfssBaseUrl } /api/profile` ;
656+ axios . get ( profileUrl , {
657+ headers : {
658+ 'Authorization' : `Bearer ${ user . accessToken } `
659+ }
660+ } )
661+ . then ( ( res ) => {
662+ // Success, use most recent info and save to storage and state
663+ user . username = res . data [ 'Username' ] ;
664+ user . avatarUrl = res . data [ 'AvatarURL' ] ;
665+ user . roles = res . data [ 'Roles' ] ;
666+ dispatch ( setFpfssUser ( user ) ) ;
667+ } )
668+ . catch ( ( ) => {
669+ // Failed auth
675670 localStorage . removeItem ( 'fpfss_user' ) ;
676- }
671+ } ) ;
672+ } catch ( err ) {
673+ log . error ( 'Launcher' , 'Fpfss saved auth was invalid, clearing...' ) ;
674+ localStorage . removeItem ( 'fpfss_user' ) ;
677675 }
678- } ) ( ) ;
676+ }
677+
678+ if ( window . electronAPI !== undefined ) {
679+ // Only exit after window closure if we're running under Electron
680+ window . onbeforeunload = ( event : BeforeUnloadEvent ) => {
681+ event . stopPropagation ( ) ;
682+ setTimeout ( ( ) => {
683+ window . Shared . back . allowDeath ( ) ;
684+ window . Shared . back . request ( BackIn . QUIT )
685+ . finally ( ( ) => {
686+ window . close ( ) ;
687+ } ) ;
688+ } , 100 ) ;
689+ } ;
690+ }
679691
680692 registerWebsocketListeners ( dispatch ) ;
681693}
0 commit comments