diff --git a/packages/desktop-client/src/components/App.tsx b/packages/desktop-client/src/components/App.tsx index ea0762201d0..32cc2d74403 100644 --- a/packages/desktop-client/src/components/App.tsx +++ b/packages/desktop-client/src/components/App.tsx @@ -128,7 +128,7 @@ function AppWrapper() { state => state.prefs.local && state.prefs.local.cloudFileId, ); let loadingText = useSelector(state => state.app.loadingText); - let { loadBudget, closeBudget, loadGlobalPrefs } = useActions(); + let { loadBudget, closeBudget, loadGlobalPrefs, sync } = useActions(); const [hiddenScrollbars, setHiddenScrollbars] = useState( hasHiddenScrollbars(), ); @@ -140,10 +140,25 @@ function AppWrapper() { } } + let isSyncing = false; + + async function onVisibilityChange() { + if (!isSyncing) { + console.debug('triggering sync because of visibility change'); + isSyncing = true; + await sync(); + isSyncing = false; + } + } + window.addEventListener('focus', checkScrollbars); + window.addEventListener('visibilitychange', onVisibilityChange); - return () => window.removeEventListener('focus', checkScrollbars); - }, []); + return () => { + window.removeEventListener('focus', checkScrollbars); + window.removeEventListener('visibilitychange', onVisibilityChange); + }; + }, [sync]); return ( diff --git a/upcoming-release-notes/1549.md b/upcoming-release-notes/1549.md new file mode 100644 index 00000000000..863ab5b1c76 --- /dev/null +++ b/upcoming-release-notes/1549.md @@ -0,0 +1,6 @@ +--- +category: Enhancements +authors: [Cldfire] +--- + +Trigger a sync when the user returns to Actual in order to present fresh data.