I am writing an app that loads various files and folders from the user’s filesystem, fetches some data from the files (eg. the file’s icon), and then displays the information in the app for each file. It works great except that the app hangs while this information is being gathered and displayed.
I’ve tried making this asynchronous (via await/async, by using Promises, and through setTimeout
), but it does not impact performance much. I have also tried using Javascript’s Web Workers, but the Electron docs warn against doing this with built-in NodeJs modules (I am using path and fs), and on top of that, using const { app, } = require('electron'); const blankIcon = app.getFileIcon("/path/to/file.txt")
in a worker script doesn’t seem to work, even with nodeIntegrationInWorker
set to true.
My question is this: in general, what is the best way to use async/threads/multiprocessing to run filesystem operations and display the results in an Electron app without making the app hang?
Apologies if this question is a bit vague. I have not been able to find much helpful information on this elsewhere on the internet.
Thanks in advance!