Skip to content
Permalink
Browse files

added the service worker update and snackbar notification code

  • Loading branch information...
ademidun committed Sep 29, 2018
1 parent 358b60a commit 1c89769041369dbbc73c6be2d2c695f91689adad
Showing with 21 additions and 1 deletion.
  1. +21 −1 src/app/app.component.ts
@@ -11,6 +11,7 @@ import {
import { Title } from '@angular/platform-browser';
import {environment} from '../environments/environment';
import {MatSnackBar} from '@angular/material';
import {SwUpdate} from "@angular/service-worker";

// import 'google.analytics'
declare const ga: any;
@@ -27,8 +28,9 @@ export class AppComponent implements AfterViewInit, OnInit {
constructor(titleService: Title,
public router: Router,
public snackBar: MatSnackBar,
public swUpdate: SwUpdate,
) {

console.log({swUpdate});
// Set title when route changes
router.events.subscribe(event => {
if (event instanceof NavigationEnd) {
@@ -49,6 +51,24 @@ export class AppComponent implements AfterViewInit, OnInit {
}

ngOnInit() {
if (true) {

// check service worker to see if new version of app is available
if (this.swUpdate.isEnabled) {

this.swUpdate.available.subscribe(() => {

const snackBarRef = this.snackBar.open('New version available', 'Load New Version');

snackBarRef.onAction().subscribe(
() => {
location.reload();
}
);

});
}
}
}

ngAfterViewInit(): void {

0 comments on commit 1c89769

Please sign in to comment.
You can’t perform that action at this time.