feat: debounce reloads
This commit is contained in:
parent
1ad6f657ae
commit
b987a39d79
2 changed files with 8 additions and 7 deletions
|
|
@ -47,6 +47,11 @@ void RootConfig::setupFileBackend(const QString& path) {
|
||||||
m_recentlySaved = false;
|
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);
|
connect(m_watcher, &QFileSystemWatcher::fileChanged, this, &RootConfig::onFileChanged);
|
||||||
|
|
||||||
qCDebug(lcConfig) << "Setting up file backend for" << metaObject()->className() << "at" << path;
|
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))
|
if (!m_watcher->files().contains(m_filePath))
|
||||||
m_watcher->addPath(m_filePath);
|
m_watcher->addPath(m_filePath);
|
||||||
|
|
||||||
if (!m_recentlySaved) {
|
if (!m_recentlySaved)
|
||||||
m_parseRetries = 0;
|
m_reloadDebounce->start();
|
||||||
if (m_retryTimer)
|
|
||||||
m_retryTimer->stop();
|
|
||||||
|
|
||||||
reload();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RootConfig::save() {
|
void RootConfig::save() {
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ private:
|
||||||
QTimer* m_saveTimer = nullptr;
|
QTimer* m_saveTimer = nullptr;
|
||||||
QTimer* m_cooldownTimer = nullptr;
|
QTimer* m_cooldownTimer = nullptr;
|
||||||
QTimer* m_retryTimer = nullptr;
|
QTimer* m_retryTimer = nullptr;
|
||||||
|
QTimer* m_reloadDebounce = nullptr;
|
||||||
int m_parseRetries = 0;
|
int m_parseRetries = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue