forked from quickshell/quickshell
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
|
@ -8,8 +8,10 @@
|
|||
#include <qguiapplication.h>
|
||||
#include <qicon.h>
|
||||
#include <qjsengine.h>
|
||||
#include <qlist.h>
|
||||
#include <qlogging.h>
|
||||
#include <qobject.h>
|
||||
#include <qprocess.h>
|
||||
#include <qqmlcontext.h>
|
||||
#include <qqmlengine.h>
|
||||
#include <qqmllist.h>
|
||||
|
@ -21,6 +23,7 @@
|
|||
#include <qwindowdefs.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../io/processcore.hpp"
|
||||
#include "generation.hpp"
|
||||
#include "iconimageprovider.hpp"
|
||||
#include "paths.hpp"
|
||||
|
@ -246,6 +249,36 @@ QVariant QuickshellGlobal::env(const QString& variable) { // NOLINT
|
|||
return qEnvironmentVariable(vstr.data());
|
||||
}
|
||||
|
||||
void QuickshellGlobal::execDetached(QList<QString> command) {
|
||||
QuickshellGlobal::execDetached(ProcessContext(std::move(command)));
|
||||
}
|
||||
|
||||
void QuickshellGlobal::execDetached(const ProcessContext& context) {
|
||||
if (context.command.isEmpty()) {
|
||||
qWarning() << "Cannot start process as command is empty.";
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& cmd = context.command.first();
|
||||
auto args = context.command.sliced(1);
|
||||
|
||||
QProcess process;
|
||||
|
||||
qs::core::process::setupProcessEnvironment(
|
||||
&process,
|
||||
context.clearEnvironment,
|
||||
context.environment
|
||||
);
|
||||
|
||||
if (!context.workingDirectory.isEmpty()) {
|
||||
process.setWorkingDirectory(context.workingDirectory);
|
||||
}
|
||||
|
||||
process.setProgram(cmd);
|
||||
process.setArguments(args);
|
||||
process.startDetached();
|
||||
}
|
||||
|
||||
QString QuickshellGlobal::iconPath(const QString& icon) {
|
||||
return IconImageProvider::requestString(icon);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue