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

+16
View File
@@ -9,6 +9,7 @@
#include <QProgressBar>
#include <QComboBox>
#include <QThread>
#include <QSettings>
#include <string>
#include <vector>
@@ -24,6 +25,7 @@ class QListWidget;
class QListWidgetItem;
class QButtonGroup;
class QFrame;
class QAction;
// Runs a package search off the UI thread.
class SearchWorker : public QThread {
@@ -94,6 +96,14 @@ private slots:
private:
enum BrowseMode { ModeSearch, ModeInstalled, ModeUpdates };
// When the sudo password is requested: once per session (at launch) or
// before every privileged operation.
enum class CredentialMode { AtLaunch, EachTime };
void applyCredentialMode(CredentialMode mode);
bool ensureCredentials();
void clearCredentialsAfterUse();
void setupUI();
void setupSidebar();
void setupHeader();
@@ -174,6 +184,12 @@ private:
HistoryManager* m_historyManager = nullptr;
BrowseMode m_browseMode = ModeSearch;
// Settings
QSettings m_settings;
CredentialMode m_credentialMode = CredentialMode::EachTime;
QAction* m_credLaunchAction = nullptr;
QAction* m_credEachTimeAction = nullptr;
std::vector<PackageInfo> m_currentResults;
std::vector<PackageInfo> m_installedPackages;
PackageInfo m_selectedPackage;
+14
View File
@@ -34,6 +34,18 @@ public:
// Exposed as static so the parsing can be unit-tested without invoking pacman.
static std::map<std::string, std::string> parseSyncRepos(const std::string& output);
// Detect a sudo authentication failure (wrong or missing password) in the
// output of a privileged command. Exposed as static so it can be
// unit-tested without invoking sudo.
static bool authFailed(const std::string& output);
// Credential handling for privileged (sudo) operations. The password is
// kept in memory only for the session (never persisted) and piped to
// `sudo -S` for each privileged command.
void setPassword(const std::string& password);
void clearPassword();
bool hasPassword() const;
std::vector<PackageInfo> search(const std::string& query) override;
bool install(const std::string& packageName,
std::function<void(const std::string&)> progressCallback) override;
@@ -47,4 +59,6 @@ public:
private:
bool isPackageInstalled(const std::string& name);
std::string m_password;
};