From 6d55ca2b1413fb224914bca60c51fac305c92ab7 Mon Sep 17 00:00:00 2001 From: nikolay Date: Thu, 22 Jun 2023 11:48:12 +0400 Subject: [PATCH] =?UTF-8?q?dev=20#14384=20=D0=9F=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA=20=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F=20WPA=20?= =?UTF-8?q?=D0=9A=D0=BE=D1=84=D0=B5=D0=9B=D0=B0=D0=B9=D0=BA:=20check=20if?= =?UTF-8?q?=20app=20is=20in=20installed=20apps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/directives/.#download-app.directive.ts | 1 - .../src/app/directives/download-app.directive.ts | 13 +++++++------ .../components/navbar/navbar.component.ts | 4 +--- angular/src/app/utils.ts | 8 +++++++- angular/src/environments/environment.prod.ts | 15 ++++++++------- angular/src/environments/environment.ts | 1 + 6 files changed, 24 insertions(+), 18 deletions(-) delete mode 120000 angular/src/app/directives/.#download-app.directive.ts diff --git a/angular/src/app/directives/.#download-app.directive.ts b/angular/src/app/directives/.#download-app.directive.ts deleted file mode 120000 index 0a3f76c..0000000 --- a/angular/src/app/directives/.#download-app.directive.ts +++ /dev/null @@ -1 +0,0 @@ -nikolay@arch.3860:1687414554 \ No newline at end of file diff --git a/angular/src/app/directives/download-app.directive.ts b/angular/src/app/directives/download-app.directive.ts index a97740a..9b2d3b6 100644 --- a/angular/src/app/directives/download-app.directive.ts +++ b/angular/src/app/directives/download-app.directive.ts @@ -4,14 +4,10 @@ import { HostListener, OnInit, Renderer2, - Inject, } from '@angular/core'; import { MessageService } from 'primeng/api'; -import { CookiesService } from 'src/app/services/cookies.service'; - -import { AppleWalletService } from 'src/app/services/apple-wallet.service'; -import { getTypeDevice } from 'src/app/utils'; +import { getTypeDevice, pwaInstalled } from 'src/app/utils'; @Directive({ selector: '[appDownloadApp]', @@ -31,7 +27,12 @@ export class DownloadAppDirective implements OnInit { if (this.deviceType === 'ios') { this.el.nativeElement.style.display = 'block'; } - if (window.matchMedia('(display-mode: standalone)').matches) { + this.checkInstalled(); + } + + async checkInstalled(): Promise { + if (window.matchMedia('(display-mode: standalone)').matches + || await pwaInstalled()) { this.el.nativeElement.style.display = 'none'; } } diff --git a/angular/src/app/presentation-options/default-option/components/navbar/navbar.component.ts b/angular/src/app/presentation-options/default-option/components/navbar/navbar.component.ts index 94862ca..14e3362 100644 --- a/angular/src/app/presentation-options/default-option/components/navbar/navbar.component.ts +++ b/angular/src/app/presentation-options/default-option/components/navbar/navbar.component.ts @@ -1,6 +1,6 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { MessagingService } from 'src/app/services/messaging.service'; -import { getTypeDevice, DeviceType, pwaInstalled } from 'src/app/utils'; +import { getTypeDevice, DeviceType } from 'src/app/utils'; import { AppleWalletService } from 'src/app/services/apple-wallet.service'; import { CookiesService } from 'src/app/services/cookies.service'; import { MatBottomSheet } from '@angular/material/bottom-sheet'; @@ -40,8 +40,6 @@ export class NavbarComponent implements OnInit { const deviceType = getTypeDevice(); this.showMenu = deviceType === DeviceType.ios; - - pwaInstalled(); } toggleMenu() { diff --git a/angular/src/app/utils.ts b/angular/src/app/utils.ts index f0c03f4..84080be 100644 --- a/angular/src/app/utils.ts +++ b/angular/src/app/utils.ts @@ -1,3 +1,5 @@ +import { environment } from "src/environments/environment.prod"; + export enum DeviceType { ios, android, @@ -12,7 +14,11 @@ export function getTypeDevice(): DeviceType { export async function pwaInstalled(): Promise { if ("getInstalledRelatedApps" in navigator) { const apps = await (window.navigator as any).getInstalledRelatedApps(); - console.log(apps) + for (const app of apps) { + if (app.url == environment.manifestUrl) { + return true; + } + } } return false; } diff --git a/angular/src/environments/environment.prod.ts b/angular/src/environments/environment.prod.ts index 7bd0e70..7c134fa 100644 --- a/angular/src/environments/environment.prod.ts +++ b/angular/src/environments/environment.prod.ts @@ -8,14 +8,15 @@ export const environment = { hasBonusProgram: true, systemId: 'tsQ2cu59Xz9qgGTm3z', defaultUrl: 'https://coffee-like-test.lk.crm4retail.ru', + manifestUrl: 'https://coffee-like-test.lk.crm4retail.ru/manifest.webmanifest', firebase: { - apiKey: "AIzaSyDTb_xuMz2vDx8xGs34AJiltraKVlwmrtY", - authDomain: "coffee-like-77bfe.firebaseapp.com", - projectId: "coffee-like-77bfe", - storageBucket: "coffee-like-77bfe.appspot.com", - messagingSenderId: "1094726277369", - appId: "1:1094726277369:web:8af560662da7700e7a2a28" - }, + apiKey: "AIzaSyDTb_xuMz2vDx8xGs34AJiltraKVlwmrtY", + authDomain: "coffee-like-77bfe.firebaseapp.com", + projectId: "coffee-like-77bfe", + storageBucket: "coffee-like-77bfe.appspot.com", + messagingSenderId: "1094726277369", + appId: "1:1094726277369:web:8af560662da7700e7a2a28" + }, version: packageJson.version, appleWalletEndpoint: 'https://apple-wallet-iiko.it-retail.tech/apns/api', icardProxy: 'https://coffee-like-test.lk.crm4retail.ru/api/icard-proxy/', diff --git a/angular/src/environments/environment.ts b/angular/src/environments/environment.ts index d859ede..0c278ea 100644 --- a/angular/src/environments/environment.ts +++ b/angular/src/environments/environment.ts @@ -8,6 +8,7 @@ export const environment = { hasBonusProgram: true, systemId: 'tsQ2cu59Xz9qgGTm3z', defaultUrl: 'http://192.168.0.179:4200', + manifestUrl: 'https://coffee-like-test.lk.crm4retail.ru/manifest.webmanifest', firebase: { apiKey: "AIzaSyDTb_xuMz2vDx8xGs34AJiltraKVlwmrtY", authDomain: "coffee-like-77bfe.firebaseapp.com",