Watching File Tree and Reactively Updating on BrowserWindow


I’m looking to use a file watcher like chokidar ( or gaze to watch a file tree and update a BrowserWindow automatically as changes occur on the file tree.

As far as I understand from the docs, the usual pattern to do something like this would be by using remote from the BrowserWindow, but I feel like it makes more sense to have a single source of truth in the main process instead.

Maybe I’m just confused about the differences between ipc and remote - can anybody explain what pattern makes the most sense for a situation like this?

Also, when I try to use chokidar with remote, I’m getting errors browser-side - which I’m assuming are the result of trying to use binaries in the BrowserWindow.

Any insight(s) here?


You can use chokidar directly in renderer-process, no need to make it run in main-process that makes it very hard to debug.

However, if you wish to maintain a filesystem that can share information among windows, put it in main process and use ipc sending informations would be a better choice. The difference between ipc and remote is the methods/properties in remote module and the module it required eventually invoke a ipc-send-sync function. So far as I known the sync-ipc will block rendering of the web-browser in some how and in my experience sometimes it cause unwanted result.

I use ipc and put file-system in main-process in my Game Editor, you can see how I do this in and, The assets panel will sending ipc message to asset-db to ask the hierarchy of the native filesystem, and inside asset-db we actually watch the changes and sending back the result to assets panel during the App running.