Skip to content

Commit

Permalink
NAS-124602: Reload UI during updates
Browse files Browse the repository at this point in the history
  • Loading branch information
undsoft committed Nov 25, 2023
1 parent 36baebd commit 61485c6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export class ManualUpdateComponent extends ViewControllerComponent {
public translate: TranslateService,
private dialogService: DialogService,
private systemService: SystemGeneralService,
private updateService: UpdateService,
) {
super();

Expand Down Expand Up @@ -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 });
}
});
Expand Down
2 changes: 0 additions & 2 deletions src/app/pages/system/update/update.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) => {
Expand Down
31 changes: 22 additions & 9 deletions src/app/services/update.service.ts
Original file line number Diff line number Diff line change
@@ -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<unknown> {
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();
}),
);
}
}

0 comments on commit 61485c6

Please sign in to comment.