import { defineComponent, ref, computed, onMounted } from 'vue'; import { useGlobalStore } from '@store/globalStore'; import { tools } from '@tools'; export default defineComponent({ name: 'CCheckAppRunning', setup() { const globalStore = useGlobalStore(); const isAppRunning = computed(() => globalStore.isAppRunning === true); const finishLoading = computed(() => globalStore.finishLoading === true); const deferredPrompt = computed(() => globalStore.deferredPrompt); const homescreen = computed(() => globalStore.homescreen === true); const viewiOS = ref(false); const viewAndroid = ref(false); const showNotice = ref(false); const showOther = ref(false); // === Rilevamento WebView === const currentUrl = window.location.href; const webViewDetectors = [ { name: 'Telegram', test: /Telegram/ }, { name: 'WhatsApp', test: /WhatsApp/ }, { name: 'Facebook', test: /FBAV|FBAN/ }, { name: 'Instagram', test: /Instagram/ }, { name: 'Messenger', test: /Messenger/ }, ]; const matchedWebView = webViewDetectors.find(({ test }) => test.test(navigator.userAgent)); const isInRestrictedWebView = !!matchedWebView; const webViewName = matchedWebView ? matchedWebView.name : 'un’app'; // === Installazione === function installApp() { if (globalStore.deferredPrompt) { globalStore.deferredPrompt.prompt(); globalStore.deferredPrompt.userChoice.then((choiceResult: any) => { if (choiceResult.outcome === 'accepted') { globalStore.deferredPrompt = null; } }); } } onMounted(() => { tools.checkApp(); }); return { tools, finishLoading, isAppRunning, deferredPrompt, homescreen, viewiOS, viewAndroid, installApp, isInRestrictedWebView, webViewName, currentUrl, showNotice, showOther, }; }, });