diff --git a/angular/src/app/directives/download-app.directive.ts b/angular/src/app/directives/download-app.directive.ts index 8ce6c16..2eaf8a1 100644 --- a/angular/src/app/directives/download-app.directive.ts +++ b/angular/src/app/directives/download-app.directive.ts @@ -19,33 +19,54 @@ export class DownloadAppDirective implements OnInit { public renderer: Renderer2, private el: ElementRef ) { - setTimeout(() => { - this.renderer.listen('window', 'beforeinstallprompt', (e) => { - e.preventDefault(); - console.log('#: ', e); - this.deferredPrompt = e; - - }); - this.renderer.listen('window', 'appinstalled', (evt) => { - console.log('INSTALLED!!!'); - }); - this.getTypeDevice(); + // setTimeout(() => { + // this.renderer.listen('window', 'beforeinstallprompt', (e) => { + // e.preventDefault(); + // console.log('#: ', e); + // this.deferredPrompt = e; + // }); + // this.renderer.listen('window', 'appinstalled', (evt) => { + // console.log('INSTALLED!!!'); + // }); + // this.getTypeDevice(); + // }, 0); + // if ( + // (this.deviceType == 'android' && this.deferredPrompt) || + // this.deviceType == 'ios' + // ) { + // console.log(this.deviceType); + // console.log(this.deferredPrompt); - }, 0) - if ( - !( - (this.deviceType == 'android' && this.deferredPrompt) || - this.deviceType == 'ios' - ) - ) { - console.log(this.deviceType); - console.log(this.deferredPrompt); + // this.el.nativeElement.style.display = 'block'; + // } + } - this.el.nativeElement.style.display = 'none'; + ngOnInit(): void { + this.getTypeDevice() + if (this.deviceType === 'ios') { + this.el.nativeElement.style.display = 'block'; + } + } + + @HostListener('window:beforeinstallprompt', ['$event']) + onBeforeInstallPrompt(e: any) { + console.log(e); + e.preventDefault(); + this.deferredPrompt = e; + } + + @HostListener('window:appinstalled', ['$event']) + onAppInstalled(e: any) { + console.log(e); + // Prevent Chrome 67 and earlier from automatically showing the prompt + e.preventDefault(); + // Stash the event so it can be triggered later. + this.deferredPrompt = e; + if (this.deferredPrompt) { + this.el.nativeElement.style.display = 'block'; } } - ngOnInit(): void {} getTypeDevice() { const userAgent = window.navigator.userAgent.toLowerCase(); diff --git a/angular/src/app/pages/account/account.component.html b/angular/src/app/pages/account/account.component.html index b687b60..39afb06 100644 --- a/angular/src/app/pages/account/account.component.html +++ b/angular/src/app/pages/account/account.component.html @@ -57,7 +57,7 @@