diff --git a/plugin/src/Caelestia/Config/rootconfig.cpp b/plugin/src/Caelestia/Config/rootconfig.cpp index 193ac472..bab8e4b8 100644 --- a/plugin/src/Caelestia/Config/rootconfig.cpp +++ b/plugin/src/Caelestia/Config/rootconfig.cpp @@ -47,6 +47,11 @@ void RootConfig::setupFileBackend(const QString& path) { m_recentlySaved = false; }); + m_reloadDebounce = new QTimer(this); + m_reloadDebounce->setSingleShot(true); + m_reloadDebounce->setInterval(50); + connect(m_reloadDebounce, &QTimer::timeout, this, &RootConfig::reload); + connect(m_watcher, &QFileSystemWatcher::fileChanged, this, &RootConfig::onFileChanged); qCDebug(lcConfig) << "Setting up file backend for" << metaObject()->className() << "at" << path; @@ -105,13 +110,8 @@ void RootConfig::onFileChanged() { if (!m_watcher->files().contains(m_filePath)) m_watcher->addPath(m_filePath); - if (!m_recentlySaved) { - m_parseRetries = 0; - if (m_retryTimer) - m_retryTimer->stop(); - - reload(); - } + if (!m_recentlySaved) + m_reloadDebounce->start(); } void RootConfig::save() { diff --git a/plugin/src/Caelestia/Config/rootconfig.hpp b/plugin/src/Caelestia/Config/rootconfig.hpp index cfb1f82b..fc9eabae 100644 --- a/plugin/src/Caelestia/Config/rootconfig.hpp +++ b/plugin/src/Caelestia/Config/rootconfig.hpp @@ -42,6 +42,7 @@ private: QTimer* m_saveTimer = nullptr; QTimer* m_cooldownTimer = nullptr; QTimer* m_retryTimer = nullptr; + QTimer* m_reloadDebounce = nullptr; int m_parseRetries = 0; };