updated deck caching to client for faster respones

This commit is contained in:
2026-04-21 23:48:25 -07:00
parent 5902d5f0b1
commit be94dac6f4
4 changed files with 391 additions and 0 deletions
+51
View File
@@ -33,6 +33,7 @@
timeFormatEl: document.getElementById("time-format"),
birthDateEl: document.getElementById("birth-date"),
tarotDeckEl: document.getElementById("tarot-deck"),
tarotDeckCacheStatusEl: document.getElementById("tarot-deck-cache-status"),
stellariumBackgroundEl: document.getElementById("stellarium-background"),
stellariumBackgroundHintEl: document.getElementById("stellarium-background-hint"),
apiBaseUrlEl: document.getElementById("api-base-url"),
@@ -122,6 +123,50 @@
}
}
function formatDeckCacheStatus(status) {
const activeDeckId = String(status?.activeDeckId || normalizeTarotDeck(getElements().tarotDeckEl?.value)).trim().toLowerCase();
const totalDeckCount = Number(status?.totalDeckCount) || 0;
const warmedDeckCount = Number(status?.warmedDeckCount) || 0;
const warmedAllDecks = totalDeckCount > 0 && warmedDeckCount >= totalDeckCount;
if (status?.selectedDeckPhase === "loading") {
return "Caching selected deck images to this browser...";
}
if (status?.selectedDeckPhase === "error") {
return "Selected deck cache warmup hit an error. Images will still load on demand.";
}
if (status?.backgroundPhase === "loading") {
if (warmedDeckCount > 0 && totalDeckCount > 0) {
return `Selected deck cached. Warming remaining decks in background (${warmedDeckCount}/${totalDeckCount}).`;
}
return "Selected deck cached. Warming remaining decks in background...";
}
if (status?.backgroundPhase === "error") {
return "Selected deck cached. Background warmup for other decks stopped early.";
}
if (status?.selectedDeckPhase === "ready" || warmedAllDecks) {
if (warmedAllDecks) {
return "Selected deck cached. All available decks are warmed in this browser.";
}
return `Selected deck cached and ready for fullscreen use (${activeDeckId}).`;
}
return "Deck cache idle.";
}
function syncDeckCacheStatus(status) {
const { tarotDeckCacheStatusEl } = getElements();
if (!tarotDeckCacheStatusEl) {
return;
}
tarotDeckCacheStatusEl.textContent = formatDeckCacheStatus(status);
}
function syncSky(geo, options) {
if (typeof config.onSyncSkyBackground === "function") {
config.onSyncSkyBackground(geo, options);
@@ -373,6 +418,7 @@
if (window.TarotCardImages?.setActiveDeck) {
window.TarotCardImages.setActiveDeck(normalized.tarotDeck);
}
syncDeckCacheStatus(window.TarotCardImages?.getDeckPreloadStatus?.());
applyExternalSettings(normalized);
return normalized;
}
@@ -577,6 +623,11 @@
document.addEventListener("connection:updated", () => {
syncConnectionInputs();
syncTarotDeckInputOptions();
syncDeckCacheStatus(window.TarotCardImages?.getDeckPreloadStatus?.());
});
document.addEventListener("tarot:deck-cache-status", (event) => {
syncDeckCacheStatus(event?.detail);
});
}