Created
August 7, 2018 08:11
-
-
Save whisher/62914a169d01c1b5628fcbe6e1f237a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class PwaService { | |
| promptEvent: ServiceWorkerEvent; | |
| constructor(private swUpdate: SwUpdate, platform: PlatformService) { | |
| if(platform.isBrowser() && environment.production){ | |
| console.log('hello browser'); | |
| swUpdate.available.subscribe(event => { | |
| console.log('current version is', event.current); | |
| console.log('available version is', event.available); | |
| if (window.confirm('Want to update?')) { | |
| swUpdate.activateUpdate().then(() => { | |
| console.log('Update'); | |
| document.location.reload(); | |
| }); | |
| } | |
| }); | |
| swUpdate.activated.subscribe(event => { | |
| console.log('old version was', event.previous); | |
| console.log('new version is', event.current); | |
| }); | |
| window.addEventListener('beforeinstallprompt', event => { | |
| this.promptEvent = event; | |
| }); | |
| this.install(); | |
| interval(6 * 60 * 60).subscribe(() => swUpdate.checkForUpdate()); | |
| } | |
| } | |
| install(): void { | |
| if(this.promptEvent){ | |
| this.promptEvent.prompt(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment