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 <qcommandlineoption.h>
|
||||||
#include <qcommandlineparser.h>
|
#include <qcommandlineparser.h>
|
||||||
#include <qcoreapplication.h>
|
#include <qcoreapplication.h>
|
||||||
|
#include <qcryptographichash.h>
|
||||||
#include <qdir.h>
|
#include <qdir.h>
|
||||||
#include <qfileinfo.h>
|
#include <qfileinfo.h>
|
||||||
#include <qguiapplication.h>
|
#include <qguiapplication.h>
|
||||||
|
@ -31,10 +32,12 @@ int qs_main(int argc, char** argv) {
|
||||||
auto useQApplication = false;
|
auto useQApplication = false;
|
||||||
auto nativeTextRendering = false;
|
auto nativeTextRendering = false;
|
||||||
auto desktopSettingsAware = true;
|
auto desktopSettingsAware = true;
|
||||||
|
auto shellId = QString();
|
||||||
QHash<QString, QString> envOverrides;
|
QHash<QString, QString> envOverrides;
|
||||||
|
|
||||||
int debugPort = -1;
|
int debugPort = -1;
|
||||||
bool waitForDebug = false;
|
bool waitForDebug = false;
|
||||||
|
bool printCurrent = false;
|
||||||
|
|
||||||
{
|
{
|
||||||
const auto app = QCoreApplication(argc, argv);
|
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
|
// NOLINTBEGIN
|
||||||
#define CHECK(rname, name, level, label, expr) \
|
#define CHECK(rname, name, level, label, expr) \
|
||||||
|
@ -274,9 +277,9 @@ int qs_main(int argc, char** argv) {
|
||||||
#undef CHECK
|
#undef CHECK
|
||||||
#undef OPTSTR
|
#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()) {
|
if (!QFile(configFilePath).exists()) {
|
||||||
|
@ -315,6 +318,8 @@ int qs_main(int argc, char** argv) {
|
||||||
auto var = envPragma.sliced(0, splitIdx).trimmed();
|
auto var = envPragma.sliced(0, splitIdx).trimmed();
|
||||||
auto val = envPragma.sliced(splitIdx + 1).trimmed();
|
auto val = envPragma.sliced(splitIdx + 1).trimmed();
|
||||||
envOverrides.insert(var, val);
|
envOverrides.insert(var, val);
|
||||||
|
} else if (pragma.startsWith("ShellId ")) {
|
||||||
|
shellId = pragma.sliced(8).trimmed();
|
||||||
} else {
|
} else {
|
||||||
qCritical() << "Unrecognized pragma" << pragma;
|
qCritical() << "Unrecognized pragma" << pragma;
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -325,6 +330,12 @@ int qs_main(int argc, char** argv) {
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (printCurrent) {
|
||||||
|
qInfo() << "shell id:" << shellId;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
for (auto [var, val]: envOverrides.asKeyValueRange()) {
|
for (auto [var, val]: envOverrides.asKeyValueRange()) {
|
||||||
qputenv(var.toUtf8(), val.toUtf8());
|
qputenv(var.toUtf8(), val.toUtf8());
|
||||||
}
|
}
|
||||||
|
@ -396,7 +407,7 @@ int qs_main(int argc, char** argv) {
|
||||||
QQuickWindow::setTextRenderType(QQuickWindow::NativeTextRendering);
|
QQuickWindow::setTextRenderType(QQuickWindow::NativeTextRendering);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto root = RootWrapper(configFilePath);
|
auto root = RootWrapper(configFilePath, shellId);
|
||||||
QGuiApplication::setQuitOnLastWindowClosed(false);
|
QGuiApplication::setQuitOnLastWindowClosed(false);
|
||||||
|
|
||||||
auto code = QGuiApplication::exec();
|
auto code = QGuiApplication::exec();
|
||||||
|
|
|
@ -16,10 +16,11 @@
|
||||||
#include "scan.hpp"
|
#include "scan.hpp"
|
||||||
#include "shell.hpp"
|
#include "shell.hpp"
|
||||||
|
|
||||||
RootWrapper::RootWrapper(QString rootPath)
|
RootWrapper::RootWrapper(QString rootPath, QString shellId)
|
||||||
: QObject(nullptr)
|
: QObject(nullptr)
|
||||||
, rootPath(std::move(rootPath))
|
, rootPath(std::move(rootPath))
|
||||||
, originalWorkingDirectory(QDir::current().absolutePath()) {
|
, shellId(std::move(shellId))
|
||||||
|
, originalWorkingDirectory(QDir::current().absolutePath()) {
|
||||||
// clang-format off
|
// clang-format off
|
||||||
QObject::connect(QuickshellSettings::instance(), &QuickshellSettings::watchFilesChanged, this, &RootWrapper::onWatchFilesChanged);
|
QObject::connect(QuickshellSettings::instance(), &QuickshellSettings::watchFilesChanged, this, &RootWrapper::onWatchFilesChanged);
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
|
@ -12,7 +12,7 @@ class RootWrapper: public QObject {
|
||||||
Q_OBJECT;
|
Q_OBJECT;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit RootWrapper(QString rootPath);
|
explicit RootWrapper(QString rootPath, QString shellId);
|
||||||
~RootWrapper() override;
|
~RootWrapper() override;
|
||||||
Q_DISABLE_COPY_MOVE(RootWrapper);
|
Q_DISABLE_COPY_MOVE(RootWrapper);
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ private slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString rootPath;
|
QString rootPath;
|
||||||
|
QString shellId;
|
||||||
EngineGeneration* generation = nullptr;
|
EngineGeneration* generation = nullptr;
|
||||||
QString originalWorkingDirectory;
|
QString originalWorkingDirectory;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue