Skip to content

Commit

Permalink
Debounce page visibility to prevent streaming/polling noise
Browse files Browse the repository at this point in the history
  • Loading branch information
cheeaun committed Aug 27, 2024
1 parent ef0d9cd commit 6930ce9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/components/background-service.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@ export default memo(function BackgroundService({ isLoggedIn }) {
// Notifications service
// - WebSocket to receive notifications when page is visible
const [visible, setVisible] = useState(true);
usePageVisibility(setVisible);
const visibleTimeout = useRef();
usePageVisibility((visible) => {
clearTimeout(visibleTimeout.current);
if (visible) {
setVisible(true);
} else {
visibleTimeout.current = setTimeout(() => {
setVisible(false);
}, POLL_INTERVAL);
}
});

const checkLatestNotification = async (masto, instance, skipCheckMarkers) => {
if (states.notificationsLast) {
const notificationsIterator = masto.v1.notifications.list({
Expand Down
4 changes: 2 additions & 2 deletions src/locales/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -511,11 +511,11 @@ msgstr ""
msgid "server domain name"
msgstr ""

#: src/components/background-service.jsx:138
#: src/components/background-service.jsx:149
msgid "Cloak mode disabled"
msgstr ""

#: src/components/background-service.jsx:138
#: src/components/background-service.jsx:149
msgid "Cloak mode enabled"
msgstr ""

Expand Down

0 comments on commit 6930ce9

Please sign in to comment.