diff --git a/app.js b/app.js index 79185b5..df31068 100644 --- a/app.js +++ b/app.js @@ -23,12 +23,11 @@ const H =(type, attributes={}, ...children)=> { const button = H("button"); const listRoom = H("ul"); -async function getFolderHandle(dirHandle) +/** @type {(handle:boolean)=>Promise} */ +async function ReloadAndRedraw(handle) { - try + if(handle) { - const workingFolder = await dirHandle.getDirectoryHandle("room"); - const module = await import("./data/room.js"); const rooms = module.default(); button.innerText = "change directory"; @@ -50,27 +49,24 @@ async function getFolderHandle(dirHandle) ) ); }) - - return true; } - catch (err) + else { button.innerText = "select directory"; - console.error("Folder selection cancelled or failed:", err); - return false; } } let handle = false; - handle = await FSHandle.getDirectoryHandle(); -await getFolderHandle(handle); +await ReloadAndRedraw(handle); + button.addEventListener("click", async()=> { const directory = await globalThis.showDirectoryPicker(); await FSHandle.setDirectoryHandle(directory); - await getFolderHandle(directory); + handle = await FSHandle.getDirectoryHandle(); + await ReloadAndRedraw(handle); }); document.body.appendChild(button); diff --git a/service-worker.js b/service-worker.js index 6b1c891..3ee73c7 100644 --- a/service-worker.js +++ b/service-worker.js @@ -8,43 +8,47 @@ let handle = false; async function Interceptor(event) { const url = new URL(event.request.url); - const pathname = url.pathname.substring(1) - const extension = pathname.substring(pathname.lastIndexOf('.') + 1); + const pathname = url.pathname.substring(1); + const parts = pathname.split("/"); - // Intercept only JavaScript files - if ( extension == "js" || extension == "json" ) + if(parts[0] == "data" || parts[0] == "room") { - console.log('[Service Worker] Intercepted JS request:', url.href); - if(!handle) + const extension = pathname.substring(pathname.lastIndexOf('.') + 1); + // Intercept only JavaScript files + if ( extension == "js" || extension == "json" ) { - handle = await FSAccess.getDirectoryHandle(); - } - if(handle) - { - try + if(!handle) { - const parts = pathname.split("/"); - let filePointer = handle; - for(let i=0; i