{ "version": 3, "sources": ["src/app/services/pwa-install/pwa-install.service.ts"], "sourcesContent": ["import { Injectable } from '@angular/core';\r\nimport { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class PwaInstallService {\r\n private deferredPrompt: any;\r\n private iosInstallPrompt$: BehaviorSubject =\r\n new BehaviorSubject(false);\r\n private androidInstallPrompt$: BehaviorSubject =\r\n new BehaviorSubject(false);\r\n\r\n private isInstalled$: BehaviorSubject = new BehaviorSubject(\r\n this.checkIfInstalled(),\r\n );\r\n\r\n initPwaInstall() {\r\n this.detectPlatform();\r\n }\r\n\r\n private isSafari(): boolean {\r\n const userAgent = navigator.userAgent;\r\n const safariRegex = /^(?:(?!chrome|android).)*safari/i;\r\n return safariRegex.test(userAgent);\r\n }\r\n\r\n // Detect whether the device is iOS\r\n private detectPlatform(): void {\r\n const isSafari = this.isSafari();\r\n if (isSafari) {\r\n // iOS specific logic to show a custom installation prompt\r\n this.iosInstallPrompt$.next(true);\r\n }\r\n\r\n // Listen for Android 'beforeinstallprompt' event\r\n window.addEventListener('beforeinstallprompt', (event: Event) => {\r\n // Prevent the default install banner from showing\r\n event.preventDefault();\r\n this.deferredPrompt = event;\r\n this.androidInstallPrompt$.next(true);\r\n });\r\n }\r\n\r\n // Service method to trigger the Android install prompt\r\n public promptInstall(): void {\r\n if (this.deferredPrompt) {\r\n this.deferredPrompt.prompt();\r\n\r\n this.deferredPrompt.userChoice.then(\r\n (choiceResult: { outcome: 'accepted' | 'dismissed' }) => {\r\n if (choiceResult.outcome === 'accepted') {\r\n this.deferredPrompt = null;\r\n this.isInstalled$.next(true);\r\n } else {\r\n console.log('User dismissed the PWA install');\r\n }\r\n },\r\n );\r\n }\r\n }\r\n\r\n // Check if the app is installed (standalone mode)\r\n private checkIfInstalled(): boolean {\r\n const isStandaloneMode = window.matchMedia(\r\n '(display-mode: standalone)',\r\n ).matches;\r\n\r\n const isIosStandalone =\r\n 'standalone' in window.navigator && !!window.navigator['standalone'];\r\n\r\n return isStandaloneMode || isIosStandalone;\r\n }\r\n\r\n // Expose whether to show the iOS install prompt\r\n public getIosInstallPrompt$() {\r\n return this.iosInstallPrompt$.asObservable();\r\n }\r\n\r\n // Expose whether to show the Android install prompt\r\n public getAndroidInstallPrompt$() {\r\n return this.androidInstallPrompt$.asObservable();\r\n }\r\n\r\n public getIsInstalled$() {\r\n return this.isInstalled$.asObservable();\r\n }\r\n}\r\n"], "mappings": "gDAMA,IAAaA,GAAiB,IAAA,CAAxB,MAAOA,CAAiB,CAH9BC,aAAA,CAKU,KAAAC,kBACN,IAAIC,EAAyB,EAAK,EAC5B,KAAAC,sBACN,IAAID,EAAyB,EAAK,EAE5B,KAAAE,aAAyC,IAAIF,EACnD,KAAKG,iBAAgB,CAAE,EAGzBC,gBAAc,CACZ,KAAKC,eAAc,CACrB,CAEQC,UAAQ,CACd,IAAMC,EAAYC,UAAUD,UAE5B,MADoB,mCACDE,KAAKF,CAAS,CACnC,CAGQF,gBAAc,CACH,KAAKC,SAAQ,GAG5B,KAAKP,kBAAkBW,KAAK,EAAI,EAIlCC,OAAOC,iBAAiB,sBAAwBC,GAAgB,CAE9DA,EAAMC,eAAc,EACpB,KAAKC,eAAiBF,EACtB,KAAKZ,sBAAsBS,KAAK,EAAI,CACtC,CAAC,CACH,CAGOM,eAAa,CACd,KAAKD,iBACP,KAAKA,eAAeE,OAAM,EAE1B,KAAKF,eAAeG,WAAWC,KAC5BC,GAAuD,CAClDA,EAAaC,UAAY,YAC3B,KAAKN,eAAiB,KACtB,KAAKb,aAAaQ,KAAK,EAAI,GAE3BY,QAAQC,IAAI,gCAAgC,CAEhD,CAAC,EAGP,CAGQpB,kBAAgB,CACtB,IAAMqB,EAAmBb,OAAOc,WAC9B,4BAA4B,EAC5BC,QAEIC,EACJ,eAAgBhB,OAAOH,WAAa,CAAC,CAACG,OAAOH,UAAU,WAEzD,OAAOgB,GAAoBG,CAC7B,CAGOC,sBAAoB,CACzB,OAAO,KAAK7B,kBAAkB8B,aAAY,CAC5C,CAGOC,0BAAwB,CAC7B,OAAO,KAAK7B,sBAAsB4B,aAAY,CAChD,CAEOE,iBAAe,CACpB,OAAO,KAAK7B,aAAa2B,aAAY,CACvC,iDAhFWhC,EAAiB,CAAA,iCAAjBA,EAAiBmC,QAAjBnC,EAAiBoC,UAAAC,WAFhB,MAAM,CAAA,CAAA,SAEPrC,CAAiB,GAAA", "names": ["PwaInstallService", "constructor", "iosInstallPrompt$", "BehaviorSubject", "androidInstallPrompt$", "isInstalled$", "checkIfInstalled", "initPwaInstall", "detectPlatform", "isSafari", "userAgent", "navigator", "test", "next", "window", "addEventListener", "event", "preventDefault", "deferredPrompt", "promptInstall", "prompt", "userChoice", "then", "choiceResult", "outcome", "console", "log", "isStandaloneMode", "matchMedia", "matches", "isIosStandalone", "getIosInstallPrompt$", "asObservable", "getAndroidInstallPrompt$", "getIsInstalled$", "factory", "\u0275fac", "providedIn"] }