Skip to content

Commit da5b536

Browse files
committed
Exit without message if canceled before UI is up
1 parent 0d990d3 commit da5b536

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

cmd.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <QMessageBox>
88
#include <QTimer>
99

10+
#include "mainwindow.h"
11+
1012
#include <unistd.h>
1113

1214
Cmd::Cmd(QObject *parent)
@@ -75,17 +77,20 @@ bool Cmd::run(const QString &cmd, QString *output, const QByteArray *input, bool
7577
}
7678
if (elevate && getuid() != 0) {
7779
bool result = proc(asRoot, {helper, cmd}, output, input, true);
78-
if (exitCode() == 126 || exitCode() == 127) {
79-
QMessageBox::critical(nullptr, tr("Administrator Access Required"),
80-
tr("This operation requires administrator privileges. Please restart the application "
81-
"and enter your password when prompted."));
80+
// Command-not-found is returned when password is entered incorrectly
81+
if (exitCode() == EXIT_CODE_PERMISSION_DENIED || exitCode() == EXIT_CODE_COMMAND_NOT_FOUND) {
82+
if (qobject_cast<MainWindow *>(qApp->activeWindow())) {
83+
QMessageBox::critical(
84+
nullptr, tr("Administrator Access Required"),
85+
tr("This operation requires administrator privileges. Please restart the application "
86+
"and enter your password when prompted."));
87+
}
8288
QTimer::singleShot(0, qApp, &QApplication::quit);
8389
exit(EXIT_FAILURE);
8490
}
8591
return result;
86-
} else {
87-
return proc("/bin/bash", {"-c", cmd}, output, input, true);
8892
}
93+
return proc("/bin/bash", {"-c", cmd}, output, input, true);
8994
}
9095

9196
bool Cmd::runAsRoot(const QString &cmd, QString *output, const QByteArray *input, bool quiet)

cmd.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ class Cmd : public QProcess
2626
void outputAvailable(const QString &out);
2727

2828
private:
29-
QString out_buffer;
3029
QString asRoot;
3130
QString helper;
31+
QString out_buffer;
32+
static constexpr int EXIT_CODE_COMMAND_NOT_FOUND = 127;
33+
static constexpr int EXIT_CODE_PERMISSION_DENIED = 126;
3234
};

0 commit comments

Comments
 (0)