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().loadUserSettings()
useUserPreferenceStore().loadDeviceSettings() useUserPreferenceStore().loadDeviceSettings()
this.setupAutoSync() this.setupAutoSync()
this.setupFocusMonitor()
}, },
methods: { methods: {
useUserPreferenceStore, useUserPreferenceStore,
useShoppingListStore, useShoppingListStore,
setupFocusMonitor: function () {
setInterval(() => {
useShoppingListStore().autosync_has_focus = document.hasFocus()
}, 1000);
},
setupAutoSync: function () { setupAutoSync: function () {
// prevent setting up multiple loops on accident // prevent setting up multiple loops on accident
// TODO should this just raise an error? // TODO should this just raise an error?

View File

@ -299,7 +299,8 @@
"Warning": "Warning", "Warning": "Warning",
"NoCategory": "No category selected.", "NoCategory": "No category selected.",
"InheritWarning": "{food} is set to inherit, changes may not persist.", "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", "Completed": "Completed",
"OfflineAlert": "You are offline, shopping list may not syncronize.", "OfflineAlert": "You are offline, shopping list may not syncronize.",
"shopping_share": "Share Shopping List", "shopping_share": "Share Shopping List",

View File

@ -22,6 +22,7 @@ export const useShoppingListStore = defineStore(_STORE_ID, {
currently_updating: false, currently_updating: false,
last_autosync: null, last_autosync: null,
undo_stack: [], undo_stack: [],
autosync_has_focus: false,
// constants // constants
GROUP_CATEGORY: 'food.supermarket_category.name', GROUP_CATEGORY: 'food.supermarket_category.name',
@ -163,7 +164,7 @@ export const useShoppingListStore = defineStore(_STORE_ID, {
} }
}, },
autosync() { autosync() {
if (!this.currently_updating) { if (!this.currently_updating && this.autosync_has_focus) {
console.log('running autosync') console.log('running autosync')
this.currently_updating = true this.currently_updating = true