diff --git a/steps/package-lock.json b/steps/package-lock.json new file mode 100644 index 0000000..4a36c79 --- /dev/null +++ b/steps/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "steps", + "lockfileVersion": 3, + "requires": true, + "packages": {} +} diff --git a/steps/src/db.js b/steps/src/db.js index a9dda75..53792e8 100644 --- a/steps/src/db.js +++ b/steps/src/db.js @@ -1,6 +1,7 @@ let db; let dbReadyPromise; let dbReadyResolve; +import { showModal } from "./modal.js"; // Initialize the promise that tracks DB readiness dbReadyPromise = new Promise((resolve) => { @@ -72,7 +73,7 @@ export function saveFileWithMetadata(key, file) { // Gracefully handle errors, especially quota limits transaction.onerror = (event) => { if (event.target.error.name === 'QuotaExceededError') { - alert("Could not cache file: Browser storage quota exceeded. The app will still work for this session."); + showModal("Could not cache file: Browser storage quota exceeded. The app will still work for this session, but files won't be saved for next time."); resolve(); // Resolve anyway to let the app continue without caching } else { console.error(`Error saving file '${key}':`, event.target.error); diff --git a/steps/src/fileLoader.js b/steps/src/fileLoader.js index cb20a23..6ec6db5 100644 --- a/steps/src/fileLoader.js +++ b/steps/src/fileLoader.js @@ -1,4 +1,5 @@ import { appState } from "./state.js"; +import { debugFlags } from "./debug.js"; import { saveFileWithMetadata } from "./db.js"; import { parseVisualizationJson } from "./fileParsers.js"; import { @@ -60,17 +61,33 @@ async function processFilePipeline(jsonFile, videoFile, fromCache) { // 1. Show the unified loading modal. showLoadingModal("Processing files..."); + const cachePromises = []; + // --- PART A: Setup Filenames & Cache (Moved Up) --- if (jsonFile) { appState.jsonFilename = jsonFile.name; localStorage.setItem("jsonFilename", appState.jsonFilename); - if (!fromCache) await saveFileWithMetadata("json", jsonFile); + if (!fromCache) { + const savePromise = saveFileWithMetadata("json", jsonFile).catch((e) => + console.warn(`Non-blocking cache save failed for JSON:`, e) + ); + if (debugFlags.CACHE_BLOCKING) { + await savePromise; + } else { + cachePromises.push(savePromise); + } + } } if (videoFile) { appState.videoFilename = videoFile.name; localStorage.setItem("videoFilename", appState.videoFilename); - if (!fromCache) await saveFileWithMetadata("video", videoFile); + if (!fromCache) { + const savePromise = saveFileWithMetadata("video", videoFile).catch((e) => + console.warn(`Non-blocking cache save failed for Video:`, e) + ); + cachePromises.push(savePromise); + } } // --- PART B: Calculate Offset (Moved Up) --- @@ -137,6 +154,13 @@ async function processFilePipeline(jsonFile, videoFile, fromCache) { // Hide modal updateLoadingModal(100, "Complete!"); setTimeout(hideModal, 300); + + // Log the results of the non-blocking cache operations once they complete. + if (cachePromises.length > 0) { + Promise.allSettled(cachePromises).then((results) => { + console.log("Non-blocking cache operations finished:", results); + }); + } }