fix: extension fs.watch accepts all event types + debounce (Windows compatibility)

This commit is contained in:
2026-03-07 14:00:08 +09:00
parent f0184ec9bd
commit 2a4ef8d0d9
3 changed files with 65 additions and 10 deletions

View File

@@ -75,9 +75,12 @@ function startBridge() {
// Watch bridge/response/ for Discord user responses
const responsePath = path.join(bridgePath, 'response');
const processedFiles = new Set<string>(); // Debounce: prevent double-processing
try {
watcher = fs.watch(responsePath, { persistent: false }, (eventType, filename) => {
if (eventType === 'rename' && filename && filename.endsWith('.json')) {
if (filename && filename.endsWith('.json') && !processedFiles.has(filename)) {
processedFiles.add(filename);
setTimeout(() => processedFiles.delete(filename), 2000);
handleResponse(path.join(responsePath, filename));
}
});
@@ -90,7 +93,9 @@ function startBridge() {
const commandsPath = path.join(bridgePath, 'commands');
try {
fs.watch(commandsPath, { persistent: false }, (eventType, filename) => {
if (eventType === 'rename' && filename && filename.endsWith('.json')) {
if (filename && filename.endsWith('.json') && !processedFiles.has(filename)) {
processedFiles.add(filename);
setTimeout(() => processedFiles.delete(filename), 2000);
handleCommand(path.join(commandsPath, filename));
}
});