Fix IndexedDb in Firefox private browsing mode (#721)

* Fix db in firefox private

* Polished wording

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
0HyperCube
2022-07-09 15:23:49 -07:00
committed by GitHub
co-authored by Keavon Chambers
parent fed1ccff88
commit 342d4b5f02
+11 -3
View File
@@ -1,4 +1,5 @@
import { PortfolioState } from "@/state-providers/portfolio"; import { PortfolioState } from "@/state-providers/portfolio";
import { stripIndents } from "@/utility-functions/strip-indents";
import { Editor } from "@/wasm-communication/editor"; import { Editor } from "@/wasm-communication/editor";
import { TriggerIndexedDbWriteDocument, TriggerIndexedDbRemoveDocument } from "@/wasm-communication/messages"; import { TriggerIndexedDbWriteDocument, TriggerIndexedDbRemoveDocument } from "@/wasm-communication/messages";
@@ -53,8 +54,14 @@ export async function createPersistenceManager(editor: Editor, portfolio: Portfo
}; };
dbOpenRequest.onerror = (): void => { dbOpenRequest.onerror = (): void => {
// eslint-disable-next-line no-console const errorText = stripIndents`
console.error("Graphite IndexedDb error:", dbOpenRequest.error); Documents won't be saved across reloads and later visits.
This may be caused by Firefox's private browsing mode.
Error on opening IndexDB:
${dbOpenRequest.error}
`;
editor.instance.error_dialog("Document auto-save doesn't work in this browser", errorText);
}; };
dbOpenRequest.onsuccess = (): void => { dbOpenRequest.onsuccess = (): void => {
@@ -62,8 +69,8 @@ export async function createPersistenceManager(editor: Editor, portfolio: Portfo
}; };
}); });
databaseConnection.then(async (db) => {
// Open auto-save documents // Open auto-save documents
const db = await databaseConnection;
const transaction = db.transaction(GRAPHITE_AUTO_SAVE_STORE, "readonly"); const transaction = db.transaction(GRAPHITE_AUTO_SAVE_STORE, "readonly");
const request = transaction.objectStore(GRAPHITE_AUTO_SAVE_STORE).getAll(); const request = transaction.objectStore(GRAPHITE_AUTO_SAVE_STORE).getAll();
await new Promise((resolve): void => { await new Promise((resolve): void => {
@@ -86,6 +93,7 @@ export async function createPersistenceManager(editor: Editor, portfolio: Portfo
resolve(undefined); resolve(undefined);
}; };
}); });
});
return closeDatabaseConnection; return closeDatabaseConnection;
} }