summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-09-02 17:24:14 +1000
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-09-02 17:24:14 +1000
commita841c776d30e705a18800269940b53cc1bb00457 (patch)
tree31c7f4e8713b73f1a3b4fd82a99f24019d2ef1d4
parentplugin/fsm: async update (diff)
downloadcaelestia-shell-a841c776d30e705a18800269940b53cc1bb00457.tar.gz
caelestia-shell-a841c776d30e705a18800269940b53cc1bb00457.tar.bz2
caelestia-shell-a841c776d30e705a18800269940b53cc1bb00457.zip
plugin/fsm: async add watcher paths
Also remove debug messages and remove futures from hash on completion
-rw-r--r--plugin/src/Caelestia/filesystemmodel.cpp32
1 files changed, 22 insertions, 10 deletions
diff --git a/plugin/src/Caelestia/filesystemmodel.cpp b/plugin/src/Caelestia/filesystemmodel.cpp
index ee2f524..40b322b 100644
--- a/plugin/src/Caelestia/filesystemmodel.cpp
+++ b/plugin/src/Caelestia/filesystemmodel.cpp
@@ -80,10 +80,25 @@ QList<FileSystemEntry*> FileSystemModel::entries() const {
void FileSystemModel::watchDirIfRecursive(const QString& path) {
if (m_recursive) {
- QDirIterator iter(path, QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
- while (iter.hasNext()) {
- m_watcher.addPath(iter.next());
- }
+ const auto currentDir = m_dir;
+ const auto future = QtConcurrent::run([path]() {
+ QDirIterator iter(path, QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
+ QStringList dirs;
+ while (iter.hasNext()) {
+ dirs << iter.next();
+ }
+ return dirs;
+ });
+ const auto watcher = new QFutureWatcher<QStringList>(this);
+ connect(watcher, &QFutureWatcher<QStringList>::finished, this, [currentDir, watcher, this]() {
+ const auto paths = watcher->result();
+ if (currentDir == m_dir && !paths.isEmpty()) {
+ // Ignore if dir has changed
+ m_watcher.addPaths(paths);
+ }
+ watcher->deleteLater();
+ });
+ watcher->setFuture(future);
}
}
@@ -188,15 +203,14 @@ void FileSystemModel::updateEntriesForDir(const QString& dir) {
const auto watcher = new QFutureWatcher<QPair<QSet<QString>, QSet<QString>>>(this);
- connect(watcher, &QFutureWatcher<QPair<QSet<QString>, QSet<QString>>>::finished, this, [watcher, this]() {
+ connect(watcher, &QFutureWatcher<QPair<QSet<QString>, QSet<QString>>>::finished, this, [dir, watcher, this]() {
+ m_futures.remove(dir);
+
if (!watcher->future().isResultReadyAt(0)) {
watcher->deleteLater();
return;
}
- QElapsedTimer timer;
- timer.start();
-
const auto result = watcher->result();
const auto removedPaths = result.first;
const auto addedPaths = result.second;
@@ -229,8 +243,6 @@ void FileSystemModel::updateEntriesForDir(const QString& dir) {
endResetModel();
watcher->deleteLater();
-
- qDebug() << "Update took" << timer.elapsed() << "ms";
});
watcher->setFuture(future);