Skip to content

Commit 6f7e2a7

Browse files
authored
Merge pull request #5 from Acik-Kaynak-Gelistirme-Toplulugu/fix/command-runner
feat: implement CommandRunner with pkexec support
2 parents d32e989 + f26bca2 commit 6f7e2a7

2 files changed

Lines changed: 41 additions & 14 deletions

File tree

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,44 @@
1-
// Shell komut çalıştırıcı
2-
31
#include "commandrunner.h"
42
#include <QProcess>
53

64
CommandRunner::CommandRunner(QObject *parent)
75
: QObject(parent)
86
{}
97

10-
CommandRunner::Result CommandRunner::run(const QString &command, const QStringList &args)
8+
CommandRunner::Result CommandRunner::run(const QString &program, const QStringList &args)
119
{
1210
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);
1530

1631
return Result {
1732
.exitCode = process.exitCode(),
1833
.stdout = QString::fromUtf8(process.readAllStandardOutput()),
1934
.stderr = QString::fromUtf8(process.readAllStandardError()),
2035
};
2136
}
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+
}

src/backend/system/commandrunner.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,31 @@
22

33
#include <QObject>
44
#include <QString>
5+
#include <QStringList>
56

6-
// CommandRunner: Shell komutlarını çalıştırır, stdout/stderr döner.
7-
// Tüm backend modülleri bu sınıfı kullanırdoğrudan sistem() çağrısı yapılmaz.
7+
// CommandRunner: Tüm backend modüllerinin kullandığı shell komut çalıştırıcı.
8+
// Hiçbir modül doğrudan sistem çağrısı yapmazhepsi bu sınıfı kullanır.
89
class CommandRunner : public QObject
910
{
1011
Q_OBJECT
1112

1213
public:
1314
struct Result {
14-
int exitCode; // 0 = başarılı
15-
QString stdout; // Komut çıktısı
16-
QString stderr; // Hata çıktısı
17-
bool success() const { return exitCode == 0; }
15+
int exitCode;
16+
QString stdout;
17+
QString stderr;
18+
bool success() const { return exitCode == 0; }
1819
};
1920

2021
explicit CommandRunner(QObject *parent = nullptr);
2122

22-
// Komutu çalıştır ve sonucu döndür (bloklayan)
23-
Result run(const QString &command, const QStringList &args = {});
23+
// Bloklayan komut — sonuç dönene kadar bekler
24+
Result run(const QString &program, const QStringList &args = {});
25+
26+
// Root gerektiren komut — pkexec ile çalıştırır
27+
Result runAsRoot(const QString &program, const QStringList &args = {});
2428

2529
signals:
26-
// Uzun süren işlemler için anlık çıktı satırı
30+
// Uzun işlemler için anlık çıktı (DNF install vb.)
2731
void outputLine(const QString &line);
2832
};

0 commit comments

Comments
 (0)