diff --git a/Frontend/src/app/app.component.ts b/Frontend/src/app/app.component.ts index 956fff5..cba7e9b 100644 --- a/Frontend/src/app/app.component.ts +++ b/Frontend/src/app/app.component.ts @@ -1,48 +1,42 @@ import { Component } from '@angular/core'; import { RouterOutlet } from '@angular/router'; -import { SwUpdate } from '@angular/service-worker'; -import { NotificationsService } from './services/notifications.service'; +import { SwUpdate, VersionReadyEvent } from '@angular/service-worker'; import { environment } from 'src/environments/environment'; +import { NotificationsService } from './services/notifications.service'; +import { filter } from 'rxjs'; @Component({ - selector: 'app-root', - templateUrl: './app.component.html', - styleUrls: ['./app.component.scss'], - standalone: true, - imports: [RouterOutlet] + selector: 'app-root', + templateUrl: './app.component.html', + styleUrls: ['./app.component.scss'], + standalone: true, + imports: [RouterOutlet] }) export class AppComponent { constructor( - // private readonly _swUpdate: SwUpdate, - //private _notifications: NotificationsService + private readonly _swUpdate: SwUpdate, + private _notifications: NotificationsService ) { - /* - console.log('Start versionUpdates subscribe', this._swUpdate.isEnabled, environment.production); if (this._swUpdate.isEnabled && environment.production) { - this._swUpdate.versionUpdates.subscribe((evt) => { - console.log('versionUpdates', evt); - switch (evt.type) { - case 'VERSION_READY': - this._swUpdate.activateUpdate().then(() => { + this._swUpdate.versionUpdates + .pipe(filter((evt): evt is VersionReadyEvent => evt.type === 'VERSION_READY')) + .subscribe((evt) => { + this._notifications.add({ + text: "New version available. DiunaBI will restart in 10 seconds.", + duration: 10000, + dismiss: () => { + window.location.reload() + }, + btn: 'Cancel', + action: () => { this._notifications.add({ - text: "New version available. DiunaBI will restart in 10 seconds.", - duration: 10000, - dismiss: () => { - window.location.reload() - }, - btn: 'Cancel', - action: () => { - this._notifications.add({ - text: "Restart canceled.", - btn: "Hide" - }); - } - }) - }); - break; - } - }); + text: "Restart canceled.", + btn: "Hide" + }); + } + }) + }); } - */ + } - } +} diff --git a/Frontend/src/app/interceptors/auth.interceptor.ts b/Frontend/src/app/interceptors/auth.interceptor.ts index bfefc4a..5164200 100644 --- a/Frontend/src/app/interceptors/auth.interceptor.ts +++ b/Frontend/src/app/interceptors/auth.interceptor.ts @@ -19,15 +19,10 @@ export class AuthInterceptor implements HttpInterceptor { ) { } intercept(request: HttpRequest, next: HttpHandler): Observable> { - console.log('Welcome to interceptor:', request.url); - console.log('IsAuth?', request.url.includes('/auth/apiToken')); if (!request.url.includes('/auth/apiToken')) { - console.log(this.auth$.expirationTime.format(), moment.utc().format()); if (this.auth$.expirationTime.isBefore(moment.utc())) { - console.log('Need to refresh token'); return this.auth$.getAPITokenObservable().pipe( mergeMap(() => { - console.log('New token is ready'); return next.handle(request.clone({ headers: request.headers.set('Authorization', `Bearer ${this.auth$.apiToken}`), })); @@ -43,7 +38,6 @@ export class AuthInterceptor implements HttpInterceptor { }) ); } else { - console.log('TOken is fine'); return next.handle(request.clone({ headers: request.headers.set('Authorization', `Bearer ${this.auth$.apiToken}`), })); diff --git a/Frontend/src/app/main-view/main-view.component.html b/Frontend/src/app/main-view/main-view.component.html index c0bb23d..4799714 100644 --- a/Frontend/src/app/main-view/main-view.component.html +++ b/Frontend/src/app/main-view/main-view.component.html @@ -34,8 +34,7 @@ Layers - - refresh + {{appVersion}} diff --git a/Frontend/src/app/main-view/main-view.component.ts b/Frontend/src/app/main-view/main-view.component.ts index cc1098c..de43402 100644 --- a/Frontend/src/app/main-view/main-view.component.ts +++ b/Frontend/src/app/main-view/main-view.component.ts @@ -1,7 +1,6 @@ import { Component, NgZone, ViewChild } from '@angular/core'; import { MatSidenav, MatSidenavModule } from '@angular/material/sidenav'; import { NavigationStart, Router, RouterLink, RouterOutlet } from '@angular/router'; -import { SwUpdate } from '@angular/service-worker'; import * as moment from 'moment'; import packageInfo from 'package.json'; import { delay } from 'rxjs'; @@ -9,7 +8,6 @@ import { environment } from 'src/environments/environment'; import { AuthService } from '../auth/auth.service'; import { DataService } from '../services/data.service'; import { DeviceService } from '../services/device.service'; -import { NotificationsService } from '../services/notifications.service'; import { MatDividerModule } from '@angular/material/divider'; import { MatListModule } from '@angular/material/list'; import { MatButtonModule } from '@angular/material/button'; @@ -38,13 +36,9 @@ export class MainViewComponent { public data$: DataService, public device$: DeviceService, private router$: Router, - private swUpdate$: SwUpdate, private ngZone$: NgZone, public auth$: AuthService, ) { - this.swUpdate$.versionUpdates.subscribe(() => { - this.reloadApp(); - }); this.router$.events.subscribe((event) => { if (event instanceof NavigationStart && device$.isMobile()) { this.snav?.close(); @@ -58,13 +52,10 @@ export class MainViewComponent { }); }); } - reloadApp() { - document.location.reload(); - } logout() { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore google.accounts.id.disableAutoSelect(); - this.reloadApp(); + window.location.reload(); } } diff --git a/Frontend/src/main.ts b/Frontend/src/main.ts index d1b0f91..db4889f 100644 --- a/Frontend/src/main.ts +++ b/Frontend/src/main.ts @@ -41,12 +41,10 @@ bootstrapApplication(AppComponent, { }, provideAnimations(), provideHttpClient(withInterceptorsFromDi()), - /* provideServiceWorker('ngsw-worker.js', { enabled: !isDevMode(), registrationStrategy: 'registerWhenStable:30000' }) - */ ] }) .catch(err => console.error(err));