Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/get-readers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const watchFiles = [];

const getExt = value => {
const parts = value.split('.');
return parts[parts.length - 1];
Expand Down Expand Up @@ -114,7 +116,18 @@ const getReaders = async (handler, vcdPath) => {
});

dropZoneEl.addEventListener('click', () => {
inputEl.click();
if (window.showOpenFilePicker){
showOpenFilePicker().then(async fileHandle => {
const files = await Promise.all(fileHandle.map(async file => {
return await file.getFile();
}))
watchFiles.push({fileHandle, files});
await handleFiles({files}, handler)();
});
return;
} else {
inputEl.click();
}
}, false);


Expand Down Expand Up @@ -144,5 +157,7 @@ const getReaders = async (handler, vcdPath) => {
};

module.exports = getReaders;
module.exports.watchFiles = watchFiles;
module.exports.handleFiles = handleFiles;

/* eslint-env browser */
25 changes: 24 additions & 1 deletion lib/vcdrom.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,33 @@ global.VCDrom = async (divName, vcdPath) => {

content.innerHTML = stringify(dropZone({width: 2048, height: 2048}));
const mod = await createVCD();
const inst = await webVcdParser(mod); // VCD parser instance
let inst = await webVcdParser(mod); // VCD parser instance
const handler = getHandler(content, inst);
await getReaders(handler, vcdPath);
// console.log(content);

if (window.showOpenFilePicker == undefined) {
return;
}
setInterval(async () => {
getReaders.watchFiles.map(
async ({fileHandle, files}) => {
const newFiles = await Promise.all(fileHandle.map(async file => {
return await file.getFile();
}));
const allEq = newFiles.every((newFile, i) => {
const file = files[i];
const eq = newFile.lastModified === file.lastModified;
getReaders.watchFiles[i].files = newFiles;
return eq;
});
if (!allEq) {
inst = await webVcdParser(mod);
const handler = getHandler(content, inst);
await getReaders.handleFiles({files: newFiles}, handler)();
}
});
}, 1000);
};

/* eslint-env browser */