Browse Source

Fix minor issue.

refactor/sync-centralize
RUSHIL AMBARISH KADU 6 months ago
parent
commit
a6458d9de0
  1. 8
      steps/src/db.js
  2. 6
      steps/src/main.js

8
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

6
steps/src/main.js

@ -496,9 +496,11 @@ document.addEventListener("DOMContentLoaded", () => {
initializeDataExplorer();
initKeyboardShortcuts();
initSyncUIHandlers();
initDB(async () => {
console.log("Database initialized. Checking for cached session...");
// 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");

Loading…
Cancel
Save