Skip to content

Commit b3d0e30

Browse files
committed
Manually debounce force reload event
Remove chokidar built-in event debouncing/aggregating and replace it with a basic custom implementation with a 250ms settle delay.
1 parent 94b7c75 commit b3d0e30

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

electron/src/mods/loader.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class ModLoader extends EventEmitter {
6363
this.locators.set("dev", devLocator);
6464

6565
// If requested, restart automatically when dev mods are modified
66-
devLocator.fsWatcher?.on("all", () => this.forceReload());
66+
devLocator.fsWatcher?.on("all", this.delayedForceReload());
6767
}
6868

6969
/**
@@ -115,6 +115,16 @@ export class ModLoader extends EventEmitter {
115115
return this.mods.find(mod => mod.metadata.id === id);
116116
}
117117

118+
private delayedForceReload() {
119+
// Debounce the force reload manually as chokidar won't aggregate events the way we want
120+
// NOTE: The delay chosen here (250ms) is quite arbitrary!
121+
let timeout: NodeJS.Timeout | undefined = undefined;
122+
return () => {
123+
clearTimeout(timeout);
124+
timeout = setTimeout(() => this.forceReload(), 250);
125+
};
126+
}
127+
118128
private async locateAllMods(): Promise<ModLocation[]> {
119129
// Sort locators by priority, lowest number is highest priority
120130
const locators = [...this.locators.entries()].sort(([, a], [, b]) => a.priority - b.priority);

electron/src/mods/locator.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,6 @@ export class DevelopmentModLocator implements ModLocator {
179179
this.fsWatcher = chokidar.watch(this.modFiles, {
180180
persistent: false,
181181
ignoreInitial: true,
182-
awaitWriteFinish: true,
183-
atomic: true,
184182
});
185183
}
186184

0 commit comments

Comments
 (0)