@@ -233,35 +233,26 @@ export class DeviceToolbarComponent implements OnInit {
233233
234234 private loadPowerState ( ) : void {
235235 // Use cached to dedupe simultaneous requests (KVM deep-link + toolbar both loading).
236- this . isLoading ( ) . set ( true )
237- this . devicesService
238- . getPowerStateCached ( this . deviceId ( ) )
239- . pipe (
240- catchError ( ( ) => {
241- // Network/backend failure; silently skip update and let UI show previous state.
242- return EMPTY
243- } ) ,
244- finalize ( ( ) => {
245- this . isLoading ( ) . set ( false )
246- } ) ,
247- takeUntilDestroyed ( this . destroyRef )
248- )
249- . subscribe ( ( powerState ) => {
250- this . setPowerStateLabel ( powerState . powerstate )
251- } )
236+ this . fetchPowerState ( this . devicesService . getPowerStateCached ( this . deviceId ( ) ) )
252237 }
253238
254239 refreshPowerState ( ) : void {
240+ // Bypass the cache so manual refresh always fetches the latest state from the device.
241+ this . fetchPowerState ( this . devicesService . getPowerState ( this . deviceId ( ) ) , ( ) => {
242+ const msg : string = this . translate . instant ( 'kvm.errorRetrievePower.value' )
243+ this . snackBar . open ( msg , undefined , SnackbarDefaults . defaultError )
244+ } )
245+ }
246+
247+ private fetchPowerState ( source : Observable < any > , onError ?: ( ) => void ) : void {
255248 this . isLoading ( ) . set ( true )
256- // Bypass the cache so manual refresh always fetches the latest state from the
257- // device rather than returning a previously cached value.
258- this . devicesService
259- . getPowerState ( this . deviceId ( ) )
249+ source
260250 . pipe (
261251 catchError ( ( err ) => {
262- console . error ( err )
263- const msg : string = this . translate . instant ( 'kvm.errorRetrievePower.value' )
264- this . snackBar . open ( msg , undefined , SnackbarDefaults . defaultError )
252+ if ( onError ) {
253+ console . error ( err )
254+ onError ( )
255+ }
265256 return EMPTY
266257 } ) ,
267258 finalize ( ( ) => {
@@ -475,6 +466,7 @@ export class DeviceToolbarComponent implements OnInit {
475466 const msg : string = this . translate . instant ( 'devices.powerActionSent.value' )
476467 console . log ( 'Power action sent successfully:' , data )
477468 this . snackBar . open ( msg , undefined , SnackbarDefaults . defaultSuccess )
469+ this . refreshPowerState ( )
478470 } else {
479471 console . log ( 'Power action failed:' , data )
480472 const msg : string = this . translate . instant ( 'devices.failPowerAction.value' )
0 commit comments