From a6458d9de0a102c0ccdba0b6f8d7463b360931d3 Mon Sep 17 00:00:00 2001 From: rakadu1 Date: Mon, 1 Dec 2025 14:29:59 +0530 Subject: [PATCH] Fix minor issue. --- steps/src/db.js | 8 ++++---- steps/src/main.js | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/steps/src/db.js b/steps/src/db.js index c06ceb7..613afdb 100644 --- a/steps/src/db.js +++ b/steps/src/db.js @@ -9,8 +9,8 @@ dbReadyPromise = new Promise((resolve) => { }); // Initializes the IndexedDB database. -export function initDB(callback) { - const request = indexedDB.open("visualizerDB", 2); // Increment version to 2 +export function initDB() { + const request = indexedDB.open("visualizerDB", 2); request.onupgradeneeded = function (event) { const db = event.target.result; @@ -27,15 +27,15 @@ export function initDB(callback) { db = event.target.result; console.log("Database initialized"); dbReadyResolve(db); // Signal that DB is ready - if (callback) callback(); }; request.onerror = function (event) { console.error("IndexedDB error:", event.target.errorCode); // If DB fails, we resolve with null so operations can proceed (gracefully failing to cache) dbReadyResolve(null); - if (callback) callback(); }; + + return dbReadyPromise; } // Ensure DB is ready before returning it diff --git a/steps/src/main.js b/steps/src/main.js index 5619823..7cb2a81 100644 --- a/steps/src/main.js +++ b/steps/src/main.js @@ -496,9 +496,11 @@ document.addEventListener("DOMContentLoaded", () => { initializeDataExplorer(); initKeyboardShortcuts(); initSyncUIHandlers(); - initDB(async () => { + + // Await the database initialization before attempting to load any files. + // This resolves the race condition on initial load. + initDB().then(async () => { console.log("Database initialized. Checking for cached session..."); - // Load filenames and the last known offset from localStorage appState.jsonFilename = localStorage.getItem("jsonFilename"); appState.videoFilename = localStorage.getItem("videoFilename");