single loop

This commit is contained in:
Seth Trowbridge 2024-10-11 17:13:58 -04:00
parent 904f7944b2
commit 5cdb1cbf89

View File

@ -3,6 +3,7 @@
<body>
<button id="open">open</button>
<script type="module">
// Function to walk through the directory and update file handles
async function updateFileHandles(dirHandle, extension, path = "", map) {
for await (const entry of dirHandle.values()) {
@ -47,28 +48,39 @@ async function checkModifiedDates(map, date) {
async function main() {
const dirHandle = await window.showDirectoryPicker();
const extension = '.html'; // Change this to the desired file extension
let fileHandlesMap = new Map();
let lastCheckTime = new Date().getTime();
const CoarseCheck = async () => {
console.log("===========coarse check==================");
console.log("=========== coarse check ==================");
fileHandlesMap = new Map();
await updateFileHandles(dirHandle, extension, "", fileHandlesMap);
setTimeout(CoarseCheck, 10000);
};
const FineCheck =async()=>{
console.log("---- fine check ----")
const focusFiles = await checkModifiedDates(fileHandlesMap, new Date(lastCheckTime));
if (focusFiles.length) {
console.log("Updated files:", focusFiles);
// Open the updated files or handle them as needed
}
lastCheckTime = new Date().getTime();
setTimeout(FineCheck, 1000);
}
CoarseCheck();
FineCheck();
let count = 0;
const Loop =async()=>
{
if (count === 0) {
await CoarseCheck();
}
await FineCheck();
count += 1;
count %= 10;
setTimeout(Loop, 1000);
}
Loop();
}
document.getElementById("open").addEventListener("click", main);