From e98495fb50c6daab74dbcd88dfbf934720fd503d Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Fri, 7 Jul 2023 15:45:52 +0200 Subject: [PATCH] Automatically reopen DB when closed (e.g. due to SW update) --- web/service_worker.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/web/service_worker.ts b/web/service_worker.ts index 0198418d..3e9df4df 100644 --- a/web/service_worker.ts +++ b/web/service_worker.ts @@ -118,6 +118,11 @@ async function handleLocalFileRequest( // Not initialzed yet, or explicitly in sync mode (so direct server communication requested) return fetch(request); } + + if (!db?.isOpen()) { + console.log("Detected that the DB was closed, reopening"); + await db!.open(); + } const path = decodeURIComponent(pathname.slice(1)); const data = await fileContentTable.get(path); if (data) {