11import { Component , OnDestroy , OnInit , Input , Output } from '@angular/core' ;
22import { combineLatest , BehaviorSubject , Subject , window } from 'rxjs' ;
33import { filter , takeUntil } from 'rxjs/operators' ;
4- import { Protocol , Plan } from "@core" ;
4+ import { Protocol , Plan , ConfigService } from "@core" ;
55import { InstanceDisplayHelper , ScreenArrangement , ScreenResolution } from "./instance-display-helper" ;
66
77@Component ( {
@@ -15,11 +15,13 @@ export class InstanceDisplaySelectComponent implements OnInit, OnDestroy {
1515 private _availableVdiProtocols : Protocol [ ] = null ;
1616 private _vdiProtocol$ : BehaviorSubject < Protocol > = new BehaviorSubject ( null ) ;
1717 private _showAdvancedSettings = false ;
18+ private _plan : Plan ;
1819
1920 private _destroy$ : Subject < boolean > = new Subject < boolean > ( ) ;
2021
2122 private _selectedSingleScreenResolution : BehaviorSubject < ScreenResolution > = new BehaviorSubject < ScreenResolution > ( null ) ;
2223 private _selectedArrangement : BehaviorSubject < ScreenArrangement > = new BehaviorSubject < ScreenArrangement > ( null ) ;
24+ private _vdiProtocolLocalStorageKey : string = InstanceDisplayHelper . USER_INSTANCE_VDI_PROTOCOL_KEY ;
2325
2426 get availableVdiProtocols ( ) : Protocol [ ] {
2527 return this . _availableVdiProtocols ;
@@ -32,13 +34,9 @@ export class InstanceDisplaySelectComponent implements OnInit, OnDestroy {
3234
3335 @Input ( )
3436 set plan ( plan : Plan ) {
37+ this . _plan = plan ;
3538 this . _availableVdiProtocols = plan ?. image . availableVdiProtocols ( ) ;
36- const userPreferredProtocol = this . _availableVdiProtocols ?. find ( protocol => protocol . name === localStorage . getItem ( InstanceDisplayHelper . USER_INSTANCE_VDI_PROTOCOL_KEY ) ) ;
37- if ( userPreferredProtocol ) {
38- this . _vdiProtocol$ . next ( userPreferredProtocol ) ;
39- } else {
40- this . _vdiProtocol$ . next ( plan ?. image . defaultVdiProtocol ? this . _availableVdiProtocols ?. find ( protocol => protocol . id === plan ?. image . defaultVdiProtocol . id ) : null ) ;
41- }
39+ this . _updateVdiProtocol ( ) ;
4240 }
4341
4442 public get destroy$ ( ) : Subject < boolean > {
@@ -82,7 +80,7 @@ export class InstanceDisplaySelectComponent implements OnInit, OnDestroy {
8280
8381 set vdiProtocol ( value : Protocol ) {
8482 this . _vdiProtocol$ . next ( value ) ;
85- localStorage . setItem ( InstanceDisplayHelper . USER_INSTANCE_VDI_PROTOCOL_KEY , value . name ) ;
83+ localStorage . setItem ( this . _vdiProtocolLocalStorageKey , value . name ) ;
8684 }
8785
8886 get vdiProtocolChoiceAvailable ( ) : boolean {
@@ -108,6 +106,9 @@ export class InstanceDisplaySelectComponent implements OnInit, OnDestroy {
108106 @Output ( )
109107 public arrangement : Subject < ScreenArrangement > = new Subject < ScreenArrangement > ( ) ;
110108
109+ constructor ( private _configurationService : ConfigService ) {
110+ }
111+
111112 public ngOnInit ( ) : void {
112113 this . selectedSingleScreenResolution = this . _helper . defaultScreenResolution ;
113114 this . selectedArrangement = this . _helper . defaultArrangement ;
@@ -125,6 +126,17 @@ export class InstanceDisplaySelectComponent implements OnInit, OnDestroy {
125126 ) . subscribe ( arrangement => {
126127 this . arrangement . next ( arrangement ) ;
127128 } )
129+
130+ this . _configurationService . configuration$ ( )
131+ . pipe ( takeUntil ( this . _destroy$ ) )
132+ . subscribe ( ( config ) => {
133+ const vdiProtocolLocalStorageKey = config . metadata [ 'VDI_LOCAL_STORAGE_KEY' ] ;
134+ if ( vdiProtocolLocalStorageKey != null ) {
135+ this . _vdiProtocolLocalStorageKey = vdiProtocolLocalStorageKey ;
136+ localStorage . removeItem ( InstanceDisplayHelper . USER_INSTANCE_VDI_PROTOCOL_KEY ) ;
137+ this . _updateVdiProtocol ( ) ;
138+ }
139+ } ) ;
128140 }
129141
130142 public handleSelectedArrangement ( arrangement : ScreenArrangement ) : void {
@@ -155,4 +167,13 @@ export class InstanceDisplaySelectComponent implements OnInit, OnDestroy {
155167 }
156168 return null ;
157169 }
170+
171+ private _updateVdiProtocol ( ) : void {
172+ const userPreferredProtocol = this . _availableVdiProtocols ?. find ( protocol => protocol . name === localStorage . getItem ( this . _vdiProtocolLocalStorageKey ) ) ;
173+ if ( userPreferredProtocol ) {
174+ this . _vdiProtocol$ . next ( userPreferredProtocol ) ;
175+ } else {
176+ this . _vdiProtocol$ . next ( this . _plan ?. image . defaultVdiProtocol ? this . _availableVdiProtocols ?. find ( protocol => protocol . id === this . _plan ?. image . defaultVdiProtocol . id ) : null ) ;
177+ }
178+ }
158179}
0 commit comments