правка
This commit is contained in:
gofnnp 2023-01-12 02:41:31 +04:00
parent dbf01e4fc5
commit 7a895c76a6

View File

@ -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({