Compare commits
8
Commits
V1.4.3
...
d44dbc3ccf
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d44dbc3ccf
|
||
|
|
f0b37bbb44
|
||
|
|
8670c02eb3
|
||
|
|
656e365daf | ||
|
|
a354a0f7fc | ||
|
|
f3ad3ca523
|
||
|
|
2c7d99138d
|
||
|
|
b204d6814a
|
No files matched your search
+4
-2
@@ -44,6 +44,7 @@ set(SOURCES
|
||||
pages/browse-page.cpp
|
||||
pages/cleanup-page.cpp
|
||||
pages/history-page.cpp
|
||||
src/log-manager.cpp
|
||||
pages/logs-page.cpp
|
||||
pages/plugins-page.cpp
|
||||
resources/resources.qrc
|
||||
@@ -63,6 +64,7 @@ set(HEADERS
|
||||
include/progress-tracker.h
|
||||
include/plugin-shop.h
|
||||
include/app-core.h
|
||||
include/log-manager.h
|
||||
pages/page.h
|
||||
pages/ui-kit.h
|
||||
pages/dashboard-page.h
|
||||
@@ -183,9 +185,9 @@ add_executable(app-core-test tests/app-core.test.cpp
|
||||
src/app-core.cpp src/workers.cpp src/pacman-manager.cpp
|
||||
src/plugin-manager.cpp src/history-manager.cpp src/update-manager.cpp
|
||||
src/plugin-shop.cpp
|
||||
src/app-logging.cpp
|
||||
src/app-logging.cpp src/log-manager.cpp
|
||||
include/app-core.h include/workers.h include/update-manager.h
|
||||
include/plugin-shop.h)
|
||||
include/plugin-shop.h include/log-manager.h)
|
||||
target_include_directories(app-core-test PRIVATE include)
|
||||
target_link_libraries(app-core-test PRIVATE Qt6::Core Qt6::Network)
|
||||
target_compile_definitions(app-core-test PRIVATE
|
||||
|
||||
+12
-9
@@ -172,17 +172,20 @@ The method is picked automatically (no configuration):
|
||||
| Method | When | What happens |
|
||||
| --- | --- | --- |
|
||||
| **Checkout** | a source checkout surrounds the binary (dev) | `git pull`, rebuild, install into the binary's directory |
|
||||
| **Clone** | installed app with no checkout, and `git` + `cmake` + a compiler | the repo is cloned/updated in `~/.local/share/PacManager/src`, rebuilt and installed in place |
|
||||
| **Prebuilt** | no build toolchain available, and the release has a prebuilt archive attached | that archive is downloaded and unpacked |
|
||||
| **Tarball** | no `git`, but `cmake` + a compiler | the release sources are built and installed |
|
||||
| **Clone** | installed app with no checkout, with `git` (or pacman to install the rest) | missing build dependencies are installed first, the repo is cloned/updated in `~/.local/share/PacManager/src`, rebuilt and installed in place |
|
||||
| **Prebuilt** | no build toolchain nor pacman, and the release has a prebuilt archive attached | that archive is downloaded and unpacked |
|
||||
| **Tarball** | no `git`, but a toolchain present or installable | missing build dependencies are installed first, the release sources are built and installed |
|
||||
|
||||
Everything builds in a temporary directory: only the final replacement of the
|
||||
binary (and plugins) needs `sudo`, and only when the target directory is owned
|
||||
by root. PacManager then restarts automatically on the new version.
|
||||
Everything builds in a temporary directory: `sudo` is only used for the final
|
||||
binary replacement (when the target directory is root-owned) and for
|
||||
**automatically installing the build dependencies** — when `qt6-base`, `cmake`,
|
||||
`gcc`/`base-devel` or `git` are missing, PacManager installs them itself through
|
||||
`pacman` as soon as the sudo password is entered, then resumes the build.
|
||||
PacManager then restarts automatically on the new version.
|
||||
|
||||
Nothing produces a prebuilt archive automatically: without one attached to the
|
||||
release, **Clone** or **Tarball** applies instead (so `git`, `cmake` and a
|
||||
compiler are needed on the machine).
|
||||
release, **Clone** or **Tarball** applies instead — having `pacman` and the sudo
|
||||
password is enough, the rest is installed by the update itself.
|
||||
|
||||
All four methods install to the same place — the running binary's directory —
|
||||
and rewrite the `version` file there. To know which release is really installed,
|
||||
@@ -198,7 +201,7 @@ The interface uses **Qt6** with a dark theme, a **navigation sidebar** and stack
|
||||
- 🏠 **Dashboard**: statistics cards, quick actions and recent activity
|
||||
- 🔍 **Search**: search bar, package table on the left and details on the right
|
||||
- 📦 **Installed**: list with **instant name filter** (local, no pacman re-run)
|
||||
- ⬆️ **Updates**: outdated packages detected by `pacman -Qu`, "Update all" button
|
||||
- ⬆️ **Updates**: outdated packages detected by `pacman -Qu`, **the check runs as soon as the tab opens** (no need to press "Update all" to see the list), "Update all" button
|
||||
- 🧹 **Cleanup**: **orphan** packages (`pacman -Qdt`, nothing requires them) and **legacy** ones (`pacman -Qm`, AUR / manual builds), bulk removal of the orphans, and cache trimming: `paccache` / `pacman -Sc` and unused Flatpak runtimes (`flatpak uninstall --unused`)
|
||||
- 📋 **History**: filterable table (installs / removals / updates / cleanups) + CSV export
|
||||
- 📜 **Logs**: built-in `/var/log/pacman.log` viewer with an instant filter
|
||||
|
||||
@@ -174,14 +174,16 @@ La méthode est choisie automatiquement (aucune configuration) :
|
||||
| Méthode | Quand | Ce qui se passe |
|
||||
| --- | --- | --- |
|
||||
| **Checkout** | un dépôt source entoure le binaire (dev) | `git pull`, recompilation puis installation dans le dossier du binaire |
|
||||
| **Clone** | app installée sans dépôt, avec `git` + `cmake` + compilateur | le dépôt est cloné puis mis à jour dans `~/.local/share/PacManager/src`, recompilé et installé en place |
|
||||
| **Prebuilt** | pas d'outillage de compilation et une archive précompilée est attachée à la release | l'archive est téléchargée et décompressée |
|
||||
| **Tarball** | `git` absent mais `cmake` + compilateur présents | les sources de la release sont compilées puis installées |
|
||||
| **Clone** | app installée sans dépôt, avec `git` (ou pacman pour installer le reste) | les dépendances de compilation manquantes sont installées, le dépôt est cloné puis mis à jour dans `~/.local/share/PacManager/src`, recompilé et installé en place |
|
||||
| **Prebuilt** | pas d'outillage de compilation ni de pacman, et une archive précompilée est attachée à la release | l'archive est téléchargée et décompressée |
|
||||
| **Tarball** | `git` absent mais un toolchain présent ou installable | les dépendances de compilation manquantes sont installées, les sources de la release sont compilées puis installées |
|
||||
|
||||
Tout se compile dans un dossier temporaire : seul le remplacement final du
|
||||
binaire (et des plugins) demande `sudo`, et uniquement si le dossier cible
|
||||
appartient à root. PacManager redémarre ensuite automatiquement sur la nouvelle
|
||||
version.
|
||||
Tout se compile dans un dossier temporaire : `sudo` n'intervient que pour
|
||||
l'installation finale du binaire (si le dossier cible appartient à root) et pour
|
||||
**l'installation automatique des dépendances de compilation** — quand `qt6-base`,
|
||||
`cmake`, `gcc`/`base-devel` ou `git` manquent, PacManager les installe lui-même
|
||||
via `pacman` dès que le mot de passe sudo est saisi, puis relance la compilation.
|
||||
PacManager redémarre ensuite automatiquement sur la nouvelle version.
|
||||
|
||||
Rien ne produit d'archive précompilée automatiquement : sans archive attachée à
|
||||
la release, ce sont **Clone** ou **Tarball** qui s'appliquent (donc `git`, `cmake`
|
||||
@@ -202,7 +204,7 @@ L'interface utilise **Qt6** avec un thème sombre, une **sidebar de navigation**
|
||||
- 🏠 **Tableau de bord** : cartes de statistiques, actions rapides et activité récente
|
||||
- 🔍 **Recherche** : barre de recherche, tableau de paquets à gauche et détails à droite
|
||||
- 📦 **Installés** : liste avec **filtre instantané** par nom (local, sans relancer pacman)
|
||||
- ⬆️ **Mises à jour** : paquets obsolètes détectés par `pacman -Qu`, bouton « Tout mettre à jour »
|
||||
- ⬆️ **Mises à jour** : paquets obsolètes détectés par `pacman -Qu`, **recherche lancée dès l'arrivée sur l'onglet** (plus besoin d'appuyer sur « Tout mettre à jour » pour voir la liste), bouton « Tout mettre à jour »
|
||||
- 🧹 **Nettoyage** : paquets **orphelins** (`pacman -Qdt`, rien ne les requiert) et **legacy** (`pacman -Qm`, AUR / compilation manuelle), suppression groupée des orphelins, et purge des caches : `paccache` / `pacman -Sc` et runtimes Flatpak inutilisés (`flatpak uninstall --unused`)
|
||||
- 📋 **Historique** : tableau filtrable (installations / suppressions / mises à jour / nettoyages) + export CSV
|
||||
- 📜 **Logs** : journal `/var/log/pacman.log` intégré, avec filtre instantané
|
||||
|
||||
@@ -11,6 +11,11 @@ les widgets pour l'interface, le réseau pour l'auto-mise à jour et le magasin
|
||||
plugins. Rien d'autre n'est requis : les plugins Flatpak et AUR ne dépendent que
|
||||
des outils qu'ils pilotent (`flatpak`, `yay`/`paru`), eux-mêmes facultatifs.
|
||||
|
||||
Ces paquets ne sont pas obligatoirement installés à la main : quand une mise à
|
||||
jour de l'application doit recompiler et qu'il manque un de ces outils, elle les
|
||||
installe elle-même via `pacman` dès que le mot de passe sudo est saisi (voir
|
||||
[mise-a-jour.md](mise-a-jour.md)).
|
||||
|
||||
## Compiler
|
||||
|
||||
```bash
|
||||
|
||||
+34
-12
@@ -29,6 +29,25 @@ jour à proposer.
|
||||
| `lastCheckDate` | Date du dernier contrôle réussi : un seul appel réseau par jour. |
|
||||
| `latestRemoteVersion` | Dernière version vue sur le serveur, affichable même sans réseau. |
|
||||
|
||||
## Les dépendances de compilation
|
||||
|
||||
Les méthodes *Checkout*, *Clone* et *Tarball* recompilent l'application : elles
|
||||
ont besoin de **base-devel, cmake, gcc, git et qt6-base**. Plutôt que de les
|
||||
exiger à l'avance, la mise à jour les installe elle-même :
|
||||
|
||||
1. Le dialogue de mise à jour demande le mot de passe sudo dès que `pacman -T`
|
||||
signale un paquet manquant (en plus du cas « dossier cible non accessible en
|
||||
écriture ») — l'utilisateur voit **pourquoi** le mot de passe est demandé ;
|
||||
2. Le script de mise à jour commence par `pacman -T` puis
|
||||
`sudo pacman -S --needed --noconfirm` avec les paquets manquants ;
|
||||
3. La recompilation n'est tentée qu'ensuite.
|
||||
|
||||
Sur une machine complète, aucune étape de plus : `pacman -T` ne renvoie rien et
|
||||
le bloc est sauté. `pacman -T` n'est interrogé qu'une fois par lancement
|
||||
(`missingBuildDependencies()`), et le choix de méthode considère alors la
|
||||
machine comme « constructible » même sans cmake ni compilateur installés :
|
||||
``canInstallPackages`` suffit, puisque pacman peut combler le manque.
|
||||
|
||||
## Les quatre méthodes d'installation
|
||||
|
||||
Toutes installent **au même endroit : le dossier de l'exécutable en cours
|
||||
@@ -38,11 +57,11 @@ arborescence de build de la même façon.
|
||||
|
||||
| Méthode | Quand elle est choisie | Ce qui se passe |
|
||||
| --- | --- | --- |
|
||||
| **Checkout** | Un dépôt source entoure le binaire (cas du développeur) | `git pull`, recompilation, installation dans le dossier du binaire. |
|
||||
| **Clone** | Application installée sans dépôt, avec `git` + `cmake` + compilateur | Clone (puis `git pull`) dans `~/.local/share/PacManager/src`, compilation, installation en place. |
|
||||
| **Prebuilt** | Pas d'outillage de compilation, mais une archive précompilée attachée à la release | Téléchargement et décompression de `PacManager-<version>-x86_64.tar.gz`. |
|
||||
| **Tarball** | `git` absent mais `cmake` + compilateur présents | Compilation des sources de la release, puis installation en place. |
|
||||
| *Aucune* | Ni outillage, ni archive attachée | Le dialogue propose d'**ouvrir la page des releases** au lieu d'un bouton qui échouerait. |
|
||||
| **Checkout** | Un dépôt source entoure le binaire (cas du développeur) | Installe les déps manquantes, puis `git pull`, recompilation, installation dans le dossier du binaire. |
|
||||
| **Clone** | Application installée sans dépôt, avec `git` (ou pacman pour l'installer) | Installe les déps manquantes, clone (puis `git pull`) dans `~/.local/share/PacManager/src`, compilation, installation en place. |
|
||||
| **Prebuilt** | Pas d'outillage de compilation **et** pacman absent ou inutile, avec une archive précompilée attachée à la release | Téléchargement et décompression de `PacManager-<version>-x86_64.tar.gz`. |
|
||||
| **Tarball** | `git` absent mais un toolchain présent **ou installable via pacman** | Installe les déps manquantes, compilation des sources de la release, puis installation en place. |
|
||||
| *Aucune* | Ni outillage (réel ou installable), ni archive attachée | Le dialogue propose d'**ouvrir la page des releases** au lieu d'un bouton qui échouerait. |
|
||||
|
||||
Le choix est une **fonction pure** (`chooseUpdateMethod()` sur
|
||||
`UpdateCapabilities` : checkout utilisable, `git`, `cmake`, compilateur, archive
|
||||
@@ -53,9 +72,10 @@ précompilée, tarball), ce qui permet de le tester sans réseau ni outillage.
|
||||
1. Le contrôle de version (API Gitea) renvoie un tag plus récent.
|
||||
2. La fenêtre affiche un dialogue : version disponible, méthode qui sera utilisée
|
||||
et dossier cible (`methodDescription()`).
|
||||
3. `sudo` n'est demandé **que si le dossier cible n'est pas accessible en
|
||||
écriture** (`binDirWritable()`), c'est-à-dire typiquement pour `/usr/bin`. Tout
|
||||
le reste se compile dans un dossier temporaire appartenant à l'utilisateur.
|
||||
3. `sudo` est demandé quand le dossier cible n'est pas accessible en écriture
|
||||
(`binDirWritable()`), c'est-à-dire typiquement pour `/usr/bin`, **ou quand des
|
||||
dépendances de compilation manquent** — voir la section ci-dessus. Tout le
|
||||
reste se compile dans un dossier temporaire appartenant à l'utilisateur.
|
||||
4. La mise à jour tourne en arrière-plan ; le binaire en cours d'exécution n'est
|
||||
pas touché.
|
||||
5. À la fin, l'application **relance** le binaire fraîchement installé
|
||||
@@ -72,10 +92,11 @@ renomme** (`stagedInstallScript()`) : c'est ce qui permet d'écraser un binaire
|
||||
## Ce qui n'est jamais fait automatiquement
|
||||
|
||||
**Aucune archive précompilée n'est produite par le dépôt** : sans asset attaché à
|
||||
la release, ce sont les méthodes *Clone* ou *Tarball* qui s'appliquent, donc
|
||||
`git`, `cmake` et un compilateur doivent être présents sur la machine. Une
|
||||
installation minimale (binaire seul) se met donc à jour en recompilant, ou pas du
|
||||
tout — dans ce cas le dialogue ouvre la page des releases.
|
||||
la release, ce sont les méthodes *Clone* ou *Tarball* qui s'appliquent. Grâce à
|
||||
l'installation automatique des dépendances, il suffit d'avoir `pacman` (donc
|
||||
d'être sur Arch) et de fournir le mot de passe sudo — `git`, `cmake`, le
|
||||
compilateur et `qt6-base` sont installés par la mise à jour elle-même. Une
|
||||
installation hors Arch sans outillage ni archive ouvre la page des releases.
|
||||
|
||||
## Vérifier à la main
|
||||
|
||||
@@ -95,6 +116,7 @@ tout — dans ce cas le dialogue ouvre la page des releases.
|
||||
| La mise à jour annonce échouer alors que le binaire a changé | Écriture impossible sans droits : vérifier les droits du dossier du binaire, ou relancer en acceptant la demande `sudo`. |
|
||||
| L'application redémarre sur l'ancienne version | Le `version` voisin du binaire n'a pas pu être réécrit : sans lui, `newestVersion()` retombe sur la version compilée, souvent plus ancienne. Vérifier les droits du fichier. |
|
||||
| Recompilation interminable | Méthode *Clone*/*Tarball* : c'est le comportement attendu sans archive précompilée attachée à la release. |
|
||||
| « sudo: a password is required » dans le journal | La mise à jour a tourné sans mot de passe et le dossier cible (ou l'installation des déps) le demandait : relancer et saisir le mot de passe dans le dialogue. |
|
||||
|
||||
Voir aussi [installation.md](installation.md) pour les chemins concernés et
|
||||
[operations.md](operations.md) pour le rôle de `sudo` dans le reste de
|
||||
|
||||
@@ -121,6 +121,9 @@ public:
|
||||
// Full content of /var/log/pacman.log; `error` is filled when it cannot be
|
||||
// read (file missing, no permission).
|
||||
QString readPackageLog(QString* error = nullptr) const;
|
||||
// Full content of the application's own journal (every operation and event,
|
||||
// including the raw output of the commands that ran).
|
||||
QString readAppLog(QString* error = nullptr) const;
|
||||
// Extra pacman information for the details panel (-Qi / -Si), cached per
|
||||
// package so selecting rows repeatedly does not re-spawn pacman.
|
||||
QString packageDetails(const PackageInfo& package);
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
#pragma once
|
||||
|
||||
#include <QMutex>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
// The application's single, always-on journal: everything the app does ends up
|
||||
// in one plain-text file that the Logs screen displays and the user can grep
|
||||
// like a terminal history.
|
||||
//
|
||||
// Two kinds of entry share the file:
|
||||
//
|
||||
// - a *command* records what a provider is about to run and then every raw
|
||||
// line it prints, exactly what running the tool by hand would show:
|
||||
//
|
||||
// [2026-09-23 14:22:03] ── pacman · install ──────────────────────────
|
||||
// [2026-09-23 14:22:03] $ install linux-headers
|
||||
// [2026-09-23 14:22:04] :: Synchronizing package databases...
|
||||
// [2026-09-23 14:22:05] :: Received timestamp for linux-headers ...
|
||||
// ...
|
||||
// [2026-09-23 14:22:10] ⟶ terminé
|
||||
//
|
||||
// - an *event* is a one-line note about something that is not a shelled
|
||||
// command: navigation, a search, a plugin toggle, a network fetch, a refused
|
||||
// request...
|
||||
//
|
||||
// [2026-09-23 14:22:02] [ui] navigation → recherche
|
||||
// [2026-09-23 14:22:03] [recherche] "firefox" → 12 résultat(s)
|
||||
//
|
||||
// Every Qt log message (qCDebug/qCInfo/qCWarning/qCCritical) is funnelled into
|
||||
// the same journal by installQtMessageHandler(), so the categories already used
|
||||
// across the code base feed it without extra plumbing.
|
||||
//
|
||||
// The file lives in the user's own data tree (XDG_CONFIG_HOME / home) so it is
|
||||
// never lost when a sandbox is rebuilt. All methods are safe to call from any
|
||||
// thread.
|
||||
class LogManager : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
// Process-wide journal, created on first use (thread-safe).
|
||||
static LogManager& instance();
|
||||
|
||||
explicit LogManager(QObject* parent = nullptr);
|
||||
|
||||
// Records a one-line event. `category` is the short tag shown in brackets
|
||||
// (e.g. "ui", "recherche", "plugin", "erreur").
|
||||
void logEvent(const QString& category, const QString& message);
|
||||
|
||||
// Opens a command block: the provider(s) and action, plus a human-readable
|
||||
// form of the command about to run (may be empty).
|
||||
void beginCommand(const QString& provider, const QString& action,
|
||||
const QString& command = QString());
|
||||
|
||||
// Appends one raw output line of the running command.
|
||||
void appendOutput(const QString& line);
|
||||
|
||||
// Closes the current command block with its outcome. `error` carries the
|
||||
// failure detail when the command failed.
|
||||
void endCommand(bool success, const QString& error = QString());
|
||||
|
||||
// Full, plain text content of the journal (empty when nothing was written
|
||||
// yet). `error` is filled when the file cannot be read at all.
|
||||
QString readFile(QString* error = nullptr) const;
|
||||
|
||||
// True when the journal file already contains at least one entry.
|
||||
bool hasEntries() const;
|
||||
|
||||
// Path of the journal as written on disk (useful for debugging).
|
||||
QString filePath() const;
|
||||
|
||||
// Routes every Qt log message into the journal. Call once, after the
|
||||
// QApplication exists. Safe to call more than once.
|
||||
static void installQtMessageHandler();
|
||||
|
||||
signals:
|
||||
// The journal changed on disk and a fresh copy of its content is available.
|
||||
void fileUpdated();
|
||||
|
||||
private:
|
||||
// Appends `text` verbatim, opening the file lazily. Caller does not hold the
|
||||
// lock; this method takes it.
|
||||
void write(const QString& text);
|
||||
|
||||
QString m_filePath;
|
||||
FILE* m_file = nullptr;
|
||||
mutable QMutex m_mutex;
|
||||
};
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <QNetworkReply>
|
||||
#include <QDateTime>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QProcess>
|
||||
|
||||
// Checks the Gitea repository for new releases and tracks the last check
|
||||
@@ -19,6 +20,10 @@
|
||||
// into ~/.local/share/PacManager/src, built, and installed in place;
|
||||
// - Prebuilt: the release's prebuilt archive is unpacked (no compiler);
|
||||
// - Tarball: the release sources are built and installed in place.
|
||||
// The three rebuilding methods (Checkout, Clone, Tarball) first make sure the
|
||||
// build dependencies (base-devel, cmake, git, qt6-base) are installed: the
|
||||
// update script asks pacman what is missing and installs it through sudo, so
|
||||
// a minimal Arch system only needs its sudo password to self-update.
|
||||
// The running binary stays untouched (it keeps the inode that was replaced on
|
||||
// disk); the UI hands over to the freshly installed build by relaunching it.
|
||||
class UpdateManager : public QObject {
|
||||
@@ -95,6 +100,16 @@ public:
|
||||
enum class UpdateMethod { None, Checkout, Clone, Prebuilt, Tarball };
|
||||
UpdateMethod updateMethod() const;
|
||||
|
||||
// Packages needed to rebuild the app. base-devel pulls gcc, make and the
|
||||
// rest of the toolchain, git feeds the Clone method, and qt6-base provides
|
||||
// the Widgets + Network modules the build links against.
|
||||
static QStringList buildDependencies();
|
||||
|
||||
// Subset of buildDependencies() that pacman reports as missing (`pacman -T`,
|
||||
// exit code 127), cached for the process lifetime. Empty when everything is
|
||||
// installed, when pacman is absent (non-Arch system) or on Windows.
|
||||
static QStringList missingBuildDependencies();
|
||||
|
||||
// Inputs of the strategy decision, split out so the choice is a pure
|
||||
// function that can be unit-tested without a network, a filesystem or an
|
||||
// installed toolchain.
|
||||
@@ -105,6 +120,9 @@ public:
|
||||
bool hasCompiler = false;
|
||||
bool hasPrebuilt = false; // the release ships a prebuilt binary archive
|
||||
bool hasTarball = false; // the release ships a source tarball
|
||||
// pacman is available, so whatever build tool is missing can be
|
||||
// installed (with the user's sudo password) before rebuilding.
|
||||
bool canInstallPackages = false;
|
||||
};
|
||||
static UpdateMethod chooseUpdateMethod(const UpdateCapabilities& capabilities);
|
||||
|
||||
@@ -122,6 +140,14 @@ public:
|
||||
// binary.
|
||||
static QString stagedInstallScript();
|
||||
|
||||
// Shell snippet run at the start of every rebuilding method: installs the
|
||||
// build dependencies pacman reports as missing (`pacman -T`) through sudo,
|
||||
// piping the given (already shell-quoted) password to `sudo -S`. Without a
|
||||
// password, `sudo -n` keeps a passwordless-sudo setup working while a
|
||||
// password-requiring one fails fast instead of hanging the background run.
|
||||
// Exposed so the unit test can assert what the update would install.
|
||||
static QString dependencyInstallScript(const QString& quotedPassword);
|
||||
|
||||
// Whether a self-update is possible with the current state.
|
||||
bool canSelfUpdate() const;
|
||||
|
||||
|
||||
@@ -154,6 +154,10 @@ BrowsePage::BrowsePage(AppCore* core, QWidget* parent) : Page(core, parent) {
|
||||
m_table,
|
||||
"Aucun paquet à afficher.\nLancez une recherche ou ouvrez la liste des "
|
||||
"paquets installés.");
|
||||
// The "Tout mettre à jour" button only makes sense on the updates tab, but
|
||||
// there it must be usable without selecting a row first; the per-package
|
||||
// buttons stay gated on the selection.
|
||||
m_updateAllButton->setToolTip("Mettre à jour tous les paquets listés");
|
||||
listLayout->addWidget(m_tableStack);
|
||||
splitter->addWidget(listCard);
|
||||
|
||||
@@ -222,9 +226,24 @@ BrowsePage::BrowsePage(AppCore* core, QWidget* parent) : Page(core, parent) {
|
||||
m_installed = results;
|
||||
if (m_mode == Mode::Installed) onFilterChanged(m_filterBar->text());
|
||||
} else if (mode == AppCore::ListMode::Updates) {
|
||||
// The "searching" hint is replaced by the outcome: an empty
|
||||
// result means the system is up to date, not that the check
|
||||
// is still running.
|
||||
if (results.empty()) {
|
||||
ui::setEmptyStateText(
|
||||
m_tableStack,
|
||||
"Aucune mise à jour disponible.\nVotre système est à "
|
||||
"jour.");
|
||||
}
|
||||
if (m_mode == Mode::Updates) populateTable(results);
|
||||
}
|
||||
});
|
||||
connect(core, &AppCore::busyChanged, this, [this](bool busy) {
|
||||
// A listing started from elsewhere (dashboard) while the user was
|
||||
// already on the updates tab would leave it without data: reload now
|
||||
// that the core is free again.
|
||||
if (!busy && m_mode == Mode::Updates && isVisible()) reloadCurrentView();
|
||||
});
|
||||
connect(core, &AppCore::busyChanged, this, [this](bool busy) {
|
||||
m_progressBar->setVisible(busy);
|
||||
if (!busy) {
|
||||
@@ -298,6 +317,19 @@ void BrowsePage::showInstalled(const QString& select) {
|
||||
|
||||
void BrowsePage::showUpdates() {
|
||||
setMode(Mode::Updates);
|
||||
// The update check is what the user came for: run it on every arrival on
|
||||
// the tab (pacman caches its queries for a few seconds, so a click right
|
||||
// after the dashboard loaded reuses that answer instead of respawning it).
|
||||
// The "searching" hint replaces the empty-state text for the duration, so
|
||||
// the tab never looks stuck on an empty table.
|
||||
ui::setEmptyStateText(m_tableStack,
|
||||
"Recherche des mises à jour en cours...\nLes résultats "
|
||||
"s'afficheront automatiquement.");
|
||||
if (core()->busy()) {
|
||||
// Something else is loading (e.g. the dashboard asked for the counts):
|
||||
// the busyChanged handler below reloads when the core frees up.
|
||||
return;
|
||||
}
|
||||
start(core()->loadUpdates(), tr("Mises à jour"));
|
||||
}
|
||||
|
||||
@@ -307,6 +339,23 @@ void BrowsePage::setMode(Mode mode) {
|
||||
m_filterRow->setVisible(mode == Mode::Installed);
|
||||
m_installButton->setVisible(mode == Mode::Search);
|
||||
|
||||
// "Tout mettre à jour" acts on the whole list, so it is only offered on the
|
||||
// tab that displays pending updates; there it needs no row selection.
|
||||
if (m_updateAllButton) {
|
||||
m_updateAllButton->setVisible(mode == Mode::Updates);
|
||||
m_updateAllButton->setEnabled(mode == Mode::Updates
|
||||
&& core()->hasAvailableProvider());
|
||||
}
|
||||
|
||||
// The updates tab rewrote the empty-state hint for its own states; restore
|
||||
// the generic one so the other tabs never show a stale updates message.
|
||||
if (mode != Mode::Updates) {
|
||||
ui::setEmptyStateText(
|
||||
m_tableStack,
|
||||
"Aucun paquet à afficher.\nLancez une recherche ou ouvrez la liste des "
|
||||
"paquets installés.");
|
||||
}
|
||||
|
||||
// Clear any stale selection and reset the details panel
|
||||
m_table->clearSelection();
|
||||
resetDetails();
|
||||
|
||||
+30
-1
@@ -1,5 +1,6 @@
|
||||
#include "logs-page.h"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
@@ -7,6 +8,7 @@
|
||||
#include <QTextEdit>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "log-manager.h"
|
||||
#include "ui-kit.h"
|
||||
|
||||
LogsPage::LogsPage(AppCore* core, QWidget* parent) : Page(core, parent) {
|
||||
@@ -17,6 +19,14 @@ LogsPage::LogsPage(AppCore* core, QWidget* parent) : Page(core, parent) {
|
||||
QHBoxLayout* filterRow = new QHBoxLayout();
|
||||
filterRow->setSpacing(10);
|
||||
|
||||
m_source = new QComboBox();
|
||||
m_source->addItem(QStringLiteral("Journal de l'application"));
|
||||
m_source->addItem(QStringLiteral("Journal pacman (/var/log/pacman.log)"));
|
||||
m_source->setMinimumHeight(36);
|
||||
m_source->setToolTip("Choisir la source du journal affiché");
|
||||
connect(m_source, &QComboBox::currentIndexChanged, this, [this](int) { load(); });
|
||||
filterRow->addWidget(m_source);
|
||||
|
||||
m_filter = new QLineEdit();
|
||||
m_filter->setPlaceholderText("Filtrer les logs (paquet, action, date)...");
|
||||
m_filter->setMinimumHeight(36);
|
||||
@@ -45,6 +55,17 @@ LogsPage::LogsPage(AppCore* core, QWidget* parent) : Page(core, parent) {
|
||||
buttonBar->addWidget(refreshButton);
|
||||
|
||||
layout->addLayout(buttonBar);
|
||||
|
||||
// The journal grows while the app runs: reload it whenever a new entry lands,
|
||||
// but only while this page is actually showing it (so an install does not
|
||||
// reload the text on a screen the user is not looking at).
|
||||
connect(&LogManager::instance(), &LogManager::fileUpdated, this, [this] {
|
||||
if (viewingAppLog() && isVisible()) load();
|
||||
});
|
||||
}
|
||||
|
||||
bool LogsPage::viewingAppLog() const {
|
||||
return m_source->currentIndex() == 0;
|
||||
}
|
||||
|
||||
void LogsPage::refresh() {
|
||||
@@ -53,11 +74,19 @@ void LogsPage::refresh() {
|
||||
|
||||
void LogsPage::load() {
|
||||
QString error;
|
||||
m_raw = core()->readPackageLog(&error);
|
||||
m_raw = viewingAppLog() ? LogManager::instance().readFile(&error)
|
||||
: core()->readPackageLog(&error);
|
||||
|
||||
if (!error.isEmpty()) {
|
||||
m_text->setPlainText(error);
|
||||
return;
|
||||
}
|
||||
if (m_raw.isEmpty()) {
|
||||
m_text->setPlainText(viewingAppLog()
|
||||
? QStringLiteral("Journal vide : rien n'a encore été enregistré.")
|
||||
: QStringLiteral("Journal pacman vide ou illisible."));
|
||||
return;
|
||||
}
|
||||
applyFilter();
|
||||
}
|
||||
|
||||
|
||||
+11
-5
@@ -4,20 +4,23 @@
|
||||
|
||||
#include "page.h"
|
||||
|
||||
class QComboBox;
|
||||
class QLineEdit;
|
||||
class QTextEdit;
|
||||
|
||||
// Logs pacman: the raw /var/log/pacman.log, filtered in memory so typing stays
|
||||
// instant even with a multi-megabyte file (the core reads it, the page keeps a
|
||||
// copy).
|
||||
// Journal viewer. Two sources share the screen: the application's own journal —
|
||||
// every operation and event, including the raw output of the commands that ran,
|
||||
// so it reads like a hand-run terminal session — and the raw /var/log/pacman.log.
|
||||
// Both are filtered in memory so typing stays instant even with a multi-megabyte
|
||||
// file (the core/journal reads it, the page keeps a copy).
|
||||
class LogsPage : public Page {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LogsPage(AppCore* core, QWidget* parent = nullptr);
|
||||
|
||||
QString navTitle() const override { return QStringLiteral("Logs pacman"); }
|
||||
QString navTitle() const override { return QStringLiteral("Logs"); }
|
||||
QString navSubtitle() const override {
|
||||
return QStringLiteral("Journal brut du gestionnaire de paquets");
|
||||
return QStringLiteral("Journal de l'application et journal pacman");
|
||||
}
|
||||
|
||||
void refresh() override;
|
||||
@@ -25,7 +28,10 @@ public:
|
||||
private:
|
||||
void load();
|
||||
void applyFilter();
|
||||
// True when the selector points at the application's own journal.
|
||||
bool viewingAppLog() const;
|
||||
|
||||
QComboBox* m_source = nullptr;
|
||||
QLineEdit* m_filter = nullptr;
|
||||
QTextEdit* m_text = nullptr;
|
||||
QString m_raw;
|
||||
|
||||
@@ -103,6 +103,13 @@ void showEmptyState(QStackedWidget* stack, bool empty) {
|
||||
if (stack) stack->setCurrentIndex(empty ? 1 : 0);
|
||||
}
|
||||
|
||||
void setEmptyStateText(QStackedWidget* stack, const QString& hint) {
|
||||
if (!stack) return;
|
||||
// withEmptyState() puts the hint label second in the placeholder's layout:
|
||||
// the only label of the stack, so this stays a safe lookup.
|
||||
if (QLabel* label = stack->findChild<QLabel*>()) label->setText(hint);
|
||||
}
|
||||
|
||||
QLabel* countLabel() {
|
||||
QLabel* label = new QLabel();
|
||||
label->setStyleSheet("font-size: 12px; color: #64748b; font-weight: 600;");
|
||||
|
||||
@@ -41,6 +41,9 @@ QTableWidget* table(const QStringList& headers, bool allStretch = false);
|
||||
// so a screen with no result explains itself instead of showing a bare header.
|
||||
QStackedWidget* withEmptyState(QTableWidget* table, const QString& hint);
|
||||
void showEmptyState(QStackedWidget* stack, bool empty);
|
||||
// Rewrites the hint shown while the listing is empty, so a screen can walk the
|
||||
// user through its states ("searching..." then "nothing found").
|
||||
void setEmptyStateText(QStackedWidget* stack, const QString& hint);
|
||||
|
||||
// Small grey counter ("12 paquet(s)").
|
||||
QLabel* countLabel();
|
||||
|
||||
+129
-18
@@ -12,6 +12,7 @@
|
||||
#include <sstream>
|
||||
|
||||
#include "app-logging.h"
|
||||
#include "log-manager.h"
|
||||
#include "plugin-shop.h"
|
||||
#include "workers.h"
|
||||
|
||||
@@ -67,6 +68,10 @@ AppCore::StartResult accepted() {
|
||||
|
||||
AppCore::StartResult refused(const QString& error, bool needsPassword = false,
|
||||
bool locked = false) {
|
||||
// Every refusal is part of "what happened": the journal records it even when
|
||||
// the reason is routine (missing password, locked database, busy core).
|
||||
LogManager::instance().logEvent(QStringLiteral("refus"), error);
|
||||
|
||||
AppCore::StartResult result;
|
||||
result.error = error;
|
||||
result.needsPassword = needsPassword;
|
||||
@@ -74,6 +79,16 @@ AppCore::StartResult refused(const QString& error, bool needsPassword = false,
|
||||
return result;
|
||||
}
|
||||
|
||||
// "pacman + flatpak", for the journal header of an operation.
|
||||
QString providerLabel(const std::vector<IPackageManager*>& providers) {
|
||||
QStringList names;
|
||||
for (IPackageManager* pm : providers) {
|
||||
if (pm) names << QString::fromStdString(pm->getName());
|
||||
}
|
||||
return names.isEmpty() ? QStringLiteral("aucun")
|
||||
: names.join(QStringLiteral(" + "));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
AppCore::AppCore(QObject* parent) : QObject(parent) {
|
||||
@@ -126,6 +141,13 @@ AppCore::AppCore(QObject* parent) : QObject(parent) {
|
||||
qCInfo(pacmgrOp) << "core ready,"
|
||||
<< static_cast<int>(availableProviders().size())
|
||||
<< "provider(s) available";
|
||||
|
||||
LogManager::instance().logEvent(
|
||||
QStringLiteral("app"),
|
||||
QStringLiteral("PacManager %1 démarré — %2 gestionnaire(s) : %3")
|
||||
.arg(version())
|
||||
.arg(static_cast<int>(availableProviders().size()))
|
||||
.arg(providerLabel(availableProviders())));
|
||||
}
|
||||
|
||||
AppCore::~AppCore() {
|
||||
@@ -227,8 +249,14 @@ void AppCore::setCredentialMode(CredentialMode mode) {
|
||||
if (mode == CredentialMode::EachTime) {
|
||||
// Each operation must re-authenticate: never keep the password around.
|
||||
clearSudoPassword();
|
||||
LogManager::instance().logEvent(
|
||||
QStringLiteral("config"),
|
||||
QStringLiteral("identifiants sudo demandés à chaque opération"));
|
||||
emit statusMessage(QStringLiteral("Identifiants demandés à chaque opération."));
|
||||
} else {
|
||||
LogManager::instance().logEvent(
|
||||
QStringLiteral("config"),
|
||||
QStringLiteral("identifiants sudo demandés une fois par session"));
|
||||
emit statusMessage(QStringLiteral("Identifiants enregistrés pour la session."));
|
||||
}
|
||||
}
|
||||
@@ -305,17 +333,20 @@ AppCore::StartResult AppCore::startList(ListMode mode) {
|
||||
return accepted();
|
||||
}
|
||||
|
||||
QString listLabel;
|
||||
switch (mode) {
|
||||
case ListMode::Installed:
|
||||
emit statusMessage(QStringLiteral("Chargement des paquets installés..."));
|
||||
listLabel = QStringLiteral("Chargement des paquets installés...");
|
||||
break;
|
||||
case ListMode::Updates:
|
||||
emit statusMessage(QStringLiteral("Recherche des mises à jour..."));
|
||||
listLabel = QStringLiteral("Recherche des mises à jour...");
|
||||
break;
|
||||
case ListMode::Cleanup:
|
||||
emit statusMessage(QStringLiteral("Analyse des paquets inutilisés et legacy..."));
|
||||
listLabel = QStringLiteral("Analyse des paquets inutilisés et legacy...");
|
||||
break;
|
||||
}
|
||||
LogManager::instance().logEvent(QStringLiteral("liste"), listLabel);
|
||||
emit statusMessage(listLabel);
|
||||
|
||||
auto* worker = new ListWorker(availableProviders(),
|
||||
mode == ListMode::Installed ? ListWorker::Installed
|
||||
@@ -327,26 +358,30 @@ AppCore::StartResult AppCore::startList(ListMode mode) {
|
||||
[this, mode](std::vector<PackageInfo> results) {
|
||||
m_list = nullptr;
|
||||
|
||||
QString done;
|
||||
if (mode == ListMode::Installed) {
|
||||
m_installedPackages = results;
|
||||
emit statusMessage(QStringLiteral("%1 paquet(s) installé(s)")
|
||||
.arg(results.size()));
|
||||
done = QStringLiteral("%1 paquet(s) installé(s)")
|
||||
.arg(results.size());
|
||||
} else if (mode == ListMode::Updates) {
|
||||
m_updatePackages = results;
|
||||
emit statusMessage(QStringLiteral("%1 mise(s) à jour disponible(s)")
|
||||
.arg(results.size()));
|
||||
done = QStringLiteral("%1 mise(s) à jour disponible(s)")
|
||||
.arg(results.size());
|
||||
} else {
|
||||
m_cleanupCandidates = results;
|
||||
int orphans = 0;
|
||||
for (const auto& pkg : results) {
|
||||
if (pkg.orphan) ++orphans;
|
||||
}
|
||||
emit statusMessage(QStringLiteral("%1 orphelin(s) et %2 paquet(s) legacy "
|
||||
"détecté(s)")
|
||||
.arg(orphans)
|
||||
.arg(static_cast<int>(results.size()) - orphans));
|
||||
done = QStringLiteral("%1 orphelin(s) et %2 paquet(s) legacy "
|
||||
"détecté(s)")
|
||||
.arg(orphans)
|
||||
.arg(static_cast<int>(results.size()) - orphans);
|
||||
}
|
||||
|
||||
LogManager::instance().logEvent(QStringLiteral("liste"), done);
|
||||
emit statusMessage(done);
|
||||
|
||||
emit listFinished(mode, results);
|
||||
|
||||
if (!m_queuedLists.isEmpty()) {
|
||||
@@ -383,6 +418,9 @@ AppCore::StartResult AppCore::startSearch(const QString& query) {
|
||||
return refused(QStringLiteral("Aucun gestionnaire de paquets disponible sur ce système."));
|
||||
}
|
||||
|
||||
LogManager::instance().logEvent(
|
||||
QStringLiteral("recherche"),
|
||||
QStringLiteral("\"%1\" via %2").arg(query.trimmed(), providerLabel(providers)));
|
||||
emit statusMessage(QStringLiteral("Recherche en cours..."));
|
||||
|
||||
auto* worker = new SearchWorker(providers, query.trimmed().toStdString());
|
||||
@@ -392,7 +430,10 @@ AppCore::StartResult AppCore::startSearch(const QString& query) {
|
||||
connect(worker, &SearchWorker::finished, this,
|
||||
[this](std::vector<PackageInfo> results) {
|
||||
m_search = nullptr;
|
||||
emit statusMessage(QStringLiteral("%1 paquet(s) trouvé(s)").arg(results.size()));
|
||||
const QString done = QStringLiteral("%1 paquet(s) trouvé(s)")
|
||||
.arg(results.size());
|
||||
LogManager::instance().logEvent(QStringLiteral("recherche"), done);
|
||||
emit statusMessage(done);
|
||||
emit searchFinished(results);
|
||||
});
|
||||
disposeWorker(worker);
|
||||
@@ -471,12 +512,22 @@ AppCore::StartResult AppCore::releaseDatabaseLock() {
|
||||
setBusy(true);
|
||||
emit statusMessage(QStringLiteral("Libération de la base de données pacman..."));
|
||||
|
||||
LogManager::instance().beginCommand(
|
||||
QStringLiteral("pacman"), QStringLiteral("release-lock"),
|
||||
QString::fromStdString(PacmanManager::describeLockHolder(holder)));
|
||||
|
||||
auto* worker = new InstallWorker(m_pacman, holder);
|
||||
connect(worker, &InstallWorker::progress, this,
|
||||
[this](const QString& message) { emit statusMessage(message); });
|
||||
[this](const QString& message) {
|
||||
if (!message.isEmpty()) LogManager::instance().appendOutput(message);
|
||||
emit statusMessage(message);
|
||||
});
|
||||
connect(worker, &InstallWorker::finished, this, [this](bool released) {
|
||||
setBusy(false);
|
||||
if (!m_pacman) return;
|
||||
if (!m_pacman) {
|
||||
LogManager::instance().endCommand(released);
|
||||
return;
|
||||
}
|
||||
if (!released) {
|
||||
emit statusMessage(QStringLiteral("Base pacman toujours verrouillée"));
|
||||
// The core is only asked to free the lock when it is actually held:
|
||||
@@ -484,11 +535,14 @@ AppCore::StartResult AppCore::releaseDatabaseLock() {
|
||||
// Reported as a plain failure (not as another lock): the view
|
||||
// already went through its lock dialog once, offering it again
|
||||
// would loop.
|
||||
LogManager::instance().endCommand(
|
||||
false, QString::fromStdString(m_pacman->lastError()));
|
||||
emit actionFinished(QStringLiteral("release-lock"), QString(),
|
||||
false, QString::fromStdString(m_pacman->lastError()),
|
||||
/*locked=*/false);
|
||||
return;
|
||||
}
|
||||
LogManager::instance().endCommand(true);
|
||||
emit statusMessage(QStringLiteral("Base libérée, reprise de l'opération..."));
|
||||
// Deferred so the status message paints before the replayed action
|
||||
// starts streaming its own progress.
|
||||
@@ -610,6 +664,9 @@ AppCore::StartResult AppCore::startRequest(const Request& request) {
|
||||
|
||||
if (bulk) {
|
||||
m_removalSuccess = true;
|
||||
LogManager::instance().beginCommand(
|
||||
providerLabel(providers), QStringLiteral("cleanup"),
|
||||
request.description);
|
||||
startNextRemovalGroup();
|
||||
return accepted();
|
||||
}
|
||||
@@ -657,8 +714,21 @@ AppCore::StartResult AppCore::startAction(InstallWorker* worker, const Request&
|
||||
|
||||
qCInfo(pacmgrOp) << request.action << QString::fromStdString(request.package.name);
|
||||
|
||||
// Journal header: what is about to run, so the raw output that follows reads
|
||||
// like a hand-run command.
|
||||
const QString target = QString::fromStdString(request.package.name);
|
||||
LogManager::instance().beginCommand(
|
||||
providerLabel(providers), request.action,
|
||||
target.isEmpty() ? QString()
|
||||
: QStringLiteral("%1 %2").arg(request.action, target));
|
||||
|
||||
connect(worker, &InstallWorker::progress, this,
|
||||
[this](const QString& message) { emit actionProgress(message, -1); });
|
||||
[this](const QString& message) {
|
||||
// Every non-empty line is the provider's own output: it is exactly
|
||||
// what running the tool by hand would have printed.
|
||||
if (!message.isEmpty()) LogManager::instance().appendOutput(message);
|
||||
emit actionProgress(message, -1);
|
||||
});
|
||||
connect(worker, &InstallWorker::progressValue, this,
|
||||
[this](int percent) { emit actionProgress(QString(), percent); });
|
||||
connect(worker, &InstallWorker::finished, this,
|
||||
@@ -723,6 +793,7 @@ void AppCore::finishAction(const Request& request,
|
||||
emit pluginsChanged();
|
||||
}
|
||||
|
||||
LogManager::instance().endCommand(success, error);
|
||||
emit actionFinished(action, name, success, error, locked);
|
||||
}
|
||||
|
||||
@@ -795,6 +866,7 @@ void AppCore::clearCredentialsAfterUse() {
|
||||
|
||||
void AppCore::startNextRemovalGroup() {
|
||||
if (m_pendingRemovals.empty()) {
|
||||
LogManager::instance().endCommand(m_removalSuccess);
|
||||
m_removalSuccess = true;
|
||||
setBusy(false);
|
||||
clearCredentialsAfterUse();
|
||||
@@ -812,14 +884,20 @@ void AppCore::startNextRemovalGroup() {
|
||||
IPackageManager* provider = job.first;
|
||||
const std::vector<std::string> packages = job.second;
|
||||
|
||||
emit actionProgress(QStringLiteral("Suppression de %1 paquet(s)...")
|
||||
.arg(packages.size()), -1);
|
||||
const QString groupLabel = QStringLiteral("Suppression de %1 paquet(s) via %2...")
|
||||
.arg(packages.size())
|
||||
.arg(QString::fromStdString(provider->getName()));
|
||||
LogManager::instance().appendOutput(groupLabel);
|
||||
emit actionProgress(groupLabel, -1);
|
||||
|
||||
auto* worker = new InstallWorker(provider, InstallWorker::Op::RemovePackages, packages);
|
||||
m_action = worker;
|
||||
|
||||
connect(worker, &InstallWorker::progress, this,
|
||||
[this](const QString& message) { emit actionProgress(message, -1); });
|
||||
[this](const QString& message) {
|
||||
if (!message.isEmpty()) LogManager::instance().appendOutput(message);
|
||||
emit actionProgress(message, -1);
|
||||
});
|
||||
connect(worker, &InstallWorker::progressValue, this,
|
||||
[this](int percent) { emit actionProgress(QString(), percent); });
|
||||
connect(worker, &InstallWorker::finished, this,
|
||||
@@ -856,6 +934,7 @@ void AppCore::startNextRemovalGroup() {
|
||||
const QString error = QString::fromStdString(provider->lastError());
|
||||
const bool locked = (m_pacman && m_pacman->lastErrorWasLock())
|
||||
|| PacmanManager::dbLocked(provider->lastError());
|
||||
LogManager::instance().endCommand(false, error);
|
||||
emit statusMessage(QStringLiteral("Échec du nettoyage"));
|
||||
emit actionFinished(QStringLiteral("cleanup"), m_cleanupRemovalDescription,
|
||||
false, error, locked);
|
||||
@@ -893,12 +972,19 @@ void AppCore::cancelPendingRequest() {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void AppCore::setPluginEnabled(const std::string& pluginId, bool enabled) {
|
||||
LogManager::instance().logEvent(
|
||||
QStringLiteral("plugin"),
|
||||
QStringLiteral("%1 %2")
|
||||
.arg(QString::fromStdString(pluginId),
|
||||
enabled ? QStringLiteral("activé") : QStringLiteral("désactivé")));
|
||||
m_plugins->setEnabled(pluginId, enabled);
|
||||
refreshProviderCache();
|
||||
emit pluginsChanged();
|
||||
}
|
||||
|
||||
void AppCore::reloadPlugins() {
|
||||
LogManager::instance().logEvent(QStringLiteral("plugin"),
|
||||
QStringLiteral("registre rechargé"));
|
||||
m_plugins->reload();
|
||||
refreshProviderCache();
|
||||
emit pluginsChanged();
|
||||
@@ -906,20 +992,30 @@ void AppCore::reloadPlugins() {
|
||||
}
|
||||
|
||||
void AppCore::loadPluginCatalog() {
|
||||
LogManager::instance().logEvent(QStringLiteral("plugin"),
|
||||
QStringLiteral("chargement du catalogue"));
|
||||
emit statusMessage(QStringLiteral("Chargement du catalogue de plugins..."));
|
||||
m_shop->refresh();
|
||||
}
|
||||
|
||||
void AppCore::installShopPlugin(const QString& id) {
|
||||
LogManager::instance().logEvent(
|
||||
QStringLiteral("plugin"),
|
||||
QStringLiteral("installation depuis la boutique : %1").arg(id));
|
||||
emit statusMessage(QStringLiteral("Téléchargement du plugin %1...").arg(id));
|
||||
m_shop->install(id);
|
||||
}
|
||||
|
||||
void AppCore::removeShopPlugin(const QString& id) {
|
||||
LogManager::instance().logEvent(
|
||||
QStringLiteral("plugin"),
|
||||
QStringLiteral("suppression depuis la boutique : %1").arg(id));
|
||||
m_shop->remove(id);
|
||||
}
|
||||
|
||||
void AppCore::clearHistory() {
|
||||
LogManager::instance().logEvent(QStringLiteral("historique"),
|
||||
QStringLiteral("effacé"));
|
||||
m_history->clear();
|
||||
emit historyChanged();
|
||||
emit statusMessage(QStringLiteral("Historique effacé"));
|
||||
@@ -933,6 +1029,7 @@ QString AppCore::readPackageLog(QString* error) const {
|
||||
"Vérifiez que le fichier existe et que vous avez les "
|
||||
"droits de lecture.")
|
||||
.arg(QString::fromUtf8(kPacmanLogPath));
|
||||
LogManager::instance().logEvent(QStringLiteral("erreur"), *error);
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
@@ -940,6 +1037,10 @@ QString AppCore::readPackageLog(QString* error) const {
|
||||
return QString::fromUtf8(logFile.readAll());
|
||||
}
|
||||
|
||||
QString AppCore::readAppLog(QString* error) const {
|
||||
return LogManager::instance().readFile(error);
|
||||
}
|
||||
|
||||
QString AppCore::packageDetails(const PackageInfo& pkg) {
|
||||
if (!m_pacman || !m_pacman->isAvailable()) return QString();
|
||||
|
||||
@@ -953,6 +1054,12 @@ QString AppCore::packageDetails(const PackageInfo& pkg) {
|
||||
const auto cached = m_detailsCache.constFind(key);
|
||||
if (cached != m_detailsCache.constEnd()) return cached.value();
|
||||
|
||||
LogManager::instance().logEvent(
|
||||
QStringLiteral("détails"),
|
||||
QStringLiteral("interrogation de %1 (%2)")
|
||||
.arg(QString::fromStdString(pkg.name),
|
||||
QString::fromStdString(pkg.provider)));
|
||||
|
||||
const bool isPacmanPkg = pkg.provider == "pacman" || pkg.provider.empty();
|
||||
const std::string queryInstalled = pkg.provider == "aur" ? "yay -Qi " : "pacman -Qi ";
|
||||
const std::string querySync = pkg.provider == "aur" ? "yay -Si " : "pacman -Si ";
|
||||
@@ -999,6 +1106,8 @@ bool AppCore::shouldCheckForAppUpdate() const {
|
||||
}
|
||||
|
||||
void AppCore::checkForAppUpdate() {
|
||||
LogManager::instance().logEvent(QStringLiteral("maj-app"),
|
||||
QStringLiteral("vérification de version"));
|
||||
emit statusMessage(QStringLiteral("Vérification des mises à jour..."));
|
||||
m_update->checkForUpdates();
|
||||
}
|
||||
@@ -1035,6 +1144,8 @@ bool AppCore::applySelfUpdate(const QString& sudoPassword, QString* error) {
|
||||
return false;
|
||||
}
|
||||
if (error) error->clear();
|
||||
LogManager::instance().logEvent(QStringLiteral("maj-app"),
|
||||
QStringLiteral("mise à jour appliquée"));
|
||||
m_update->performSelfUpdate(sudoPassword);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
#include "log-manager.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QLoggingCategory>
|
||||
#include <QStandardPaths>
|
||||
#include <QStringBuilder>
|
||||
#include <QStringList>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
namespace {
|
||||
|
||||
// Where the plain text history of what the app did lives on any desktop
|
||||
// session, inside the user's own data tree (so a Flatpak-sandboxed build still
|
||||
// finds it in ~/.local/share).
|
||||
QString logDirectory() {
|
||||
const QString dir = QStandardPaths::writableLocation(
|
||||
QStandardPaths::AppConfigLocation);
|
||||
if (!dir.isEmpty()) {
|
||||
QDir(dir).mkpath(".");
|
||||
return dir;
|
||||
}
|
||||
return QDir::homePath() + QStringLiteral("/.config/PacManager");
|
||||
}
|
||||
|
||||
QString currentTimestamp() {
|
||||
return QDateTime::currentDateTime().toString(
|
||||
QStringLiteral("yyyy-MM-dd hh:mm:ss"));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
LogManager& LogManager::instance() {
|
||||
// Function-local static: created once, thread-safe since C++11.
|
||||
static LogManager manager;
|
||||
return manager;
|
||||
}
|
||||
|
||||
LogManager::LogManager(QObject* parent) : QObject(parent) {
|
||||
m_filePath = logDirectory() + QStringLiteral("/") + QStringLiteral("operations.log");
|
||||
}
|
||||
|
||||
QString LogManager::filePath() const {
|
||||
return m_filePath;
|
||||
}
|
||||
|
||||
void LogManager::write(const QString& text) {
|
||||
QMutexLocker lock(&m_mutex);
|
||||
|
||||
// Append mode, opened lazily and kept open: a long session keeps growing and
|
||||
// the file is never truncated while the app runs.
|
||||
if (!m_file) {
|
||||
m_file = std::fopen(QFile::encodeName(m_filePath).constData(), "a");
|
||||
if (!m_file) return;
|
||||
}
|
||||
|
||||
const QByteArray bytes = text.toUtf8();
|
||||
std::fputs(bytes.constData(), m_file);
|
||||
// Flushed line by line so the journal survives a crash: the last thing the
|
||||
// app did is exactly what the user wants to read after one.
|
||||
std::fflush(m_file);
|
||||
}
|
||||
|
||||
void LogManager::logEvent(const QString& category, const QString& message) {
|
||||
if (message.isEmpty()) return;
|
||||
|
||||
// A Qt log message may carry several lines; flatten them so every journal
|
||||
// entry stays one physical line.
|
||||
QString flat = message;
|
||||
flat.replace(QLatin1Char('\n'), QStringLiteral(" "));
|
||||
flat.replace(QLatin1Char('\r'), QString());
|
||||
|
||||
write(QStringLiteral("[%1] [%2] %3\n").arg(currentTimestamp(), category, flat));
|
||||
emit fileUpdated();
|
||||
}
|
||||
|
||||
void LogManager::beginCommand(const QString& provider, const QString& action,
|
||||
const QString& command) {
|
||||
const QString stamp = currentTimestamp();
|
||||
QString text = QStringLiteral("[%1] ── %2 · %3 ")
|
||||
.arg(stamp, provider, action);
|
||||
// A rule long enough to separate two operations at a glance.
|
||||
int rule = 46 - static_cast<int>(action.size()) - static_cast<int>(provider.size());
|
||||
if (rule < 3) rule = 3;
|
||||
text += QStringLiteral("─").repeated(rule);
|
||||
text += QLatin1Char('\n');
|
||||
|
||||
if (!command.isEmpty()) {
|
||||
text += QStringLiteral("[%1] $ %2\n").arg(stamp, command);
|
||||
}
|
||||
|
||||
write(text);
|
||||
emit fileUpdated();
|
||||
}
|
||||
|
||||
void LogManager::appendOutput(const QString& line) {
|
||||
if (line.trimmed().isEmpty()) return;
|
||||
// No timestamp on output lines: this is the tool's own text, replayed as it
|
||||
// would appear in a terminal, and timestamps on every line would drown it.
|
||||
write(QStringLiteral(" %1\n").arg(line));
|
||||
}
|
||||
|
||||
void LogManager::endCommand(bool success, const QString& error) {
|
||||
QString text = QStringLiteral("[%1] %2\n")
|
||||
.arg(currentTimestamp(),
|
||||
success ? QStringLiteral("⟶ terminé")
|
||||
: QStringLiteral("⟶ échec"));
|
||||
|
||||
if (!error.isEmpty()) {
|
||||
const QStringList lines = error.split(QLatin1Char('\n'));
|
||||
for (const QString& line : lines) {
|
||||
if (line.trimmed().isEmpty()) continue;
|
||||
text += QStringLiteral(" %1\n").arg(line);
|
||||
}
|
||||
}
|
||||
|
||||
write(text);
|
||||
emit fileUpdated();
|
||||
}
|
||||
|
||||
QString LogManager::readFile(QString* error) const {
|
||||
QMutexLocker lock(&m_mutex);
|
||||
|
||||
if (!QFile::exists(m_filePath)) {
|
||||
if (error) error->clear();
|
||||
return QString();
|
||||
}
|
||||
|
||||
QFile file(m_filePath);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
if (error) {
|
||||
*error = QStringLiteral("Impossible d'ouvrir %1.").arg(m_filePath);
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
if (error) error->clear();
|
||||
|
||||
// Read the file in chunks to avoid loading a very large journal into memory
|
||||
// at once; the file grows with session usage.
|
||||
constexpr int bufferSize = 8192;
|
||||
QByteArray chunk;
|
||||
chunk.resize(bufferSize);
|
||||
QString result;
|
||||
while (!file.atEnd()) {
|
||||
const qint64 read = file.read(chunk.data(), bufferSize);
|
||||
if (read > 0) {
|
||||
result += QString::fromUtf8(chunk, static_cast<int>(read));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool LogManager::hasEntries() const {
|
||||
return !readFile().isEmpty();
|
||||
}
|
||||
|
||||
void LogManager::installQtMessageHandler() {
|
||||
// Make sure the singleton is created on the calling (main) thread before any
|
||||
// worker emits a log message.
|
||||
instance();
|
||||
|
||||
qInstallMessageHandler([](QtMsgType type, const QMessageLogContext& context,
|
||||
const QString& message) {
|
||||
// Keep the usual console output too, so a developer still sees the logs
|
||||
// in a terminal.
|
||||
const char* category = context.category ? context.category : "default";
|
||||
std::fprintf(stderr, "[%s] %s\n", category, message.toLocal8Bit().constData());
|
||||
|
||||
QString level;
|
||||
switch (type) {
|
||||
case QtDebugMsg: level = QStringLiteral("debug"); break;
|
||||
case QtInfoMsg: level = QStringLiteral("info"); break;
|
||||
case QtWarningMsg: level = QStringLiteral("avertissement"); break;
|
||||
case QtCriticalMsg: level = QStringLiteral("critique"); break;
|
||||
case QtFatalMsg: level = QStringLiteral("fatal"); break;
|
||||
}
|
||||
|
||||
LogManager::instance().logEvent(
|
||||
QStringLiteral("qt/%1").arg(QString::fromLatin1(category)),
|
||||
QStringLiteral("%1: %2").arg(level, message));
|
||||
|
||||
if (type == QtFatalMsg) std::abort();
|
||||
});
|
||||
}
|
||||
+83
-7
@@ -28,6 +28,7 @@
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "app-logging.h"
|
||||
#include "log-manager.h"
|
||||
#include "browse-page.h"
|
||||
#include "cleanup-page.h"
|
||||
#include "dashboard-page.h"
|
||||
@@ -660,9 +661,13 @@ void MainWindow::setupMenuBar() {
|
||||
|
||||
QMenu* fileMenu = menuBar->addMenu("Fichier");
|
||||
fileMenu->addAction("Exporter la liste affichée...", this, [this] {
|
||||
LogManager::instance().logEvent(QStringLiteral("ui"),
|
||||
QStringLiteral("export de la liste affichée"));
|
||||
m_browse->exportCsv();
|
||||
});
|
||||
fileMenu->addAction("Exporter l'historique...", this, [this] {
|
||||
LogManager::instance().logEvent(QStringLiteral("ui"),
|
||||
QStringLiteral("export de l'historique"));
|
||||
m_history->exportCsv();
|
||||
});
|
||||
fileMenu->addSeparator();
|
||||
@@ -770,7 +775,11 @@ void MainWindow::setupShortcuts() {
|
||||
bind(QKeySequence(QStringLiteral("Ctrl+U")), [this]() {
|
||||
m_navGroup->button(NavUpdates)->click();
|
||||
});
|
||||
bind(QKeySequence(QStringLiteral("Ctrl+E")), [this]() { m_browse->exportCsv(); });
|
||||
bind(QKeySequence(QStringLiteral("Ctrl+E")), [this]() {
|
||||
LogManager::instance().logEvent(QStringLiteral("ui"),
|
||||
QStringLiteral("export de la liste affichée"));
|
||||
m_browse->exportCsv();
|
||||
});
|
||||
bind(QKeySequence::Quit, [this]() { close(); });
|
||||
}
|
||||
|
||||
@@ -781,6 +790,23 @@ void MainWindow::setupShortcuts() {
|
||||
void MainWindow::onNavChanged(int id) {
|
||||
qCDebug(pacmgrUi) << "navigate to page" << id;
|
||||
|
||||
QString pageName;
|
||||
switch (id) {
|
||||
case NavDashboard: pageName = QStringLiteral("tableau de bord"); break;
|
||||
case NavSearch: pageName = QStringLiteral("recherche"); break;
|
||||
case NavInstalled: pageName = QStringLiteral("installés"); break;
|
||||
case NavUpdates: pageName = QStringLiteral("mises à jour"); break;
|
||||
case NavCleanup: pageName = QStringLiteral("nettoyage"); break;
|
||||
case NavHistory: pageName = QStringLiteral("historique"); break;
|
||||
case NavLogs: pageName = QStringLiteral("logs"); break;
|
||||
case NavPlugins: pageName = QStringLiteral("plugins"); break;
|
||||
default: break;
|
||||
}
|
||||
LogManager::instance().logEvent(
|
||||
QStringLiteral("ui"),
|
||||
pageName.isEmpty() ? QStringLiteral("navigation → page %1").arg(id)
|
||||
: QStringLiteral("navigation → %1").arg(pageName));
|
||||
|
||||
switch (id) {
|
||||
case NavDashboard:
|
||||
m_pages->setCurrentWidget(m_dashboard);
|
||||
@@ -832,6 +858,9 @@ void MainWindow::onOpenPage(const QString& pageId) {
|
||||
void MainWindow::onOpenPackage(const QString& name) {
|
||||
if (name.isEmpty()) return;
|
||||
|
||||
LogManager::instance().logEvent(
|
||||
QStringLiteral("ui"),
|
||||
QStringLiteral("ouverture des détails de %1").arg(name));
|
||||
m_browse->selectOnNextLoad(name);
|
||||
if (QAbstractButton* button = m_navGroup->button(NavInstalled)) button->click();
|
||||
statusBar()->showMessage(QString("Ouverture des détails de %1...").arg(name));
|
||||
@@ -846,10 +875,14 @@ void MainWindow::onStartRequested(const AppCore::StartResult& result, const QStr
|
||||
}
|
||||
|
||||
void MainWindow::onRefresh() {
|
||||
LogManager::instance().logEvent(QStringLiteral("ui"),
|
||||
QStringLiteral("clic rafraîchir les sources"));
|
||||
handleStartResult(m_core->refresh(), "Rafraîchissement des sources");
|
||||
}
|
||||
|
||||
void MainWindow::onUpdateAll() {
|
||||
LogManager::instance().logEvent(QStringLiteral("ui"),
|
||||
QStringLiteral("clic tout mettre à jour"));
|
||||
handleStartResult(m_core->updateAll(), "Mise à jour globale");
|
||||
}
|
||||
|
||||
@@ -868,6 +901,11 @@ void MainWindow::onTrayActivated(QSystemTrayIcon::ActivationReason reason) {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void MainWindow::applyCredentialMode(AppCore::CredentialMode mode) {
|
||||
LogManager::instance().logEvent(
|
||||
QStringLiteral("ui"),
|
||||
QStringLiteral("mode d'identifiants → %1")
|
||||
.arg(mode == AppCore::CredentialMode::AtLaunch ? QStringLiteral("au lancement")
|
||||
: QStringLiteral("à chaque fois")));
|
||||
m_core->setCredentialMode(mode);
|
||||
// Per-session credentials: prompt once now so operations don't re-ask. The
|
||||
// core reports the mode change in the status bar itself.
|
||||
@@ -879,21 +917,34 @@ void MainWindow::applyCredentialMode(AppCore::CredentialMode mode) {
|
||||
bool MainWindow::promptForSudoPassword() {
|
||||
if (m_core->hasSudoPassword()) return true;
|
||||
|
||||
LogManager::instance().logEvent(
|
||||
QStringLiteral("ui"),
|
||||
QStringLiteral("demande du mot de passe administrateur"));
|
||||
|
||||
bool ok = false;
|
||||
const QString password = QInputDialog::getText(
|
||||
this, "Authentification",
|
||||
"Mot de passe administrateur (sudo) :",
|
||||
QLineEdit::Password, QString(), &ok);
|
||||
if (!ok) {
|
||||
LogManager::instance().logEvent(
|
||||
QStringLiteral("ui"),
|
||||
QStringLiteral("mot de passe refusé par l'utilisateur"));
|
||||
statusBar()->showMessage("Opération annulée : identifiants requis.");
|
||||
return false;
|
||||
}
|
||||
|
||||
LogManager::instance().logEvent(QStringLiteral("ui"),
|
||||
QStringLiteral("mot de passe fourni"));
|
||||
m_core->setSudoPassword(password);
|
||||
return true;
|
||||
}
|
||||
|
||||
void MainWindow::showActionError(const QString& title, const QString& error, bool locked) {
|
||||
LogManager::instance().logEvent(
|
||||
QStringLiteral("erreur"),
|
||||
QStringLiteral("%1 : %2").arg(title, error.isEmpty() ? QStringLiteral("sans détail") : error));
|
||||
|
||||
// A locked database is the one failure the app can resolve on its own, so it
|
||||
// gets its own dialog instead of a message the user has to act on by hand.
|
||||
if (locked) {
|
||||
@@ -930,6 +981,10 @@ void MainWindow::handleStartResult(const AppCore::StartResult& result,
|
||||
}
|
||||
|
||||
void MainWindow::handleDatabaseLock(const QString& title) {
|
||||
LogManager::instance().logEvent(
|
||||
QStringLiteral("verrou"),
|
||||
QStringLiteral("%1 : %2").arg(title, m_core->databaseLockDescription()));
|
||||
|
||||
// The other manager frequently finishes while the failed operation was
|
||||
// unwinding: retry straight away rather than announcing a lock that is gone.
|
||||
if (!m_core->databaseLocked()) {
|
||||
@@ -1095,6 +1150,8 @@ void MainWindow::onCoreHistoryChanged() {
|
||||
}
|
||||
|
||||
void MainWindow::onCheckForUpdates() {
|
||||
LogManager::instance().logEvent(QStringLiteral("ui"),
|
||||
QStringLiteral("clic vérifier les mises à jour"));
|
||||
m_core->checkForAppUpdate();
|
||||
}
|
||||
|
||||
@@ -1149,21 +1206,40 @@ void MainWindow::onCoreUpdateCheckFinished(bool hasUpdate, const QString& latest
|
||||
return;
|
||||
}
|
||||
|
||||
// Prompt for the sudo password only when the update must write into a
|
||||
// root-owned directory (e.g. /usr/bin). Every method installs into the
|
||||
// running binary's directory, and only that final copy is privileged:
|
||||
// everything else builds in a temp directory owned by the user.
|
||||
// Prompt for the sudo password when the update needs privileges: either the
|
||||
// final install writes into a root-owned directory (e.g. /usr/bin), or the
|
||||
// build dependencies (qt6-base, cmake, gcc/base-devel, git) are missing and
|
||||
// the update script must install them first — on a minimal Arch system both
|
||||
// are why the update cannot run unprivileged. The password is consumed by
|
||||
// `sudo -S` inside the update script itself (install of the dependencies,
|
||||
// then the final copy).
|
||||
QString sudoPassword;
|
||||
if (!m_core->binDirWritable()) {
|
||||
const bool needsDeps = !UpdateManager::missingBuildDependencies().isEmpty();
|
||||
if (!m_core->binDirWritable() || needsDeps) {
|
||||
QString reason;
|
||||
if (needsDeps) {
|
||||
reason = QStringLiteral(
|
||||
"Des dépendances de compilation manquent (%1).\n")
|
||||
.arg(UpdateManager::missingBuildDependencies().join(", "));
|
||||
} else {
|
||||
reason = QStringLiteral("L'installation doit écrire dans %1.\n").arg(targetDir);
|
||||
}
|
||||
bool ok = false;
|
||||
sudoPassword = QInputDialog::getText(
|
||||
this, "Mise à jour",
|
||||
QString("Mot de passe sudo pour installer dans %1 :").arg(targetDir),
|
||||
QString("%1Mot de passe sudo pour mettre à jour PacManager :\n")
|
||||
.arg(reason),
|
||||
QLineEdit::Password, QString(), &ok);
|
||||
if (!ok) {
|
||||
statusBar()->showMessage("Mise à jour annulée.");
|
||||
return;
|
||||
}
|
||||
if (!sudoPassword.isEmpty()) {
|
||||
// The update pipeline also serves the other privileged flows, and
|
||||
// it drops the password after each use: priming it here avoids a
|
||||
// second prompt when the update itself was started from one.
|
||||
m_core->setSudoPassword(sudoPassword);
|
||||
}
|
||||
}
|
||||
|
||||
qCInfo(pacmgrUpdate) << "applying update, method" << static_cast<int>(method)
|
||||
|
||||
+17
-1
@@ -1,4 +1,7 @@
|
||||
#include <QApplication>
|
||||
#include <QLoggingCategory>
|
||||
|
||||
#include "log-manager.h"
|
||||
#include "main-window.h"
|
||||
#include "update-manager.h"
|
||||
|
||||
@@ -8,11 +11,24 @@ int main(int argc, char* argv[]) {
|
||||
app.setApplicationVersion(UpdateManager::currentVersion());
|
||||
app.setOrganizationName("Freebuff");
|
||||
|
||||
// Every log category the app uses is enabled (qCDebug included) and funnelled
|
||||
// into the journal, so the Logs screen shows the same detail as a debug run
|
||||
// without the user having to set QT_LOGGING_RULES.
|
||||
QLoggingCategory::setFilterRules(QStringLiteral("pacmgr.*=true"));
|
||||
LogManager::installQtMessageHandler();
|
||||
LogManager::instance().logEvent(
|
||||
QStringLiteral("app"),
|
||||
QStringLiteral("session démarrée (v%1)").arg(UpdateManager::currentVersion()));
|
||||
|
||||
MainWindow window;
|
||||
window.setWindowTitle("PacManager - Gestionnaire de Paquets");
|
||||
window.resize(1200, 760);
|
||||
window.setMinimumSize(960, 600);
|
||||
window.show();
|
||||
|
||||
return app.exec();
|
||||
const int code = app.exec();
|
||||
|
||||
LogManager::instance().logEvent(QStringLiteral("app"),
|
||||
QStringLiteral("session terminée (code %1)").arg(code));
|
||||
return code;
|
||||
}
|
||||
+83
-7
@@ -119,6 +119,50 @@ QString UpdateManager::releasePageUrl() const {
|
||||
return m_releasePageUrl;
|
||||
}
|
||||
|
||||
// Packages required to rebuild the app. base-devel is the Arch metapackage
|
||||
// pulling the whole toolchain (gcc, make, sudo…), git feeds the Clone method
|
||||
// and qt6-base provides the Widgets + Network modules the build links against.
|
||||
// cmake ships in base-devel on current Arch but is listed explicitly so a
|
||||
// stripped-down system still gets it.
|
||||
QStringList UpdateManager::buildDependencies() {
|
||||
return {QStringLiteral("base-devel"), QStringLiteral("cmake"),
|
||||
QStringLiteral("gcc"), QStringLiteral("git"),
|
||||
QStringLiteral("qt6-base")};
|
||||
}
|
||||
|
||||
// `pacman -T` answers "which of these packages is NOT installed" (exit 127 with
|
||||
// the missing names on stdout), the exact question the update asks. The result
|
||||
// is cached for the process lifetime: a package does not vanish between the
|
||||
// dialog and the update, and the check spawns one pacman per call.
|
||||
QStringList UpdateManager::missingBuildDependencies() {
|
||||
static QStringList cached;
|
||||
static bool fetched = false;
|
||||
if (fetched) return cached;
|
||||
fetched = true;
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
return cached;
|
||||
#else
|
||||
if (QProcess::execute("/bin/sh", {"-c", "command -v pacman >/dev/null 2>&1"}) != 0) {
|
||||
return cached; // not an Arch system: nothing to install, and the
|
||||
// rebuild methods will fail on their own if attempted
|
||||
}
|
||||
|
||||
QProcess pacman;
|
||||
QStringList args{QStringLiteral("-T")};
|
||||
args += buildDependencies();
|
||||
pacman.start("pacman", args);
|
||||
if (!pacman.waitForFinished(15000)) return cached;
|
||||
// simplified() collapses newlines and runs of spaces into single spaces:
|
||||
// pacman -T prints the missing targets whitespace-separated, and splitting
|
||||
// the raw output would keep line breaks inside the tokens.
|
||||
cached = QString::fromUtf8(pacman.readAllStandardOutput())
|
||||
.simplified()
|
||||
.split(QLatin1Char(' '), Qt::SkipEmptyParts);
|
||||
return cached;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Cached `command -v` lookup. The update dialog queries several tools on
|
||||
// every check; caching keeps that from spawning a shell per query.
|
||||
bool UpdateManager::toolAvailable(const char* tool) {
|
||||
@@ -186,25 +230,33 @@ UpdateManager::UpdateMethod UpdateManager::updateMethod() const {
|
||||
capabilities.hasCompiler = compilerAvailable();
|
||||
capabilities.hasPrebuilt = !m_prebuiltUrl.isEmpty();
|
||||
capabilities.hasTarball = !m_tarballUrl.isEmpty();
|
||||
// pacman present = every missing build tool can be installed first, which
|
||||
// makes the Clone/Tarball methods reachable on a minimal Arch system.
|
||||
capabilities.canInstallPackages = toolAvailable("pacman");
|
||||
return chooseUpdateMethod(capabilities);
|
||||
}
|
||||
|
||||
// Strategy, in order of preference:
|
||||
// 1. Checkout: a source checkout is the developer's tree, pull + rebuild it;
|
||||
// 2. Clone: rebuild from the real sources (git + cmake + compiler present),
|
||||
// so an installed app follows the repo whatever its location;
|
||||
// 3. Prebuilt: no toolchain, unpack the release's binary archive;
|
||||
// 4. Tarball: no git but a compiler, build the release sources.
|
||||
// 2. Clone: rebuild from the real sources (git + cmake + compiler present, or
|
||||
// installable through pacman first), so an installed app follows the repo
|
||||
// whatever its location;
|
||||
// 3. Prebuilt: no toolchain and pacman cannot fill the gap, unpack the
|
||||
// release's binary archive;
|
||||
// 4. Tarball: no git but a buildable toolchain, build the release sources.
|
||||
// Anything else cannot update locally and falls back to the releases page.
|
||||
UpdateManager::UpdateMethod UpdateManager::chooseUpdateMethod(
|
||||
const UpdateCapabilities& capabilities) {
|
||||
if (capabilities.checkoutUsable) return UpdateMethod::Checkout;
|
||||
if (capabilities.hasGit && capabilities.hasCmake && capabilities.hasCompiler) {
|
||||
const bool buildable = capabilities.hasCmake && capabilities.hasCompiler;
|
||||
// pacman present = every missing build tool can be installed first, which
|
||||
// makes the rebuilding methods reachable on a minimal Arch system.
|
||||
const bool buildableWithPacman = capabilities.canInstallPackages;
|
||||
if (capabilities.hasGit && (buildable || buildableWithPacman)) {
|
||||
return UpdateMethod::Clone;
|
||||
}
|
||||
if (capabilities.hasPrebuilt) return UpdateMethod::Prebuilt;
|
||||
if (capabilities.hasTarball && capabilities.hasCmake
|
||||
&& capabilities.hasCompiler) {
|
||||
if (capabilities.hasTarball && (buildable || buildableWithPacman)) {
|
||||
return UpdateMethod::Tarball;
|
||||
}
|
||||
return UpdateMethod::None;
|
||||
@@ -392,6 +444,27 @@ bool UpdateManager::isNewerVersion(const QString& remote, const QString& local)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Shell snippet shared by every rebuilding method: asks pacman which of the
|
||||
// build dependencies are missing (`pacman -T`, exit 127) and installs them
|
||||
// through `pacman -S --needed --noconfirm`. --needed skips what is already
|
||||
// installed, --noconfirm keeps the unattended update from blocking on a
|
||||
// pacman prompt. With a password it is piped to `sudo -S`; without one, `-n`
|
||||
// keeps a passwordless-sudo setup working while a password-requiring sudo
|
||||
// fails fast instead of hanging the background run on an unanswerable prompt.
|
||||
// On a fully equipped machine the whole block is skipped.
|
||||
QString UpdateManager::dependencyInstallScript(const QString& quotedPassword) {
|
||||
const QString sudoPrefix = quotedPassword.isEmpty()
|
||||
? QStringLiteral("sudo -n")
|
||||
: QStringLiteral("printf '%s\\n' %1 | sudo -S").arg(quotedPassword);
|
||||
return QStringLiteral(
|
||||
"MISSING=$(pacman -T %1 2>/dev/null || true)\n"
|
||||
"if [ -n \"$MISSING\" ]; then\n"
|
||||
" echo \"Installation des dependances de compilation : $MISSING\"\n"
|
||||
" %2 pacman -S --needed --noconfirm $MISSING 2>&1\n"
|
||||
"fi\n")
|
||||
.arg(buildDependencies().join(QLatin1Char(' ')), sudoPrefix);
|
||||
}
|
||||
|
||||
// Rebuilds + reinstalls the app in the background, using the strategy picked
|
||||
// by updateMethod(). The running process is untouched (it keeps the replaced
|
||||
// inode); the caller relaunches into the new build. Exits non-zero on failure
|
||||
@@ -427,6 +500,7 @@ void UpdateManager::performSelfUpdate(const QString& sudoPassword) {
|
||||
// leave the copy in use (and its version marker) untouched.
|
||||
void UpdateManager::performCheckoutUpdate(const QString& sudoPassword) {
|
||||
QString script = updateScriptPrologue();
|
||||
script += dependencyInstallScript(quotedPassword(sudoPassword));
|
||||
script += QStringLiteral(
|
||||
"git pull --ff-only origin main 2>&1 || git pull --ff-only 2>&1\n"
|
||||
"if [ -d build ]; then\n"
|
||||
@@ -542,6 +616,7 @@ QString UpdateManager::quotedPassword(const QString& sudoPassword) {
|
||||
// running binary lives.
|
||||
void UpdateManager::performCloneUpdate(const QString& sudoPassword) {
|
||||
QString script = updateScriptPrologue();
|
||||
script += dependencyInstallScript(quotedPassword(sudoPassword));
|
||||
script += QStringLiteral(
|
||||
"SRC=%1\n"
|
||||
"export SRC\n"
|
||||
@@ -593,6 +668,7 @@ void UpdateManager::performPrebuiltUpdate(const QString& sudoPassword) {
|
||||
// result where the running binary lives. Used only when git is unavailable.
|
||||
void UpdateManager::performTarballUpdate(const QString& sudoPassword) {
|
||||
QString script = updateScriptPrologue();
|
||||
script += dependencyInstallScript(quotedPassword(sudoPassword));
|
||||
script += QStringLiteral(
|
||||
"command -v cmake >/dev/null 2>&1 || { echo 'cmake est requis pour la mise a jour'; exit 1; }\n"
|
||||
"URL=%1\n"
|
||||
|
||||
@@ -119,6 +119,79 @@ static void testChooseMethod_noneWhenNothingAvailable() {
|
||||
"method_none_without_anything");
|
||||
}
|
||||
|
||||
// pacman can install whatever build tool is missing, so a minimal Arch system
|
||||
// (no cmake, no compiler, not even git) still reaches the rebuilding methods:
|
||||
// the update script installs the dependencies first, with the sudo password the
|
||||
// user typed in the update dialog.
|
||||
static void testChooseMethod_pacmanUnlocksClone() {
|
||||
Caps caps;
|
||||
caps.canInstallPackages = true; // nothing else installed
|
||||
caps.hasGit = true; // git is the only tool the clone path
|
||||
// strictly needs up front (deps install
|
||||
// brings cmake + the compiler)
|
||||
check(UpdateManager::chooseUpdateMethod(caps) == Method::Clone,
|
||||
"method_clone_with_pacman_only");
|
||||
}
|
||||
|
||||
static void testChooseMethod_pacmanWithoutGit_stillTarball() {
|
||||
Caps caps;
|
||||
caps.canInstallPackages = true;
|
||||
caps.hasTarball = true; // no git: the tarball path also needs no tool now
|
||||
check(UpdateManager::chooseUpdateMethod(caps) == Method::Tarball,
|
||||
"method_tarball_with_pacman_only");
|
||||
}
|
||||
|
||||
// Without pacman there is no way to fill a missing toolchain: the prebuilt
|
||||
// archive (when the release ships one) stays the only option.
|
||||
static void testChooseMethod_noPacman_prebuiltStillFallback() {
|
||||
Caps caps;
|
||||
caps.hasGit = true; // git alone cannot build, and pacman cannot fix it
|
||||
caps.hasPrebuilt = true;
|
||||
check(UpdateManager::chooseUpdateMethod(caps) == Method::Prebuilt,
|
||||
"method_prebuilt_without_pacman");
|
||||
}
|
||||
|
||||
// The dependency list and its `pacman -T` probe are pure data/IO: the list is
|
||||
// asserted literally so a rename cannot silently break the install script, and
|
||||
// the missing-dependency lookup must agree with pacman itself (empty on this
|
||||
// machine means "nothing to install", not "unknown").
|
||||
static void testBuildDependencies() {
|
||||
const QStringList deps = UpdateManager::buildDependencies();
|
||||
check(deps.contains("base-devel"), "deps_base_devel");
|
||||
check(deps.contains("cmake"), "deps_cmake");
|
||||
check(deps.contains("gcc"), "deps_gcc");
|
||||
check(deps.contains("qt6-base"), "deps_qt6_base");
|
||||
check(deps.contains("git"), "deps_git");
|
||||
|
||||
// On a machine without pacman this is empty and the update simply keeps
|
||||
// its current behaviour; with pacman it must never report an installed
|
||||
// package as missing.
|
||||
const QStringList missing = UpdateManager::missingBuildDependencies();
|
||||
for (const QString& pkg : missing) {
|
||||
check(deps.contains(pkg), "missing_dependency_is_from_the_list");
|
||||
}
|
||||
}
|
||||
|
||||
// The generated snippet must install exactly what pacman -T reports, through
|
||||
// sudo (with the password piped to -S), and skip everything on a complete
|
||||
// system. Quoted here is the password safety: the quoting is the same as the
|
||||
// one used for the install step.
|
||||
static void testDependencyInstallScript() {
|
||||
const QString script = UpdateManager::dependencyInstallScript("'secret'");
|
||||
check(script.contains("pacman -T"), "script_asks_pacman_what_is_missing");
|
||||
check(script.contains("base-devel"), "script_installs_base_devel");
|
||||
check(script.contains("qt6-base"), "script_installs_qt6_base");
|
||||
check(script.contains("--needed --noconfirm"), "script_pacman_flags");
|
||||
check(script.contains("| sudo -S"), "script_pipes_password_to_sudo");
|
||||
check(script.contains("'secret'"), "script_uses_the_given_password");
|
||||
|
||||
// No password: sudo -n fails fast on a password-requiring setup instead of
|
||||
// hanging the background update on an unanswerable prompt.
|
||||
const QString passwordless = UpdateManager::dependencyInstallScript(QString());
|
||||
check(passwordless.contains("sudo -n"), "script_passwordless_uses_sudo_n");
|
||||
check(!passwordless.contains("sudo -S"), "script_passwordless_has_no_pipe");
|
||||
}
|
||||
|
||||
// Reconciliation of the two sources of truth: whichever is ahead wins, an empty
|
||||
// side never does. This is what stops a release from being offered again when the
|
||||
// binary and the installed marker disagree.
|
||||
@@ -327,6 +400,11 @@ int main() {
|
||||
testChooseMethod_tarballWithoutGit();
|
||||
testChooseMethod_tarballRequiresCompiler();
|
||||
testChooseMethod_noneWhenNothingAvailable();
|
||||
testChooseMethod_pacmanUnlocksClone();
|
||||
testChooseMethod_pacmanWithoutGit_stillTarball();
|
||||
testChooseMethod_noPacman_prebuiltStillFallback();
|
||||
testBuildDependencies();
|
||||
testDependencyInstallScript();
|
||||
|
||||
#if !defined(Q_OS_WIN)
|
||||
testStagedInstall_replacesRunningExecutable();
|
||||
|
||||
Reference in new issue
Block a user