diff --git a/projects/ngx-pwa-install/src/lib/ngx-pwa-install.providers.ts b/projects/ngx-pwa-install/src/lib/ngx-pwa-install.providers.ts new file mode 100644 index 0000000..9de9732 --- /dev/null +++ b/projects/ngx-pwa-install/src/lib/ngx-pwa-install.providers.ts @@ -0,0 +1,17 @@ +import { InjectionToken } from '@angular/core'; +import { fromEvent, ReplaySubject } from 'rxjs'; +import { tap } from 'rxjs/operators'; + +export const beforeInstallPromptFactory = () => { + const event$ = fromEvent(window, 'beforeinstallprompt') + .pipe( + tap(e => e.preventDefault()), + ); + const beforeInstallPromptSubject = new ReplaySubject(); + event$.subscribe(beforeInstallPromptSubject); + return beforeInstallPromptSubject; +}; +export const BeforeInstallPrompt = new InjectionToken>('BeforeInstallPrompt', { + providedIn: 'root', + factory: beforeInstallPromptFactory +});