From 1d8e7d5c35bf1fe0e6666b1c8590bfb5bad7583d Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Mon, 30 Oct 2023 12:09:45 +0100 Subject: [PATCH] Fix client reset --- web/syscalls/debug.ts | 57 +++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/web/syscalls/debug.ts b/web/syscalls/debug.ts index bf41618..353bf4c 100644 --- a/web/syscalls/debug.ts +++ b/web/syscalls/debug.ts @@ -3,49 +3,42 @@ import type { SysCallMapping } from "../../plugos/system.ts"; export function debugSyscalls(): SysCallMapping { return { "debug.resetClient": async () => { - if (indexedDB.databases) { - // get a list of all existing IndexedDB databases - const databases = await indexedDB.databases(); - // loop through the list and delete each database - await Promise.all( - databases.map(async (database) => { - console.log("Now deleting", database.name); - await new Promise((resolve) => { - return indexedDB.deleteDatabase(database.name!).onsuccess = - resolve; - }); - }), - ); - } else { - alert("Cannot flush local databases (Firefox user?)"); - } - if (navigator.serviceWorker) { const registration = await navigator.serviceWorker.ready; if (registration?.active) { registration.active.postMessage({ type: "flushCache" }); + await new Promise((resolve) => { + navigator.serviceWorker.addEventListener("message", (event) => { + if (event.data.type === "cacheFlushed") { + console.log("Cache flushed"); + navigator.serviceWorker.getRegistrations().then( + async (registrations) => { + for (const registration of registrations) { + await registration.unregister(); + } + resolve(); + }, + ); + } + }); + }); } else { alert("No service worker active, so not unregistering"); } - await new Promise((resolve) => { - navigator.serviceWorker.addEventListener("message", (event) => { - if (event.data.type === "cacheFlushed") { - console.log("Cache flushed"); - navigator.serviceWorker.getRegistrations().then( - async (registrations) => { - for (const registration of registrations) { - await registration.unregister(); - } - resolve(); - }, - ); - } - }); - }); } else { alert("Service workers not supported, so not unregistering"); } + if (indexedDB.databases) { + // get a list of all existing IndexedDB databases + const databases = await indexedDB.databases(); + // loop through the list and delete each database + for (const database of databases) { + indexedDB.deleteDatabase(database.name!); + } + } else { + alert("Cannot flush local databases (Firefox user?)"); + } // And finally, reload the page alert("Reset complete, now reloading the page...");