single loop
This commit is contained in:
parent
904f7944b2
commit
5cdb1cbf89
@ -3,6 +3,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<button id="open">open</button>
|
<button id="open">open</button>
|
||||||
<script type="module">
|
<script type="module">
|
||||||
|
|
||||||
// Function to walk through the directory and update file handles
|
// Function to walk through the directory and update file handles
|
||||||
async function updateFileHandles(dirHandle, extension, path = "", map) {
|
async function updateFileHandles(dirHandle, extension, path = "", map) {
|
||||||
for await (const entry of dirHandle.values()) {
|
for await (const entry of dirHandle.values()) {
|
||||||
@ -47,6 +48,7 @@ async function checkModifiedDates(map, date) {
|
|||||||
async function main() {
|
async function main() {
|
||||||
const dirHandle = await window.showDirectoryPicker();
|
const dirHandle = await window.showDirectoryPicker();
|
||||||
const extension = '.html'; // Change this to the desired file extension
|
const extension = '.html'; // Change this to the desired file extension
|
||||||
|
|
||||||
let fileHandlesMap = new Map();
|
let fileHandlesMap = new Map();
|
||||||
let lastCheckTime = new Date().getTime();
|
let lastCheckTime = new Date().getTime();
|
||||||
|
|
||||||
@ -54,21 +56,31 @@ async function main() {
|
|||||||
console.log("=========== coarse check ==================");
|
console.log("=========== coarse check ==================");
|
||||||
fileHandlesMap = new Map();
|
fileHandlesMap = new Map();
|
||||||
await updateFileHandles(dirHandle, extension, "", fileHandlesMap);
|
await updateFileHandles(dirHandle, extension, "", fileHandlesMap);
|
||||||
setTimeout(CoarseCheck, 10000);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const FineCheck =async()=>{
|
const FineCheck =async()=>{
|
||||||
|
console.log("---- fine check ----")
|
||||||
const focusFiles = await checkModifiedDates(fileHandlesMap, new Date(lastCheckTime));
|
const focusFiles = await checkModifiedDates(fileHandlesMap, new Date(lastCheckTime));
|
||||||
if (focusFiles.length) {
|
if (focusFiles.length) {
|
||||||
console.log("Updated files:", focusFiles);
|
console.log("Updated files:", focusFiles);
|
||||||
// Open the updated files or handle them as needed
|
// Open the updated files or handle them as needed
|
||||||
}
|
}
|
||||||
lastCheckTime = new Date().getTime();
|
lastCheckTime = new Date().getTime();
|
||||||
setTimeout(FineCheck, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CoarseCheck();
|
let count = 0;
|
||||||
FineCheck();
|
const Loop =async()=>
|
||||||
|
{
|
||||||
|
if (count === 0) {
|
||||||
|
await CoarseCheck();
|
||||||
|
}
|
||||||
|
await FineCheck();
|
||||||
|
count += 1;
|
||||||
|
count %= 10;
|
||||||
|
setTimeout(Loop, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
Loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("open").addEventListener("click", main);
|
document.getElementById("open").addEventListener("click", main);
|
||||||
|
Loading…
Reference in New Issue
Block a user