From 61485c67ac00a20b70822cc6751e2c82a9324c8e Mon Sep 17 00:00:00 2001 From: Evgeny Stepanovych Date: Sat, 25 Nov 2023 09:27:22 +0100 Subject: [PATCH] NAS-124602: Reload UI during updates --- .../manualupdate/manualupdate.component.ts | 3 -- .../pages/system/update/update.component.ts | 2 -- src/app/services/update.service.ts | 31 +++++++++++++------ 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/app/pages/system/update/manualupdate/manualupdate.component.ts b/src/app/pages/system/update/manualupdate/manualupdate.component.ts index c7c9f640875..3e7a47d5059 100644 --- a/src/app/pages/system/update/manualupdate/manualupdate.component.ts +++ b/src/app/pages/system/update/manualupdate/manualupdate.component.ts @@ -85,7 +85,6 @@ export class ManualUpdateComponent extends ViewControllerComponent { public translate: TranslateService, private dialogService: DialogService, private systemService: SystemGeneralService, - private updateService: UpdateService, ) { super(); @@ -164,14 +163,12 @@ export class ManualUpdateComponent extends ViewControllerComponent { this.dialogRef.close(false); if (!this.isHA) { if (ures[0].attributes.preferences['rebootAfterManualUpdate']) { - this.updateService.setForHardRefresh(); this.router.navigate(['/others/reboot'], { skipLocationChange: true }); } else { this.translate.get('Restart').subscribe((reboot: string) => { this.translate.get(helptext.rebootAfterManualUpdate.manual_reboot_msg).subscribe((reboot_prompt: string) => { this.dialogService.confirm(reboot, reboot_prompt).subscribe((reboot_res) => { if (reboot_res) { - this.updateService.setForHardRefresh(); this.router.navigate(['/others/reboot'], { skipLocationChange: true }); } }); diff --git a/src/app/pages/system/update/update.component.ts b/src/app/pages/system/update/update.component.ts index 5e6eb65ae21..3608d7cd328 100644 --- a/src/app/pages/system/update/update.component.ts +++ b/src/app/pages/system/update/update.component.ts @@ -105,7 +105,6 @@ export class UpdateComponent implements OnInit, OnDestroy { protected storage: StorageService, protected http: HttpClient, public core: CoreService, - private updateService: UpdateService, ) { this.sysGenService.updateRunning.subscribe((res) => { res === 'true' ? this.isUpdateRunning = true : this.isUpdateRunning = false; @@ -400,7 +399,6 @@ export class UpdateComponent implements OnInit, OnDestroy { this.dialogRef.componentInstance.jobId = jobId; this.dialogRef.componentInstance.wsshow(); this.dialogRef.componentInstance.success.subscribe((res) => { - this.updateService.setForHardRefresh(); this.router.navigate(['/others/reboot'], { skipLocationChange: true }); }); this.dialogRef.componentInstance.failure.subscribe((err) => { diff --git a/src/app/services/update.service.ts b/src/app/services/update.service.ts index b78324c2635..c803baea89d 100644 --- a/src/app/services/update.service.ts +++ b/src/app/services/update.service.ts @@ -1,27 +1,40 @@ import { Inject, Injectable } from '@angular/core'; +import { Observable } from 'rxjs'; +import { tap } from 'rxjs/operators'; import { WINDOW } from 'app/helpers/window.helper'; +import { ApiTimestamp } from 'app/interfaces/api-date.interface'; +import { WebSocketService } from 'app/services/ws.service'; @Injectable({ providedIn: 'root', }) export class UpdateService { + private lastSeenBuiltTime: number; + constructor( + private ws: WebSocketService, @Inject(WINDOW) private window: Window, ) {} /** * Hard refresh is needed to load new html and js after the update. */ - setForHardRefresh(): void { - this.window.localStorage.setItem('hardRefresh', 'true'); - } + hardRefreshIfNeeded(): Observable { + return this.ws.call('system.build_time').pipe( + tap((buildTime: ApiTimestamp) => { + if (!this.lastSeenBuiltTime) { + // First boot. + this.lastSeenBuiltTime = buildTime.$date; + return; + } - hardRefreshIfNeeded(): void { - if (this.window.localStorage.getItem('hardRefresh') !== 'true') { - return; - } + if (this.lastSeenBuiltTime === buildTime.$date) { + // No update. + return; + } - this.window.localStorage.removeItem('hardRefresh'); - this.window.location.reload(); + this.window.location.reload(); + }), + ); } }