only auto sync when window is focused

This commit is contained in:
vabene1111 2024-01-14 22:16:38 +08:00
parent d1865b57f1
commit 4a7bd6a885
3 changed files with 14 additions and 2 deletions

View File

@ -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?

View File

@ -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",

View File

@ -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