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>
65 lines
2.9 KiB
C++
65 lines
2.9 KiB
C++
#pragma once
|
|
|
|
#include "package-manager.h"
|
|
#include <map>
|
|
|
|
// Native Arch Linux package manager, integrated directly into the application
|
|
class PacmanManager : public IPackageManager {
|
|
public:
|
|
std::string getName() const override { return "pacman"; }
|
|
std::string getVersion() const override { return "1.0.0"; }
|
|
std::string getDescription() const override {
|
|
return "Gestionnaire de paquets natif d'Arch Linux";
|
|
}
|
|
|
|
bool canSearch() const override { return true; }
|
|
bool canInstall() const override { return true; }
|
|
bool canRemove() const override { return true; }
|
|
bool canUpdate() const override { return true; }
|
|
bool canListInstalled() const override { return true; }
|
|
|
|
bool isAvailable() const override {
|
|
return system("which pacman > /dev/null 2>&1") == 0;
|
|
}
|
|
|
|
// Parse `pacman -Q` output (one "name version" line per package).
|
|
// Exposed as static so the parsing can be unit-tested without invoking pacman.
|
|
static std::vector<PackageInfo> parseInstalledOutput(const std::string& output);
|
|
|
|
// Parse `pacman -Qi` output (one block per package) into a name -> installed size map.
|
|
// Exposed as static so the parsing can be unit-tested without invoking pacman.
|
|
static std::map<std::string, std::string> parseInstalledSizes(const std::string& output);
|
|
|
|
// Parse `pacman -Sl` output ("repo name version" per line) into a name -> repository map.
|
|
// 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;
|
|
bool remove(const std::string& packageName,
|
|
std::function<void(const std::string&)> progressCallback) override;
|
|
bool update(const std::string& packageName = "",
|
|
std::function<void(const std::string&)> progressCallback = nullptr) override;
|
|
std::vector<PackageInfo> listInstalled() override;
|
|
std::vector<PackageInfo> listUpdates() override;
|
|
bool refresh(std::function<void(const std::string&)> progressCallback = nullptr) override;
|
|
|
|
private:
|
|
bool isPackageInstalled(const std::string& name);
|
|
|
|
std::string m_password;
|
|
};
|