2025-10-26 02:47:59 +02:00
|
|
|
|
import { defineComponent, ref, computed, onMounted } from 'vue';
|
|
|
|
|
|
import { useGlobalStore } from '@store/globalStore';
|
|
|
|
|
|
import { tools } from '@tools';
|
2022-12-07 18:16:23 +01:00
|
|
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
|
|
name: 'CCheckAppRunning',
|
2025-10-26 02:47:59 +02:00
|
|
|
|
setup() {
|
|
|
|
|
|
const globalStore = useGlobalStore();
|
2022-12-07 18:16:23 +01:00
|
|
|
|
|
2025-10-26 02:47:59 +02:00
|
|
|
|
const isAppRunning = computed(() => globalStore.isAppRunning === true);
|
|
|
|
|
|
const finishLoading = computed(() => globalStore.finishLoading === true);
|
|
|
|
|
|
const deferredPrompt = computed(() => globalStore.deferredPrompt);
|
|
|
|
|
|
const homescreen = computed(() => globalStore.homescreen === true);
|
2022-12-07 18:16:23 +01:00
|
|
|
|
|
2025-10-26 02:47:59 +02:00
|
|
|
|
const viewiOS = ref(false);
|
|
|
|
|
|
const viewAndroid = ref(false);
|
|
|
|
|
|
const showNotice = ref(false);
|
|
|
|
|
|
const showOther = ref(false);
|
2022-12-07 18:16:23 +01:00
|
|
|
|
|
2025-10-26 02:47:59 +02:00
|
|
|
|
// === Rilevamento WebView ===
|
|
|
|
|
|
const currentUrl = window.location.href;
|
2023-01-25 20:52:47 +01:00
|
|
|
|
|
2025-10-26 02:47:59 +02:00
|
|
|
|
const webViewDetectors = [
|
|
|
|
|
|
{ name: 'Telegram', test: /Telegram/ },
|
|
|
|
|
|
{ name: 'WhatsApp', test: /WhatsApp/ },
|
|
|
|
|
|
{ name: 'Facebook', test: /FBAV|FBAN/ },
|
|
|
|
|
|
{ name: 'Instagram', test: /Instagram/ },
|
|
|
|
|
|
{ name: 'Messenger', test: /Messenger/ },
|
|
|
|
|
|
];
|
2023-01-25 20:52:47 +01:00
|
|
|
|
|
2025-10-26 02:47:59 +02:00
|
|
|
|
const matchedWebView = webViewDetectors.find(({ test }) => test.test(navigator.userAgent));
|
|
|
|
|
|
const isInRestrictedWebView = !!matchedWebView;
|
|
|
|
|
|
const webViewName = matchedWebView ? matchedWebView.name : 'un’app';
|
2022-12-20 10:58:55 +01:00
|
|
|
|
|
2025-10-26 02:47:59 +02:00
|
|
|
|
// === Installazione ===
|
2022-12-07 18:16:23 +01:00
|
|
|
|
function installApp() {
|
2023-01-03 16:51:45 +01:00
|
|
|
|
if (globalStore.deferredPrompt) {
|
2025-10-26 02:47:59 +02:00
|
|
|
|
globalStore.deferredPrompt.prompt();
|
2025-03-01 14:14:43 +01:00
|
|
|
|
globalStore.deferredPrompt.userChoice.then((choiceResult: any) => {
|
2023-01-03 16:51:45 +01:00
|
|
|
|
if (choiceResult.outcome === 'accepted') {
|
|
|
|
|
|
globalStore.deferredPrompt = null;
|
|
|
|
|
|
}
|
2025-03-01 14:14:43 +01:00
|
|
|
|
});
|
2023-01-03 16:51:45 +01:00
|
|
|
|
}
|
2022-12-07 18:16:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-26 02:47:59 +02:00
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
tools.checkApp();
|
|
|
|
|
|
});
|
2022-12-07 18:16:23 +01:00
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
tools,
|
|
|
|
|
|
finishLoading,
|
|
|
|
|
|
isAppRunning,
|
2022-12-20 10:58:55 +01:00
|
|
|
|
deferredPrompt,
|
2025-10-26 02:47:59 +02:00
|
|
|
|
homescreen,
|
2023-01-25 20:52:47 +01:00
|
|
|
|
viewiOS,
|
|
|
|
|
|
viewAndroid,
|
2025-10-26 02:47:59 +02:00
|
|
|
|
installApp,
|
|
|
|
|
|
isInRestrictedWebView,
|
|
|
|
|
|
webViewName,
|
|
|
|
|
|
currentUrl,
|
|
|
|
|
|
showNotice,
|
|
|
|
|
|
showOther,
|
|
|
|
|
|
};
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|