diff --git a/angular/src/app/directives/download-app.directive.ts b/angular/src/app/directives/download-app.directive.ts index b0b35a1..d664418 100644 --- a/angular/src/app/directives/download-app.directive.ts +++ b/angular/src/app/directives/download-app.directive.ts @@ -1,4 +1,10 @@ -import { Directive, ElementRef, HostListener, OnInit, Renderer2 } from '@angular/core'; +import { + Directive, + ElementRef, + HostListener, + OnInit, + Renderer2, +} from '@angular/core'; import { MessageService } from 'primeng/api'; @Directive({ @@ -17,27 +23,32 @@ export class DownloadAppDirective implements OnInit { e.preventDefault(); console.log('#: ', e); this.deferredPrompt = e; + + this.getTypeDevice(); + + if ( + !( + (this.deviceType == 'android' && this.deferredPrompt) || + this.deviceType == 'ios' + ) + ) { + console.log(this.deviceType); + console.log(this.deferredPrompt); + + this.el.nativeElement.style.display = 'none'; + } }); this.renderer.listen('window', 'appinstalled', (evt) => { console.log('INSTALLED!!!'); }); } - ngOnInit(): void { - this.getTypeDevice(); - - if (!((this.deviceType == 'android' && this.deferredPrompt) || this.deviceType == 'ios')) { - console.log(this.deviceType); - console.log(this.deferredPrompt); - - this.el.nativeElement.style.display = 'none' - } - } + ngOnInit(): void {} getTypeDevice() { const userAgent = window.navigator.userAgent.toLowerCase(); console.log(userAgent); - + const ios = /iphone|ipod|ipad/.test(userAgent); this.deviceType = ios ? 'ios' : 'android'; } @@ -51,9 +62,9 @@ export class DownloadAppDirective implements OnInit { this.messageService.add({ severity: 'custom', summary: `Для установки нажмите на кнопку поделиться в Вашем браузере и выберите пункт 'На экран «Домой»'`, - sticky: true + sticky: true, }); - return + return; } if (!this.deferredPrompt) { this.messageService.add({