mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-30 14:18:11 +08:00
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:
co-authored by
Keavon Chambers
parent
fed1ccff88
commit
342d4b5f02
@@ -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,29 +69,30 @@ export async function createPersistenceManager(editor: Editor, portfolio: Portfo
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// Open auto-save documents
|
databaseConnection.then(async (db) => {
|
||||||
const db = await databaseConnection;
|
// Open auto-save documents
|
||||||
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 => {
|
||||||
request.onsuccess = (): void => {
|
request.onsuccess = (): void => {
|
||||||
const previouslySavedDocuments: TriggerIndexedDbWriteDocument[] = request.result;
|
const previouslySavedDocuments: TriggerIndexedDbWriteDocument[] = request.result;
|
||||||
|
|
||||||
const documentOrder: string[] = JSON.parse(window.localStorage.getItem(GRAPHITE_AUTO_SAVE_ORDER_KEY) || "[]");
|
const documentOrder: string[] = JSON.parse(window.localStorage.getItem(GRAPHITE_AUTO_SAVE_ORDER_KEY) || "[]");
|
||||||
const orderedSavedDocuments = documentOrder
|
const orderedSavedDocuments = documentOrder
|
||||||
.map((id) => previouslySavedDocuments.find((autoSave) => autoSave.details.id === id))
|
.map((id) => previouslySavedDocuments.find((autoSave) => autoSave.details.id === id))
|
||||||
.filter((x) => x !== undefined) as TriggerIndexedDbWriteDocument[];
|
.filter((x) => x !== undefined) as TriggerIndexedDbWriteDocument[];
|
||||||
|
|
||||||
const currentDocumentVersion = editor.instance.graphite_document_version();
|
const currentDocumentVersion = editor.instance.graphite_document_version();
|
||||||
orderedSavedDocuments.forEach((doc: TriggerIndexedDbWriteDocument) => {
|
orderedSavedDocuments.forEach((doc: TriggerIndexedDbWriteDocument) => {
|
||||||
if (doc.version === currentDocumentVersion) {
|
if (doc.version === currentDocumentVersion) {
|
||||||
editor.instance.open_auto_saved_document(BigInt(doc.details.id), doc.details.name, doc.details.is_saved, doc.document);
|
editor.instance.open_auto_saved_document(BigInt(doc.details.id), doc.details.name, doc.details.is_saved, doc.document);
|
||||||
} else {
|
} else {
|
||||||
removeDocument(doc.details.id);
|
removeDocument(doc.details.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
resolve(undefined);
|
resolve(undefined);
|
||||||
};
|
};
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return closeDatabaseConnection;
|
return closeDatabaseConnection;
|
||||||
|
|||||||
Reference in New Issue
Block a user