Skip to content

Commit

Permalink
Sync on visibility change (actualbudget#1549)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cldfire authored Aug 23, 2023
1 parent 3e4133f commit 3e27b66
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
21 changes: 18 additions & 3 deletions packages/desktop-client/src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
Expand All @@ -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 (
<ResponsiveProvider>
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/1549.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [Cldfire]
---

Trigger a sync when the user returns to Actual in order to present fresh data.

0 comments on commit 3e27b66

Please sign in to comment.