From 2a97456c0f6c6174eb5d19f36a8356a07b9c740c Mon Sep 17 00:00:00 2001 From: Surya Paolo Date: Tue, 20 Dec 2022 10:58:55 +0100 Subject: [PATCH] fix isAppRunning --- .env.development | 2 +- .env.example.production | 2 +- _ALL_SITES/riso.app/.env.development | 2 +- _ALL_SITES/riso.app/.env.production | 2 +- .../terradellavisione.app/.env.development | 2 +- src/App.ts | 19 ++--------------- .../CCheckAppRunning/CCheckAppRunning.ts | 21 ++++++++++++------- src/components/CSignIn/CSignIn.ts | 2 ++ src/components/CSignUp/CSignUp.ts | 4 +++- src/components/CSignUp/CSignUp.vue | 1 + src/components/CSkill/CSkill.ts | 1 + src/mixins/mixin-operator.ts | 2 +- src/model/GlobalStore.ts | 1 + src/store/Modules/tools.ts | 21 +++++++++++++++++++ src/store/UserStore.ts | 8 ++++--- src/store/globalStore.ts | 1 + src/views/user/myactivities/myactivities.vue | 2 +- 17 files changed, 57 insertions(+), 36 deletions(-) diff --git a/.env.development b/.env.development index b7ec499f..80d9f213 100755 --- a/.env.development +++ b/.env.development @@ -1,4 +1,4 @@ -APP_VERSION="0.5.44" +APP_VERSION="0.5.46" SERVICE_WORKER_FILE="service-worker.js" APP_ID="13" DIRECTORY_LOCAL="newfreeplanet" diff --git a/.env.example.production b/.env.example.production index aa3c1323..9821604d 100755 --- a/.env.example.production +++ b/.env.example.production @@ -1,4 +1,4 @@ -APP_VERSION="0.5.44" +APP_VERSION="0.5.46" SERVICE_WORKER_FILE="service-worker.js" APP_ID="13" DIRECTORY_LOCAL=newfreeplanet diff --git a/_ALL_SITES/riso.app/.env.development b/_ALL_SITES/riso.app/.env.development index b7ec499f..80d9f213 100755 --- a/_ALL_SITES/riso.app/.env.development +++ b/_ALL_SITES/riso.app/.env.development @@ -1,4 +1,4 @@ -APP_VERSION="0.5.44" +APP_VERSION="0.5.46" SERVICE_WORKER_FILE="service-worker.js" APP_ID="13" DIRECTORY_LOCAL="newfreeplanet" diff --git a/_ALL_SITES/riso.app/.env.production b/_ALL_SITES/riso.app/.env.production index be4c2a40..65d22d66 100644 --- a/_ALL_SITES/riso.app/.env.production +++ b/_ALL_SITES/riso.app/.env.production @@ -1,4 +1,4 @@ -APP_VERSION="0.5.44" +APP_VERSION="0.5.46" SERVICE_WORKER_FILE="service-worker.js" APP_ID="13" DIRECTORY_LOCAL=newfreeplanet diff --git a/_ALL_SITES/terradellavisione.app/.env.development b/_ALL_SITES/terradellavisione.app/.env.development index e283501b..14aeab0f 100755 --- a/_ALL_SITES/terradellavisione.app/.env.development +++ b/_ALL_SITES/terradellavisione.app/.env.development @@ -1,4 +1,4 @@ -APP_VERSION="0.5.44" +APP_VERSION="0.5.46" SERVICE_WORKER_FILE="service-worker.js" APP_ID="14" DIRECTORY_LOCAL="newfreeplanet" diff --git a/src/App.ts b/src/App.ts index f8d21983..88eda102 100755 --- a/src/App.ts +++ b/src/App.ts @@ -75,29 +75,14 @@ export default { console.log('scrolled') } } - - let displayMode = 'browser'; - const mqStandAlone = '(display-mode: standalone)'; - if (navigator) - console.log('navigator') - // @ts-ignore - if (navigator && navigator.standalone) - console.log('navigator.standalone') - // @ts-ignore - if (((navigator && (navigator.standalone))) || - (window.matchMedia(mqStandAlone).matches)) { - console.log('navigator.standalone') - displayMode = 'standalone' - } - - globalStore.isAppRunning = displayMode === 'standalone'; - console.log('isapp running = ', globalStore.isAppRunning) } + function mounted() { darkcookie.value = tools.getCookie('darkmode', false, false, false) === '-1' scroll() + tools.checkApp() } diff --git a/src/components/CCheckAppRunning/CCheckAppRunning.ts b/src/components/CCheckAppRunning/CCheckAppRunning.ts index 40b011f8..4357b6e7 100755 --- a/src/components/CCheckAppRunning/CCheckAppRunning.ts +++ b/src/components/CCheckAppRunning/CCheckAppRunning.ts @@ -1,4 +1,4 @@ -import { defineComponent, ref, computed, PropType, toRef } from 'vue' +import { defineComponent, ref, computed, PropType, toRef, onMounted } from 'vue' import { useUserStore } from '@store/UserStore' import { useRouter } from 'vue-router' import { useGlobalStore } from '@store/globalStore' @@ -19,36 +19,41 @@ export default defineComponent({ const globalStore = useGlobalStore() const { t } = useI18n() - const deferredPrompt = ref(null) - const isAppRunning = computed(() => globalStore.isAppRunning ) const finishLoading = computed(() => globalStore.finishLoading) + const deferredPrompt = computed(() => globalStore.deferredPrompt) + function initprompt() { window.addEventListener('beforeinstallprompt', (event) => { event.preventDefault() console.log('beforeinstallprompt !') // Stash the event so it can be triggered later. - deferredPrompt.value = event + globalStore.deferredPrompt = event }) } function installApp() { - if (deferredPrompt.value) - deferredPrompt.value.prompt() + if (globalStore.deferredPrompt) + globalStore.deferredPrompt.prompt() } - initprompt() + function mounted() { + initprompt() + tools.checkApp() + } + + onMounted(mounted) return { userStore, tools, costanti, finishLoading, - deferredPrompt, installApp, isAppRunning, + deferredPrompt, } } }) diff --git a/src/components/CSignIn/CSignIn.ts b/src/components/CSignIn/CSignIn.ts index 143a5bd7..1d37177a 100755 --- a/src/components/CSignIn/CSignIn.ts +++ b/src/components/CSignIn/CSignIn.ts @@ -103,6 +103,8 @@ export default defineComponent({ userStore.signin($router, signin.value) .then((riscode: any) => { console.log('signin FINITO CALL: riscode=', riscode) + tools.checkApp() + if ($q.screen.lt.sm) { globalStore.setleftDrawerOpen(false) } diff --git a/src/components/CSignUp/CSignUp.ts b/src/components/CSignUp/CSignUp.ts index ce553b07..93a5c0cf 100755 --- a/src/components/CSignUp/CSignUp.ts +++ b/src/components/CSignUp/CSignUp.ts @@ -87,6 +87,7 @@ export default defineComponent({ const isalreadyReg = ref(false) const needTelegram = ref(false) const slide = ref('1') + const inputAportador = ref(null) const inputEmail = ref(null) const inputUsername = ref(null) const inputName = ref(null) @@ -98,7 +99,7 @@ export default defineComponent({ let ret = true if (slide.value === '1') { // Invitante + Email - ret = !signup.email || !v$.value.aportador_solidario || v$.value.aportador_solidario.$invalid || (inputEmail.value && inputEmail.value.hasError) + ret = !signup.email || !signup.aportador_solidario || inputAportador.value.hasError || (inputEmail.value && inputEmail.value.hasError) } else if (slide.value === '2') { // Username ret = !signup.username || (inputUsername.value && inputUsername.value.hasError) @@ -391,6 +392,7 @@ export default defineComponent({ needTelegram, slide, checkifDisabled, + inputAportador, inputEmail, inputUsername, inputName, diff --git a/src/components/CSignUp/CSignUp.vue b/src/components/CSignUp/CSignUp.vue index d6636e95..7a9788d1 100755 --- a/src/components/CSignUp/CSignUp.vue +++ b/src/components/CSignUp/CSignUp.vue @@ -113,6 +113,7 @@ showaportador && signup.aportador_solidario !== tools.APORTADOR_NONE " + ref="inputAportador" bg-color="lightblue" :readonly="!!ap_iniziale" v-model="signup.aportador_solidario" diff --git a/src/components/CSkill/CSkill.ts b/src/components/CSkill/CSkill.ts index 7a2720cc..2e4c498c 100755 --- a/src/components/CSkill/CSkill.ts +++ b/src/components/CSkill/CSkill.ts @@ -156,6 +156,7 @@ export default defineComponent({ comune: 1, userId: 1, username: 1, + name: 1, surname: 1, lasttimeonline: 1, mycities: 1, diff --git a/src/mixins/mixin-operator.ts b/src/mixins/mixin-operator.ts index f48b4ca8..e093dedc 100755 --- a/src/mixins/mixin-operator.ts +++ b/src/mixins/mixin-operator.ts @@ -34,7 +34,7 @@ export default function () { function getTeacherByUsername(username: string) { const op = getOperatorByUsername(username) if (!!op) { - return op.name ? op.name : '' + ' ' + op.surname ? op.surname : '' + return (op.name ? op.name : '') + ' ' + op.surname ? op.surname : '' } else { return '' } diff --git a/src/model/GlobalStore.ts b/src/model/GlobalStore.ts index 41118b03..53ddf437 100755 --- a/src/model/GlobalStore.ts +++ b/src/model/GlobalStore.ts @@ -457,6 +457,7 @@ export interface IGlobalState { myselector: ISelector, addNewRecord: string, isAppRunning: boolean + deferredPrompt: any } export interface IMenuList { diff --git a/src/store/Modules/tools.ts b/src/store/Modules/tools.ts index 399e2100..45e97f6e 100644 --- a/src/store/Modules/tools.ts +++ b/src/store/Modules/tools.ts @@ -7394,6 +7394,27 @@ export const tools = { return myarr }, + checkApp() { + const globalStore = useGlobalStore() + + try { + let displayMode = 'browser'; + const mqStandAlone = '(display-mode: standalone)'; + // @ts-ignore + if (((navigator && (navigator.standalone))) || + (window.matchMedia(mqStandAlone).matches)) { + console.log('navigator.standalone') + displayMode = 'standalone' + } + console.log('displayMode = ', displayMode) + + globalStore.isAppRunning = displayMode === 'standalone'; + } catch (e) { + console.log('error navigator.standalone ?!') + } + }, + + // getLocale() { // if (navigator.languages && navigator.languages.length > 0) { // return navigator.languages[0] diff --git a/src/store/UserStore.ts b/src/store/UserStore.ts index bba3e2d1..e6c9766b 100755 --- a/src/store/UserStore.ts +++ b/src/store/UserStore.ts @@ -449,12 +449,12 @@ export const useUserStore = defineStore('UserStore', { let myrec = this.getRecByCol(user, col) if (!!myrec.name) - name = myrec.name + name = myrec.name + ' ' if (!!myrec.surname) - name += ' ' + myrec.surname + name += myrec.surname + ' ' if (!name) { - name = myrec.username + name += myrec.username + ' ' } if (col && col.field === 'extrarec' && !name) { name = myrec.dest @@ -996,6 +996,8 @@ export const useUserStore = defineStore('UserStore', { await globalStore.clearDataAfterLogout() + tools.checkApp() + return Api.SendReq('/users/me/token', 'DELETE', null) .then((res) => { console.log(res) diff --git a/src/store/globalStore.ts b/src/store/globalStore.ts index a62b1bb5..483876d7 100644 --- a/src/store/globalStore.ts +++ b/src/store/globalStore.ts @@ -183,6 +183,7 @@ export const useGlobalStore = defineStore('GlobalStore', { myselector: { data: {}, table: ''}, addNewRecord: '', isAppRunning: false, + deferredPrompt: null, }), getters: { diff --git a/src/views/user/myactivities/myactivities.vue b/src/views/user/myactivities/myactivities.vue index d7dd3048..d06ac206 100755 --- a/src/views/user/myactivities/myactivities.vue +++ b/src/views/user/myactivities/myactivities.vue @@ -46,7 +46,7 @@
{{ myuser.name }} - {{ +  {{ myuser.surname }}