From 0bfb8dd9eded7946d04c1983d2a1f92f6644148e Mon Sep 17 00:00:00 2001 From: HighImKevin Date: Thu, 13 Nov 2025 05:51:44 -0500 Subject: [PATCH] Improve handling for when user is logged out --- itemDetailsCollections.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/itemDetailsCollections.js b/itemDetailsCollections.js index 82d27e3..b721886 100644 --- a/itemDetailsCollections.js +++ b/itemDetailsCollections.js @@ -18,8 +18,6 @@ async function populateCollectionsCache() { // Check if user is logged in and poll for 5 seconds if not if (ApiClient._loggedIn === false) { - WARN('User not logged in, retrying in ' + POLL_INTERVAL + ' milliseconds'); - setTimeout(populateCollectionsCache, POLL_INTERVAL); return; } @@ -195,6 +193,12 @@ window.KefinTweaksUtils.onViewPage( async (view, element, hash, itemPromise) => { + if (ApiClient._loggedIn === false) { + return; + } + + await populateCollectionsCache(); + // Only handle details pages const activePage = document.querySelector('.libraryPage:not(.hide)'); if (!activePage) return; @@ -217,17 +221,22 @@ LOG('Collections hook initialized'); } + const maxInitAttempts = 10; + let initAttempts = 0; + // Initialize cache population on script load function initialize() { - if (!window.IndexedDBCache || !window.ApiClient || !window.ApiClient.getCurrentUserId) { + if (!window.ApiClient) { WARN('Dependencies not available, retrying in 1 second'); - setTimeout(initialize, 1000); + if (initAttempts < maxInitAttempts) { + setTimeout(initialize, 1000); + initAttempts++; + } else { + ERR('Dependencies not available after 10 seconds, giving up'); + } return; } - LOG('Initializing collections cache...'); - populateCollectionsCache(); - // Initialize collections hook initializeCollectionsHook(); }