fix(crashes): stop destroying QThread workers while still running

Deleting SearchWorker/ListWorker/InstallWorker from the `finished` ->
`deleteLater` connection aborted the app with
"QThread: Destroyed while thread is still running" (SIGABRT) whenever a
list loaded or a package op finished. The deferred delete raced the
thread teardown because these workers have no event loop to process it
after run() returns.

Wait for the thread to complete (wait() clears the running flag, and by
then run() already emitted finished) before scheduling deleteLater, and
bind every cross-thread signal to the MainWindow context object so the
handlers run queued on the GUI thread instead of inside the worker.

Also drop the intrusive popups (removal confirmation, pacman/sudo
unavailable, empty-search notice) in favour of status bar messages, and
let sudo take the password via -S so no per-op polkit dialog is shown.

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
BlackAngelTV committed 2026-08-28 15:13:15 +02:00
1 parent 5df9f2c22a
commit ad31e5c597
5 files changed
+264 -67

No files matched your search

+84 -36
View File
@@ -19,6 +19,38 @@ static std::string exec(const char* cmd) {
return result;
}
// Escape a string so it can be embedded inside single quotes in a shell
// command without breaking out of the quotes (used for the sudo password).
static std::string shellQuote(const std::string& s) {
std::string out = "'";
for (char c : s) {
if (c == '\'') out += "'\\''";
else out += c;
}
out += "'";
return out;
}
// Run a privileged pacman command as root, piping the password to `sudo -S`
// on stdin and returning the combined stdout+stderr.
static std::string execPrivileged(const std::string& pacmanCmd,
const std::string& password) {
std::string full = "printf '%s\\n' " + shellQuote(password)
+ " | sudo -S " + pacmanCmd + " 2>&1";
return exec(full.c_str());
}
// Stream the lines of a command's output to the progress callback, if any.
static void streamOutput(const std::string& output,
std::function<void(const std::string&)> progressCallback) {
if (!progressCallback) return;
std::istringstream iss(output);
std::string line;
while (std::getline(iss, line)) {
if (!line.empty()) progressCallback(line);
}
}
std::vector<PackageInfo> PacmanManager::search(const std::string& query) {
std::vector<PackageInfo> results;
@@ -68,52 +100,53 @@ std::vector<PackageInfo> PacmanManager::search(const std::string& query) {
bool PacmanManager::install(const std::string& packageName,
std::function<void(const std::string&)> progressCallback) {
if (progressCallback) progressCallback("Installation de " + packageName + "...");
std::string cmd = "pkexec pacman -S --noconfirm " + packageName + " 2>&1";
std::string output = exec(cmd.c_str());
if (progressCallback) {
std::istringstream iss(output);
std::string line;
while (std::getline(iss, line)) {
if (!line.empty()) progressCallback(line);
}
std::string output = execPrivileged("pacman -S --noconfirm " + packageName, m_password);
streamOutput(output, progressCallback);
// A wrong/expired password must not be silently reused: drop it so the
// next attempt prompts again.
if (authFailed(output)) {
clearPassword();
return false;
}
return isPackageInstalled(packageName);
}
bool PacmanManager::remove(const std::string& packageName,
std::function<void(const std::string&)> progressCallback) {
if (progressCallback) progressCallback("Suppression de " + packageName + "...");
std::string cmd = "pkexec pacman -R --noconfirm " + packageName + " 2>&1";
std::string output = exec(cmd.c_str());
if (progressCallback) {
std::istringstream iss(output);
std::string line;
while (std::getline(iss, line)) {
if (!line.empty()) progressCallback(line);
}
std::string output = execPrivileged("pacman -R --noconfirm " + packageName, m_password);
streamOutput(output, progressCallback);
if (authFailed(output)) {
clearPassword();
return false;
}
return !isPackageInstalled(packageName);
}
bool PacmanManager::update(const std::string& packageName,
std::function<void(const std::string&)> progressCallback) {
std::string output;
if (packageName.empty()) {
if (progressCallback) progressCallback("Mise à jour de tous les paquets...");
std::string cmd = "pkexec pacman -Syu --noconfirm 2>&1";
exec(cmd.c_str());
return true;
output = execPrivileged("pacman -Syu --noconfirm", m_password);
} else {
if (progressCallback) progressCallback("Mise à jour de " + packageName + "...");
std::string cmd = "pkexec pacman -S --noconfirm " + packageName + " 2>&1";
exec(cmd.c_str());
return true;
output = execPrivileged("pacman -S --noconfirm " + packageName, m_password);
}
streamOutput(output, progressCallback);
if (authFailed(output)) {
clearPassword();
return false;
}
return true;
}
std::vector<PackageInfo> PacmanManager::listInstalled() {
@@ -175,15 +208,12 @@ std::vector<PackageInfo> PacmanManager::listUpdates() {
bool PacmanManager::refresh(std::function<void(const std::string&)> progressCallback) {
if (progressCallback) progressCallback("Rafraîchissement des bases de données...");
std::string cmd = "pkexec pacman -Sy --noconfirm 2>&1";
std::string output = exec(cmd.c_str());
std::string output = execPrivileged("pacman -Sy --noconfirm", m_password);
streamOutput(output, progressCallback);
if (progressCallback) {
std::istringstream iss(output);
std::string line;
while (std::getline(iss, line)) {
if (!line.empty()) progressCallback(line);
}
if (authFailed(output)) {
clearPassword();
return false;
}
// `pacman -Sy` has no easy success code; treat a completed run as success
@@ -285,3 +315,21 @@ std::map<std::string, std::string> PacmanManager::parseSyncRepos(
return repos;
}
bool PacmanManager::authFailed(const std::string& output) {
return output.find("incorrect password") != std::string::npos
|| output.find("a password is required") != std::string::npos
|| output.find("Authentication failure") != std::string::npos;
}
void PacmanManager::setPassword(const std::string& password) {
m_password = password;
}
void PacmanManager::clearPassword() {
m_password.clear();
}
bool PacmanManager::hasPassword() const {
return !m_password.empty();
}