diff --git a/js/Makefile.am b/js/Makefile.am index 512be0130..f35026e81 100644 --- a/js/Makefile.am +++ b/js/Makefile.am @@ -3,6 +3,7 @@ jsdir = $(pkgdatadir)/js nobase_dist_js_DATA = \ misc/docInfo.js \ + misc/fileUtils.js \ misc/format.js \ misc/gnomeSession.js \ misc/params.js \ diff --git a/js/misc/fileUtils.js b/js/misc/fileUtils.js new file mode 100644 index 000000000..411004156 --- /dev/null +++ b/js/misc/fileUtils.js @@ -0,0 +1,22 @@ +const Gio = imports.gi.Gio; +const GLib = imports.gi.GLib; + +function listDirAsync(file, callback) { + let allFiles = []; + file.enumerate_children_async(Gio.FILE_ATTRIBUTE_STANDARD_NAME, + Gio.FileQueryInfoFlags.NONE, + GLib.PRIORITY_LOW, null, function (obj, res) { + let enumerator = obj.enumerate_children_finish(res); + function onNextFileComplete(obj, res) { + let files = obj.next_files_finish(res); + if (files.length) { + allFiles = allFiles.concat(files); + enumerator.next_files_async(100, GLib.PRIORITY_LOW, null, onNextFileComplete); + } else { + enumerator.close(null); + callback(allFiles); + } + } + enumerator.next_files_async(100, GLib.PRIORITY_LOW, null, onNextFileComplete); + }); +}