|
1 | | -// Shell komut çalıştırıcı |
2 | | - |
3 | 1 | #include "commandrunner.h" |
4 | 2 | #include <QProcess> |
5 | 3 |
|
6 | 4 | CommandRunner::CommandRunner(QObject *parent) |
7 | 5 | : QObject(parent) |
8 | 6 | {} |
9 | 7 |
|
10 | | -CommandRunner::Result CommandRunner::run(const QString &command, const QStringList &args) |
| 8 | +CommandRunner::Result CommandRunner::run(const QString &program, const QStringList &args) |
11 | 9 | { |
12 | 10 | QProcess process; |
13 | | - process.start(command, args); |
14 | | - process.waitForFinished(-1); // -1 = timeout yok |
| 11 | + |
| 12 | + // Stdout'u anlık olarak sinyal olarak ilet |
| 13 | + connect(&process, &QProcess::readyReadStandardOutput, this, [&]() { |
| 14 | + const QString line = QString::fromUtf8(process.readAllStandardOutput()).trimmed(); |
| 15 | + if (!line.isEmpty()) |
| 16 | + emit outputLine(line); |
| 17 | + }); |
| 18 | + |
| 19 | + process.start(program, args); |
| 20 | + |
| 21 | + if (!process.waitForStarted(3000)) { |
| 22 | + return Result { |
| 23 | + .exitCode = -1, |
| 24 | + .stdout = {}, |
| 25 | + .stderr = QStringLiteral("Failed to start: %1").arg(program), |
| 26 | + }; |
| 27 | + } |
| 28 | + |
| 29 | + process.waitForFinished(-1); |
15 | 30 |
|
16 | 31 | return Result { |
17 | 32 | .exitCode = process.exitCode(), |
18 | 33 | .stdout = QString::fromUtf8(process.readAllStandardOutput()), |
19 | 34 | .stderr = QString::fromUtf8(process.readAllStandardError()), |
20 | 35 | }; |
21 | 36 | } |
| 37 | + |
| 38 | +CommandRunner::Result CommandRunner::runAsRoot(const QString &program, const QStringList &args) |
| 39 | +{ |
| 40 | + // pkexec ile privilege escalation — sudo yerine PolicyKit kullanıyoruz |
| 41 | + QStringList pkexecArgs; |
| 42 | + pkexecArgs << program << args; |
| 43 | + return run(QStringLiteral("pkexec"), pkexecArgs); |
| 44 | +} |
0 commit comments