@@ -3,6 +3,7 @@ import { BehaviorSubject, lastValueFrom } from 'rxjs';
33import { AppListApiService } from './api/app-list-api.service' ;
44import { ProtectedApp } from '../models/protected-app' ;
55import { ApiResponse } from '../models/api-response' ;
6+ import { GlobalStateService } from './global-state.service' ;
67
78@Injectable ( {
89 providedIn : 'root'
@@ -12,7 +13,7 @@ export class AppListService {
1213 private applistSubject = new BehaviorSubject < ProtectedApp [ ] > ( [ ] ) ;
1314 applist$ = this . applistSubject . asObservable ( ) ;
1415
15- constructor ( private applistApi : AppListApiService ) { }
16+ constructor ( private applistApi : AppListApiService , private globalState : GlobalStateService ) { }
1617
1718 get applist ( ) : ProtectedApp [ ] {
1819 return this . applistSubject ?. value || [ ] ;
@@ -24,7 +25,13 @@ export class AppListService {
2425 async getAppList ( ) : Promise < ApiResponse > {
2526 try {
2627 const apiResponse = await lastValueFrom ( this . applistApi . getAppList ( ) ) ;
27- if ( apiResponse . type == 'success' ) this . applist = apiResponse . data as ProtectedApp [ ] ;
28+ if ( apiResponse . type == 'success' ) {
29+ this . applist = apiResponse . data as ProtectedApp [ ] ;
30+ if ( ! this . applist . find ( app => app . id == this . globalState . selectedApp . id ) ) {
31+ const defaultApp = this . applist . find ( app => app . namespace == 'default' && app . application == 'default' ) ;
32+ this . globalState . selectedApp = defaultApp || this . applist [ 0 ] ;
33+ }
34+ }
2835 return apiResponse ;
2936 } catch ( error ) {
3037 return { type : 'error' , message : 'Error when fetching app list' } ;
0 commit comments