From 57100baf7cc33bbe0cda54c2be4f93aee2a93b8a Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Fri, 19 Jan 2024 20:09:46 +0800 Subject: [PATCH] improved document visibility handling --- vue/src/apps/ShoppingListView/ShoppingListView.vue | 14 ++------------ vue/src/stores/ShoppingListStore.js | 2 +- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/vue/src/apps/ShoppingListView/ShoppingListView.vue b/vue/src/apps/ShoppingListView/ShoppingListView.vue index 8d31b8e2..34debb2c 100644 --- a/vue/src/apps/ShoppingListView/ShoppingListView.vue +++ b/vue/src/apps/ShoppingListView/ShoppingListView.vue @@ -570,28 +570,18 @@ export default { window.addEventListener("online", this.updateOnlineStatus) window.addEventListener("offline", this.updateOnlineStatus) + addEventListener("visibilitychange", (event) => {useShoppingListStore().autosync_has_focus = (document.visibilityState === 'visible')}); + this.$i18n.locale = window.CUSTOM_LOCALE this.shopping_list_store.refreshFromAPI() useUserPreferenceStore().loadUserSettings() useUserPreferenceStore().loadDeviceSettings() this.autoSyncLoop() - this.setupFocusMonitor() - }, methods: { useUserPreferenceStore, useShoppingListStore, - - /** - * setup interval checking for focus every 1000ms and updating the store variable - */ - setupFocusMonitor: function () { - setInterval(() => { - useShoppingListStore().autosync_has_focus = document.hasFocus() - }, 1000); - - }, /** * recursive function calling autosync after set amount of time has passed */ diff --git a/vue/src/stores/ShoppingListStore.js b/vue/src/stores/ShoppingListStore.js index d4e3d8e3..42631ce7 100644 --- a/vue/src/stores/ShoppingListStore.js +++ b/vue/src/stores/ShoppingListStore.js @@ -26,8 +26,8 @@ export const useShoppingListStore = defineStore(_STORE_ID, { // internal currently_updating: false, last_autosync: null, + autosync_has_focus: true, undo_stack: [], - autosync_has_focus: false, // constants GROUP_CATEGORY: 'food.supermarket_category.name',