Files
myprojplanet_vite/src/components/CCheckAppRunning/CCheckAppRunning.ts

68 lines
1.9 KiB
TypeScript
Raw Normal View History

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 : 'unapp';
2022-12-20 10:58:55 +01:00
// === Installazione ===
function installApp() {
2023-01-03 16:51:45 +01:00
if (globalStore.deferredPrompt) {
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
}
}
onMounted(() => {
tools.checkApp();
});
return {
tools,
finishLoading,
isAppRunning,
2022-12-20 10:58:55 +01:00
deferredPrompt,
homescreen,
viewiOS,
viewAndroid,
installApp,
isInRestrictedWebView,
webViewName,
currentUrl,
showNotice,
showOther,
};
},
});