forked from quickshell/quickshell
core: add per-config shell id
Will be useful for future functionality such as IPC and caching.
This commit is contained in:
parent
79b2fea52e
commit
d582bb7b57
3 changed files with 22 additions and 9 deletions
|
@ -5,6 +5,7 @@
|
|||
#include <qcommandlineoption.h>
|
||||
#include <qcommandlineparser.h>
|
||||
#include <qcoreapplication.h>
|
||||
#include <qcryptographichash.h>
|
||||
#include <qdir.h>
|
||||
#include <qfileinfo.h>
|
||||
#include <qguiapplication.h>
|
||||
|
@ -31,10 +32,12 @@ int qs_main(int argc, char** argv) {
|
|||
auto useQApplication = false;
|
||||
auto nativeTextRendering = false;
|
||||
auto desktopSettingsAware = true;
|
||||
auto shellId = QString();
|
||||
QHash<QString, QString> 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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue