Created
July 29, 2018 12:54
-
-
Save whisher/bd8a0e01ac197f15638ed2899e172da2 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
| import { Injectable } from '@angular/core'; | |
| import { SwUpdate } from '@angular/service-worker'; | |
| import { PlatformService } from '../platform/platform.service'; | |
| type ServiceWorkerEvent = any; | |
| @Injectable({ | |
| providedIn: 'root' | |
| }) | |
| export class PwaService { | |
| //promptEvent: BeforeInstallPromptEvent as EventTarget; | |
| promptEvent: ServiceWorkerEvent; | |
| constructor(private swUpdate: SwUpdate, platform: PlatformService) { | |
| if(platform.isBrowser()){ | |
| swUpdate.available.subscribe(event => { | |
| if (window.confirm('Want to update?')) { | |
| window.location.reload(); | |
| } | |
| }); | |
| window.addEventListener('beforeinstallprompt', event => { | |
| this.promptEvent = event; | |
| }); | |
| } | |
| } | |
| 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