diff --git a/src/core/main.cpp b/src/core/main.cpp index 36717db0..f3fef81d 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -31,10 +32,12 @@ int qs_main(int argc, char** argv) { auto useQApplication = false; auto nativeTextRendering = false; auto desktopSettingsAware = true; + auto shellId = QString(); QHash envOverrides; int debugPort = -1; bool waitForDebug = false; + bool printCurrent = false; { const auto app = QCoreApplication(argc, argv); @@ -85,7 +88,7 @@ int qs_main(int argc, char** argv) { } { - auto printCurrent = parser.isSet(currentOption); + printCurrent = parser.isSet(currentOption); // NOLINTBEGIN #define CHECK(rname, name, level, label, expr) \ @@ -274,9 +277,9 @@ int qs_main(int argc, char** argv) { #undef CHECK #undef OPTSTR - qInfo() << "config file path:" << configFilePath; + shellId = QCryptographicHash::hash(configFilePath.toUtf8(), QCryptographicHash::Md5).toHex(); - if (printCurrent) return 0; + qInfo() << "config file path:" << configFilePath; } if (!QFile(configFilePath).exists()) { @@ -315,6 +318,8 @@ int qs_main(int argc, char** argv) { auto var = envPragma.sliced(0, splitIdx).trimmed(); auto val = envPragma.sliced(splitIdx + 1).trimmed(); envOverrides.insert(var, val); + } else if (pragma.startsWith("ShellId ")) { + shellId = pragma.sliced(8).trimmed(); } else { qCritical() << "Unrecognized pragma" << pragma; return -1; @@ -325,6 +330,12 @@ int qs_main(int argc, char** argv) { file.close(); } + + if (printCurrent) { + qInfo() << "shell id:" << shellId; + return 0; + } + for (auto [var, val]: envOverrides.asKeyValueRange()) { qputenv(var.toUtf8(), val.toUtf8()); } @@ -396,7 +407,7 @@ int qs_main(int argc, char** argv) { QQuickWindow::setTextRenderType(QQuickWindow::NativeTextRendering); } - auto root = RootWrapper(configFilePath); + auto root = RootWrapper(configFilePath, shellId); QGuiApplication::setQuitOnLastWindowClosed(false); auto code = QGuiApplication::exec(); diff --git a/src/core/rootwrapper.cpp b/src/core/rootwrapper.cpp index 096ac4de..c4c5e711 100644 --- a/src/core/rootwrapper.cpp +++ b/src/core/rootwrapper.cpp @@ -16,10 +16,11 @@ #include "scan.hpp" #include "shell.hpp" -RootWrapper::RootWrapper(QString rootPath) - : QObject(nullptr) - , rootPath(std::move(rootPath)) - , originalWorkingDirectory(QDir::current().absolutePath()) { +RootWrapper::RootWrapper(QString rootPath, QString shellId) + : QObject(nullptr) + , rootPath(std::move(rootPath)) + , shellId(std::move(shellId)) + , originalWorkingDirectory(QDir::current().absolutePath()) { // clang-format off QObject::connect(QuickshellSettings::instance(), &QuickshellSettings::watchFilesChanged, this, &RootWrapper::onWatchFilesChanged); // clang-format on diff --git a/src/core/rootwrapper.hpp b/src/core/rootwrapper.hpp index 7958ee5c..46603097 100644 --- a/src/core/rootwrapper.hpp +++ b/src/core/rootwrapper.hpp @@ -12,7 +12,7 @@ class RootWrapper: public QObject { Q_OBJECT; public: - explicit RootWrapper(QString rootPath); + explicit RootWrapper(QString rootPath, QString shellId); ~RootWrapper() override; Q_DISABLE_COPY_MOVE(RootWrapper); @@ -24,6 +24,7 @@ private slots: private: QString rootPath; + QString shellId; EngineGeneration* generation = nullptr; QString originalWorkingDirectory; };