forked from quickshell/quickshell
refactor: move settings to their own object
This commit is contained in:
parent
62f99f5754
commit
4ef4cba4ee
8 changed files with 107 additions and 78 deletions
|
@ -27,6 +27,10 @@ RootWrapper::RootWrapper(QString rootPath)
|
|||
QObject::connect(&this->engine, &QQmlEngine::quit, app, &QCoreApplication::quit);
|
||||
QObject::connect(&this->engine, &QQmlEngine::exit, app, &QCoreApplication::exit);
|
||||
|
||||
// clang-format off
|
||||
QObject::connect(QuickshellSettings::instance(), &QuickshellSettings::watchFilesChanged, this, &RootWrapper::onWatchFilesChanged);
|
||||
// clang-format on
|
||||
|
||||
this->reloadGraph(true);
|
||||
|
||||
if (this->root == nullptr) {
|
||||
|
@ -37,13 +41,12 @@ RootWrapper::RootWrapper(QString rootPath)
|
|||
|
||||
RootWrapper::~RootWrapper() {
|
||||
// event loop may no longer be running so deleteLater is not an option
|
||||
QuickshellGlobal::deleteInstance();
|
||||
delete this->root;
|
||||
}
|
||||
|
||||
void RootWrapper::reloadGraph(bool hard) {
|
||||
if (this->root != nullptr) {
|
||||
QuickshellGlobal::deleteInstance();
|
||||
QuickshellSettings::reset();
|
||||
this->engine.clearComponentCache();
|
||||
}
|
||||
|
||||
|
@ -87,25 +90,23 @@ void RootWrapper::reloadGraph(bool hard) {
|
|||
QuickshellPlugin::runOnReload();
|
||||
}
|
||||
|
||||
this->onConfigChanged();
|
||||
this->onWatchFilesChanged();
|
||||
}
|
||||
|
||||
void RootWrapper::onConfigChanged() {
|
||||
auto config = this->root->config();
|
||||
void RootWrapper::onWatchFilesChanged() {
|
||||
auto watchFiles = QuickshellSettings::instance()->watchFiles();
|
||||
|
||||
if (config.mWatchFiles && this->configWatcher == nullptr) {
|
||||
if (watchFiles && this->configWatcher == nullptr) {
|
||||
this->configWatcher = new FiletreeWatcher();
|
||||
this->configWatcher->addPath(QFileInfo(this->rootPath).dir().path());
|
||||
|
||||
QObject::connect(this->root, &ShellRoot::configChanged, this, &RootWrapper::onConfigChanged);
|
||||
|
||||
QObject::connect(
|
||||
this->configWatcher,
|
||||
&FiletreeWatcher::fileChanged,
|
||||
this,
|
||||
&RootWrapper::onWatchedFilesChanged
|
||||
);
|
||||
} else if (!config.mWatchFiles && this->configWatcher != nullptr) {
|
||||
} else if (!watchFiles && this->configWatcher != nullptr) {
|
||||
this->configWatcher->deleteLater();
|
||||
this->configWatcher = nullptr;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue