feat: add support for getting and setting workdir

This commit is contained in:
outfoxxed committed 2024-03-03 17:05:19 -08:00
1 parent b5f50cd68f
commit bbe64f42f3
8 files changed
+109 -2

No files matched your search

+9 -1
View File
@@ -2,6 +2,7 @@
#include <cstdlib>
#include <utility>
#include <qdir.h>
#include <qfileinfo.h>
#include <qlogging.h>
#include <qobject.h>
@@ -10,6 +11,7 @@
#include <qtimer.h>
#include <qurl.h>
#include "qmlglobal.hpp"
#include "reload.hpp"
#include "shell.hpp"
#include "watcher.hpp"
@@ -17,7 +19,8 @@
RootWrapper::RootWrapper(QString rootPath)
: QObject(nullptr)
, rootPath(std::move(rootPath))
, engine(this) {
, engine(this)
, originalWorkingDirectory(QDir::current().absolutePath()) {
this->reloadGraph(true);
if (this->root == nullptr) {
@@ -28,14 +31,19 @@ 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) {
QuickshellGlobal::deleteInstance();
if (this->root != nullptr) {
this->engine.clearComponentCache();
}
QDir::setCurrent(this->originalWorkingDirectory);
auto component = QQmlComponent(&this->engine, QUrl::fromLocalFile(this->rootPath));
auto* obj = component.beginCreate(this->engine.rootContext());