From 4a7bd6a8855482721c044c0d3e63356b87e1f538 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Sun, 14 Jan 2024 22:16:38 +0800 Subject: [PATCH] only auto sync when window is focused --- vue/src/apps/ShoppingListView/ShoppingListView.vue | 10 ++++++++++ vue/src/locales/en.json | 3 ++- vue/src/stores/ShoppingListStore.js | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/vue/src/apps/ShoppingListView/ShoppingListView.vue b/vue/src/apps/ShoppingListView/ShoppingListView.vue index 2ea04cf7..49d3a6bd 100644 --- a/vue/src/apps/ShoppingListView/ShoppingListView.vue +++ b/vue/src/apps/ShoppingListView/ShoppingListView.vue @@ -575,10 +575,20 @@ export default { useUserPreferenceStore().loadUserSettings() useUserPreferenceStore().loadDeviceSettings() this.setupAutoSync() + this.setupFocusMonitor() + }, methods: { useUserPreferenceStore, useShoppingListStore, + + setupFocusMonitor: function () { + setInterval(() => { + useShoppingListStore().autosync_has_focus = document.hasFocus() + }, 1000); + + }, + setupAutoSync: function () { // prevent setting up multiple loops on accident // TODO should this just raise an error? diff --git a/vue/src/locales/en.json b/vue/src/locales/en.json index 65265100..022e5d60 100644 --- a/vue/src/locales/en.json +++ b/vue/src/locales/en.json @@ -299,7 +299,8 @@ "Warning": "Warning", "NoCategory": "No category selected.", "InheritWarning": "{food} is set to inherit, changes may not persist.", - "ShowDelayed": "Show Delayed Items", + "ShowDelayed": "Show delayed items", + "ShowRecentlyCompleted": "Show recently completed items", "Completed": "Completed", "OfflineAlert": "You are offline, shopping list may not syncronize.", "shopping_share": "Share Shopping List", diff --git a/vue/src/stores/ShoppingListStore.js b/vue/src/stores/ShoppingListStore.js index f13076a6..b22700dd 100644 --- a/vue/src/stores/ShoppingListStore.js +++ b/vue/src/stores/ShoppingListStore.js @@ -22,6 +22,7 @@ export const useShoppingListStore = defineStore(_STORE_ID, { currently_updating: false, last_autosync: null, undo_stack: [], + autosync_has_focus: false, // constants GROUP_CATEGORY: 'food.supermarket_category.name', @@ -163,7 +164,7 @@ export const useShoppingListStore = defineStore(_STORE_ID, { } }, autosync() { - if (!this.currently_updating) { + if (!this.currently_updating && this.autosync_has_focus) { console.log('running autosync') this.currently_updating = true