Refresh bookmark relative times in background

This commit is contained in:
2026-03-03 15:35:33 +01:00
parent 438c0ce77c
commit d82892125a

View File

@@ -384,6 +384,7 @@ const BOOKMARK_WINDOW_DAYS = 28;
const BOOKMARK_SUFFIXES = ['Gewinnspiel', 'gewinnen', 'verlosen'];
const DEFAULT_BOOKMARK_LABEL = 'Gewinnspiel / gewinnen / verlosen';
const BOOKMARK_PREFS_KEY = 'trackerBookmarkPreferences';
const BOOKMARK_RELATIVE_TIME_REFRESH_MS = 60000;
const INCLUDE_EXPIRED_STORAGE_KEY = 'trackerIncludeExpired';
const POSTS_SEARCH_STORAGE_KEY = 'trackerPostsSearchTerm';
const PENDING_BULK_COUNT_STORAGE_KEY = 'trackerPendingBulkCount';
@@ -750,6 +751,8 @@ let manualPostModalPreviousOverflow = '';
let activeDeadlinePicker = null;
let bookmarkPanelVisible = false;
let bookmarkOutsideHandler = null;
let bookmarkRelativeTimeTimer = null;
let bookmarkRelativeTimeListenersBound = false;
let bookmarkSearchTerm = '';
let bookmarkSortMode = 'recent';
let bookmarkSortDirection = 'desc';
@@ -1292,6 +1295,64 @@ async function refreshBookmarks(options = {}) {
return bookmarkFetchPromise;
}
function isBookmarksUiVisible() {
if (bookmarkPanelVisible) {
return true;
}
const bookmarksView = document.querySelector('[data-view="bookmarks"]');
return Boolean(bookmarksView && bookmarksView.classList.contains('app-view--active'));
}
function refreshBookmarkRelativeTimes() {
if (!bookmarksList || !bookmarkState.loaded) {
return;
}
if (!isBookmarksUiVisible()) {
return;
}
renderBookmarks();
}
function startBookmarkRelativeTimeRefresh() {
if (bookmarkRelativeTimeTimer) {
return;
}
bookmarkRelativeTimeTimer = setInterval(() => {
if (document.visibilityState !== 'visible') {
return;
}
refreshBookmarkRelativeTimes();
}, BOOKMARK_RELATIVE_TIME_REFRESH_MS);
}
function bindBookmarkRelativeTimeRefreshListeners() {
if (bookmarkRelativeTimeListenersBound) {
return;
}
bookmarkRelativeTimeListenersBound = true;
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible') {
refreshBookmarkRelativeTimes();
}
});
window.addEventListener('focus', () => {
refreshBookmarkRelativeTimes();
});
window.addEventListener('pageshow', () => {
refreshBookmarkRelativeTimes();
});
window.addEventListener('app:view-change', (event) => {
const view = event && event.detail ? event.detail.view : null;
if (view === 'bookmarks') {
refreshBookmarkRelativeTimes();
}
});
}
function formatFacebookDateParts(date) {
const year = date.getFullYear();
const month = date.getMonth() + 1;
@@ -1947,6 +2008,8 @@ function initializeBookmarks() {
return;
}
startBookmarkRelativeTimeRefresh();
bindBookmarkRelativeTimeRefreshListeners();
refreshBookmarks().catch(() => {});
if (bookmarkPanel) {