diff --git a/components/LayoutCommon.vue b/components/LayoutCommon.vue index b4a493b2..990ccafa 100644 --- a/components/LayoutCommon.vue +++ b/components/LayoutCommon.vue @@ -154,14 +154,11 @@ export default { }, monitorTabVisibility() { if (process.client) { - // console.log('---monitorTabVisibility') document.addEventListener('visibilitychange', () => { - console.log('---visibilitychange') const miscStore = useMiscStore() miscStore.visible = !document.hidden if (this.me && !document.hidden) { - // console.log('---visibilitychange CHANGED') // We have become visible. Refetch our notification count and chat count, which are the two key things which // produce red badges people should click on. const notificationStore = useNotificationStore() diff --git a/stores/mobile.js b/stores/mobile.js index 254b0300..6fc946ab 100644 --- a/stores/mobile.js +++ b/stores/mobile.js @@ -27,6 +27,8 @@ import { FirebaseMessaging } from '@capacitor-firebase/messaging'; import { ZoomPlugin } from 'capacitor-zoom-android'; import { App } from '@capacitor/app'; import { useRouter } from '#imports' +import { useChatStore } from '~/stores/chat' +import { useNotificationStore } from '~/stores/notification' export const useMobileStore = defineStore({ // Do not persist id: 'mobile', @@ -67,6 +69,7 @@ export const useMobileStore = defineStore({ // Do not persist await this.initDeepLinks() await this.initPushNotifications() await this.checkForAppUpdate() + await this.initWakeUpActions() //await this.initFirebaseMessaging() /*if (!this.isiOS) { try { @@ -215,6 +218,26 @@ export const useMobileStore = defineStore({ // Do not persist return urlParams }, + ////////////// + // https://capacitorjs.com/docs/apis/app#addlistenerresume + async initWakeUpActions() { + if (process.client) { + App.addListener('resume', async event => { + // We have become visible. Refetch our notification count and chat count, which are the two key things which + // produce red badges people should click on. + try { + const notificationStore = useNotificationStore() + notificationStore.fetchCount() + + const chatStore = useChatStore() + + // Don't log as we might have been logged out since we were last active. + chatStore.fetchChats(null, false) + } catch (e){} + }) + } + }, + ////////////// // Needs: https://www.ilovefreegle.org/.well-known/assetlinks.json async initDeepLinks() {