From 6df62db4c769172a6ad129355cc662986a65017d Mon Sep 17 00:00:00 2001 From: Alex Kulagin Date: Tue, 28 Jan 2020 15:31:28 +0500 Subject: [PATCH] add module providers --- .../src/lib/ngx-pwa-install.providers.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 projects/ngx-pwa-install/src/lib/ngx-pwa-install.providers.ts 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 +});