mirror of
https://git.outfoxxed.me/quickshell/quickshell.git
synced 2025-11-04 19:04:56 +11:00
core/qmlglobal: add execDetached functions for spawning processes
This commit is contained in:
parent
0140356d99
commit
0499518143
10 changed files with 167 additions and 30 deletions
37
src/io/processcore.cpp
Normal file
37
src/io/processcore.cpp
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#include "processcore.hpp"
|
||||
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qhash.h>
|
||||
#include <qprocess.h>
|
||||
#include <qvariant.h>
|
||||
|
||||
#include "../core/common.hpp"
|
||||
|
||||
namespace qs::core::process {
|
||||
|
||||
void setupProcessEnvironment(
|
||||
QProcess* process,
|
||||
bool clear,
|
||||
const QHash<QString, QVariant>& envChanges
|
||||
) {
|
||||
const auto& sysenv = qs::Common::INITIAL_ENVIRONMENT;
|
||||
auto env = clear ? QProcessEnvironment() : sysenv;
|
||||
|
||||
for (auto& name: envChanges.keys()) {
|
||||
auto value = envChanges.value(name);
|
||||
if (!value.isValid()) continue;
|
||||
|
||||
if (clear) {
|
||||
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);
|
||||
}
|
||||
|
||||
} // namespace qs::core::process
|
||||
Loading…
Add table
Add a link
Reference in a new issue