|
7 | 7 | #include <QMessageBox> |
8 | 8 | #include <QTimer> |
9 | 9 |
|
| 10 | +#include "mainwindow.h" |
| 11 | + |
10 | 12 | #include <unistd.h> |
11 | 13 |
|
12 | 14 | Cmd::Cmd(QObject *parent) |
@@ -75,17 +77,20 @@ bool Cmd::run(const QString &cmd, QString *output, const QByteArray *input, bool |
75 | 77 | } |
76 | 78 | if (elevate && getuid() != 0) { |
77 | 79 | 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 | + } |
82 | 88 | QTimer::singleShot(0, qApp, &QApplication::quit); |
83 | 89 | exit(EXIT_FAILURE); |
84 | 90 | } |
85 | 91 | return result; |
86 | | - } else { |
87 | | - return proc("/bin/bash", {"-c", cmd}, output, input, true); |
88 | 92 | } |
| 93 | + return proc("/bin/bash", {"-c", cmd}, output, input, true); |
89 | 94 | } |
90 | 95 |
|
91 | 96 | bool Cmd::runAsRoot(const QString &cmd, QString *output, const QByteArray *input, bool quiet) |
|
0 commit comments