diff --git a/kjvstudy_org/static/sw.js b/kjvstudy_org/static/sw.js
index 02450f2..76d3b88 100644
--- a/kjvstudy_org/static/sw.js
+++ b/kjvstudy_org/static/sw.js
@@ -314,4 +314,21 @@ self.addEventListener('message', (event) => {
console.log('[SW] Received START_CACHING request');
startBackgroundCaching();
}
+
+ // Report current caching status
+ if (event.data && event.data.type === 'GET_CACHE_STATUS') {
+ if (cachingInProgress) {
+ event.source.postMessage({
+ type: 'CACHE_PROGRESS',
+ cached: cachedCount,
+ total: totalToCache,
+ inProgress: true
+ });
+ } else {
+ event.source.postMessage({
+ type: 'CACHE_IDLE',
+ inProgress: false
+ });
+ }
+ }
});
diff --git a/kjvstudy_org/templates/offline.html b/kjvstudy_org/templates/offline.html
index c5b6548..525bf20 100644
--- a/kjvstudy_org/templates/offline.html
+++ b/kjvstudy_org/templates/offline.html
@@ -498,23 +498,39 @@
navigator.serviceWorker.addEventListener('message', function(event) {
const data = event.data;
if (data.type === 'CACHE_STATUS') {
+ cacheProgress.classList.add('active');
progressText.textContent = data.status;
} else if (data.type === 'CACHE_PROGRESS') {
+ // Show progress bar if caching is in progress
+ cacheProgress.classList.add('active');
+ startCacheBtn.disabled = true;
+ startCacheBtn.textContent = 'Downloading...';
+
const pct = Math.round((data.cached / data.total) * 100);
progressFill.style.width = pct + '%';
progressText.textContent = 'Downloading: ' + data.cached.toLocaleString() + ' / ' + data.total.toLocaleString() + ' pages (' + pct + '%)';
} else if (data.type === 'CACHE_COMPLETE') {
+ cacheProgress.classList.add('active');
progressFill.style.width = '100%';
progressText.innerHTML = '✓ Download complete! ' + data.total.toLocaleString() + ' pages available offline.';
startCacheBtn.textContent = 'Downloaded!';
+ startCacheBtn.disabled = true;
// Refresh the cache list
setTimeout(checkCaches, 500);
} else if (data.type === 'CACHE_ERROR') {
+ cacheProgress.classList.add('active');
progressText.innerHTML = 'Error: ' + data.error + '';
startCacheBtn.disabled = false;
startCacheBtn.textContent = 'Try Again';
}
});
+
+ // Check if caching is already in progress when page loads
+ navigator.serviceWorker.ready.then(function(registration) {
+ if (registration.active) {
+ registration.active.postMessage({ type: 'GET_CACHE_STATUS' });
+ }
+ });
}
// Bible Reader functionality