work-graph-simple/app.js
2025-07-26 21:35:31 -04:00

38 lines
1.0 KiB
JavaScript

import * as FSHandle from "./store-directory-handle.js";
async function getFolderHandle(dirHandle) {
try {
globalThis.FOLDER = await dirHandle.getDirectoryHandle("room");
return true;
} catch (err) {
console.error("Folder selection cancelled or failed:", err);
return false;
}
}
const d =(...args)=> document.createElement(...args);
let handle = false;
let valid = false;
handle = await FSHandle.getDirectoryHandle();
console.log("handle:", handle);
if(handle)
{
valid = await getFolderHandle(handle);
}
const button = d("button");
button.innerText = valid ? "change directory" : "select directory";
button.addEventListener("click", async()=>{
const directory = await globalThis.showDirectoryPicker();
await FSHandle.setDirectoryHandle(directory);
await getFolderHandle(directory);
console.log("about to spoof user filesystem as remote...");
const module = await import("./data/room.js");
console.log("module loaded", module);
button.innerText = "change directory"
});
document.body.appendChild(button);