From 7a895c76a6623315f34b145a3ab43c13893d9cd5 Mon Sep 17 00:00:00 2001 From: gofnnp Date: Thu, 12 Jan 2023 02:41:31 +0400 Subject: [PATCH] =?UTF-8?q?dev=20#13538=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/directives/download-app.directive.ts | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) 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({