improved document visibility handling

This commit is contained in:
vabene1111
2024-01-19 20:09:46 +08:00
parent 05cf7cc081
commit 57100baf7c
2 changed files with 3 additions and 13 deletions

View File

@ -570,28 +570,18 @@ export default {
window.addEventListener("online", this.updateOnlineStatus) window.addEventListener("online", this.updateOnlineStatus)
window.addEventListener("offline", this.updateOnlineStatus) window.addEventListener("offline", this.updateOnlineStatus)
addEventListener("visibilitychange", (event) => {useShoppingListStore().autosync_has_focus = (document.visibilityState === 'visible')});
this.$i18n.locale = window.CUSTOM_LOCALE this.$i18n.locale = window.CUSTOM_LOCALE
this.shopping_list_store.refreshFromAPI() this.shopping_list_store.refreshFromAPI()
useUserPreferenceStore().loadUserSettings() useUserPreferenceStore().loadUserSettings()
useUserPreferenceStore().loadDeviceSettings() useUserPreferenceStore().loadDeviceSettings()
this.autoSyncLoop() this.autoSyncLoop()
this.setupFocusMonitor()
}, },
methods: { methods: {
useUserPreferenceStore, useUserPreferenceStore,
useShoppingListStore, 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 * recursive function calling autosync after set amount of time has passed
*/ */

View File

@ -26,8 +26,8 @@ export const useShoppingListStore = defineStore(_STORE_ID, {
// internal // internal
currently_updating: false, currently_updating: false,
last_autosync: null, last_autosync: null,
autosync_has_focus: true,
undo_stack: [], undo_stack: [],
autosync_has_focus: false,
// constants // constants
GROUP_CATEGORY: 'food.supermarket_category.name', GROUP_CATEGORY: 'food.supermarket_category.name',