PWA final fix
This commit is contained in:
@@ -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"
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,15 +19,10 @@ export class AuthInterceptor implements HttpInterceptor {
|
||||
) { }
|
||||
|
||||
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
|
||||
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}`),
|
||||
}));
|
||||
|
||||
@@ -34,8 +34,7 @@
|
||||
Layers
|
||||
</a>
|
||||
<mat-divider></mat-divider>
|
||||
<a mat-list-item (click)="reloadApp()">
|
||||
<mat-icon class="menu-icon">refresh</mat-icon>
|
||||
<a mat-list-item>
|
||||
{{appVersion}}
|
||||
</a>
|
||||
</mat-nav-list>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,12 +41,10 @@ bootstrapApplication(AppComponent, {
|
||||
},
|
||||
provideAnimations(),
|
||||
provideHttpClient(withInterceptorsFromDi()),
|
||||
/*
|
||||
provideServiceWorker('ngsw-worker.js', {
|
||||
enabled: !isDevMode(),
|
||||
registrationStrategy: 'registerWhenStable:30000'
|
||||
})
|
||||
*/
|
||||
]
|
||||
})
|
||||
.catch(err => console.error(err));
|
||||
|
||||
Reference in New Issue
Block a user