forked from quickshell/quickshell
core/process: ignore environment changes made by the Env pragma
This pragma ends up used to set things like QQC theme which shouldn't be cascaded into child processes.
This commit is contained in:
parent
4a0f6382b0
commit
2773e5468f
5 changed files with 25 additions and 17 deletions
|
@ -1,9 +1,11 @@
|
|||
#include "common.hpp"
|
||||
|
||||
#include <qdatetime.h>
|
||||
#include <qprocess.h>
|
||||
|
||||
namespace qs {
|
||||
|
||||
const QDateTime Common::LAUNCH_TIME = QDateTime::currentDateTime();
|
||||
QProcessEnvironment Common::INITIAL_ENVIRONMENT = {}; // NOLINT
|
||||
|
||||
}
|
||||
} // namespace qs
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <qdatetime.h>
|
||||
#include <qprocess.h>
|
||||
|
||||
namespace qs {
|
||||
|
||||
struct Common {
|
||||
static const QDateTime LAUNCH_TIME;
|
||||
static QProcessEnvironment INITIAL_ENVIRONMENT; // NOLINT
|
||||
};
|
||||
|
||||
} // namespace qs
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <qtenvironmentvariables.h>
|
||||
#include <ranges>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "model.hpp"
|
||||
|
||||
namespace {
|
||||
|
@ -260,6 +261,7 @@ void DesktopEntry::doExec(const QString& execString, const QString& workingDirec
|
|||
process.setProgram(args.at(0));
|
||||
process.setArguments(args.sliced(1));
|
||||
if (!workingDirectory.isEmpty()) process.setWorkingDirectory(workingDirectory);
|
||||
process.setProcessEnvironment(qs::Common::INITIAL_ENVIRONMENT);
|
||||
process.startDetached();
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <qtypes.h>
|
||||
#include <qvariant.h>
|
||||
|
||||
#include "../core/common.hpp"
|
||||
#include "../core/generation.hpp"
|
||||
#include "../core/qmlglobal.hpp"
|
||||
#include "datastream.hpp"
|
||||
|
@ -223,26 +224,24 @@ void Process::setupEnvironment(QProcess* process) {
|
|||
process->setWorkingDirectory(this->mWorkingDirectory);
|
||||
}
|
||||
|
||||
if (!this->mEnvironment.isEmpty() || this->mClearEnvironment) {
|
||||
auto sysenv = QProcessEnvironment::systemEnvironment();
|
||||
auto env = this->mClearEnvironment ? QProcessEnvironment() : sysenv;
|
||||
const auto& sysenv = qs::Common::INITIAL_ENVIRONMENT;
|
||||
auto env = this->mClearEnvironment ? QProcessEnvironment() : sysenv;
|
||||
|
||||
for (auto& name: this->mEnvironment.keys()) {
|
||||
auto value = this->mEnvironment.value(name);
|
||||
if (!value.isValid()) continue;
|
||||
for (auto& name: this->mEnvironment.keys()) {
|
||||
auto value = this->mEnvironment.value(name);
|
||||
if (!value.isValid()) continue;
|
||||
|
||||
if (this->mClearEnvironment) {
|
||||
if (value.isNull()) {
|
||||
if (sysenv.contains(name)) env.insert(name, sysenv.value(name));
|
||||
} else env.insert(name, value.toString());
|
||||
} else {
|
||||
if (value.isNull()) env.remove(name);
|
||||
else env.insert(name, value.toString());
|
||||
}
|
||||
if (this->mClearEnvironment) {
|
||||
if (value.isNull()) {
|
||||
if (sysenv.contains(name)) env.insert(name, sysenv.value(name));
|
||||
} else env.insert(name, value.toString());
|
||||
} else {
|
||||
if (value.isNull()) env.remove(name);
|
||||
else env.insert(name, value.toString());
|
||||
}
|
||||
|
||||
process->setProcessEnvironment(env);
|
||||
}
|
||||
|
||||
process->setProcessEnvironment(env);
|
||||
}
|
||||
|
||||
void Process::onStarted() {
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <qlist.h>
|
||||
#include <qlogging.h>
|
||||
#include <qnamespace.h>
|
||||
#include <qprocess.h>
|
||||
#include <qqmldebug.h>
|
||||
#include <qquickwindow.h>
|
||||
#include <qstring.h>
|
||||
|
@ -151,6 +152,8 @@ int launch(const LaunchArgs& args, char** argv, QCoreApplication* coreApplicatio
|
|||
QsPaths::instance()->linkPathDir();
|
||||
LogManager::initFs();
|
||||
|
||||
Common::INITIAL_ENVIRONMENT = QProcessEnvironment::systemEnvironment();
|
||||
|
||||
for (auto [var, val]: pragmas.envOverrides.asKeyValueRange()) {
|
||||
qputenv(var.toUtf8(), val.toUtf8());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue