правка
This commit is contained in:
gofnnp 2023-01-13 03:13:06 +04:00
parent c7ade7515c
commit b33ed15666
2 changed files with 4 additions and 31 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "fashion-logica", "name": "fashion-logica",
"version": "0.0.3", "version": "0.0.4",
"scripts": { "scripts": {
"ng": "ng", "ng": "ng",
"start": "ng serve --host 192.168.0.14", "start": "ng serve --host 192.168.0.14",

View File

@ -18,31 +18,10 @@ export class DownloadAppDirective implements OnInit {
private messageService: MessageService, private messageService: MessageService,
public renderer: Renderer2, public renderer: Renderer2,
private el: ElementRef 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();
// }, 0);
// if (
// (this.deviceType == 'android' && this.deferredPrompt) ||
// this.deviceType == 'ios'
// ) {
// console.log(this.deviceType);
// console.log(this.deferredPrompt);
// this.el.nativeElement.style.display = 'block';
// }
}
ngOnInit(): void { ngOnInit(): void {
this.getTypeDevice() this.getTypeDevice();
if (this.deviceType === 'ios') { if (this.deviceType === 'ios') {
this.el.nativeElement.style.display = 'block'; this.el.nativeElement.style.display = 'block';
} }
@ -50,7 +29,6 @@ export class DownloadAppDirective implements OnInit {
@HostListener('window:beforeinstallprompt', ['$event']) @HostListener('window:beforeinstallprompt', ['$event'])
onBeforeInstallPrompt(e: any) { onBeforeInstallPrompt(e: any) {
console.log(e);
e.preventDefault(); e.preventDefault();
this.deferredPrompt = e; this.deferredPrompt = e;
if (this.deferredPrompt) { if (this.deferredPrompt) {
@ -60,7 +38,6 @@ export class DownloadAppDirective implements OnInit {
@HostListener('window:appinstalled', ['$event']) @HostListener('window:appinstalled', ['$event'])
onAppInstalled(e: any) { onAppInstalled(e: any) {
console.log(e);
// Prevent Chrome 67 and earlier from automatically showing the prompt // Prevent Chrome 67 and earlier from automatically showing the prompt
e.preventDefault(); e.preventDefault();
// Stash the event so it can be triggered later. // Stash the event so it can be triggered later.
@ -68,11 +45,8 @@ export class DownloadAppDirective implements OnInit {
this.el.nativeElement.style.display = 'none'; this.el.nativeElement.style.display = 'none';
} }
getTypeDevice() { getTypeDevice() {
const userAgent = window.navigator.userAgent.toLowerCase(); const userAgent = window.navigator.userAgent.toLowerCase();
console.log(userAgent);
const ios = /iphone|ipod|ipad/.test(userAgent); const ios = /iphone|ipod|ipad/.test(userAgent);
this.deviceType = ios ? 'ios' : 'android'; this.deviceType = ios ? 'ios' : 'android';
} }
@ -86,7 +60,7 @@ export class DownloadAppDirective implements OnInit {
this.messageService.add({ this.messageService.add({
severity: 'custom', severity: 'custom',
summary: `Для установки нажмите на кнопку поделиться в Вашем браузере и выберите пункт 'На экран «Домой»'`, summary: `Для установки нажмите на кнопку поделиться в Вашем браузере и выберите пункт 'На экран «Домой»'`,
sticky: true, life: 5,
}); });
return; return;
} }
@ -104,7 +78,6 @@ export class DownloadAppDirective implements OnInit {
severity: 'custom', severity: 'custom',
summary: 'Спасибо за установку!', summary: 'Спасибо за установку!',
}); });
console.log('User Accepted!!!');
} }
this.deferredPrompt = null; this.deferredPrompt = null;
}); });