feat(update): add self-update check via Gitea releases API
tests / build-test (push) Has been cancelled

Adds an UpdateManager that queries the Gitea releases API once per day,
stores the last check state in a JSON file, and offers to pull + rebuild
the source repository when a newer version exists. The running binary is
left untouched until the next launch.

Also sets the app version from the version file at build time instead of
the hardcoded 1.0.0, and copies the version file next to the executable.
This commit is contained in:
BlackAngelTV committed 2026-09-09 19:49:45 +02:00
1 parent 9b357cde63
commit 44a7e5b396
6 files changed
+424 -6

No files matched your search

+6
View File
@@ -18,6 +18,7 @@
#include "pacman-manager.h"
#include "plugin-manager.h"
#include "history-manager.h"
#include "update-manager.h"
class QStackedWidget;
class QTableWidget;
@@ -110,6 +111,10 @@ private slots:
void onToggleProvider();
void onRescanProviders();
void onInstallProviderTool();
void onCheckForUpdates();
void onUpdateCheckFinished(bool hasUpdate, const QString& latestVersion,
const QString& errorMessage);
void onSelfUpdateFinished(bool success, const QString& message);
private:
enum BrowseMode { ModeSearch, ModeInstalled, ModeUpdates };
@@ -224,6 +229,7 @@ private:
PacmanManager* m_pacman = nullptr; // non-owning, used for sudo credentials/logs
PluginManager* m_pluginManager = nullptr; // owns every provider
HistoryManager* m_historyManager = nullptr;
UpdateManager* m_updateManager = nullptr; // checks Gitea releases (owned)
BrowseMode m_browseMode = ModeSearch;
// Settings
+73
View File
@@ -0,0 +1,73 @@
#pragma once
#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QDateTime>
#include <QString>
#include <QProcess>
// Checks the Gitea repository for new releases and tracks the last check
// state in a JSON file so the app only queries the API once per day.
// When the user accepts, the app updates itself by pulling + rebuilding
// the source repository in the background; the running binary stays
// untouched until the next launch.
class UpdateManager : public QObject {
Q_OBJECT
public:
explicit UpdateManager(QObject* parent = nullptr);
// Current app version, read from the version file at build time.
static QString currentVersion();
// Path of the state file storing the last check date and the latest
// known remote version (e.g. ~/.local/share/PacManager/update-state.json).
static QString stateFilePath();
// True when the last check happened less than 24h ago, so we can skip
// the network call at launch.
bool shouldCheck() const;
// Latest remote version recorded in the state file (empty if never checked).
QString lastKnownRemoteVersion() const;
// Fetches the latest release from the Gitea API. Emits checkFinished.
void checkForUpdates();
// True when the remote version is newer than the local one.
static bool isNewerVersion(const QString& remote, const QString& local);
// Path of the source repository, or empty when the app is installed
// without the repo (e.g. ~/.local/bin). Used for self-update.
QString repoPath() const;
// Whether the source repository is present so a self-update is possible.
bool canSelfUpdate() const;
// Pulls the latest code from the remote and rebuilds the app in the
// background. The current running binary is left untouched; the new
// version takes effect at the next launch. Emits selfUpdateFinished.
void performSelfUpdate();
signals:
// Emitted after a check completes. hasUpdate is true when a newer
// release exists; errorMessage is non-empty when the request failed.
void checkFinished(bool hasUpdate, const QString& latestVersion,
const QString& errorMessage);
// Emitted when the background self-update completes. success is true
// if the pull + build produced a fresh executable.
void selfUpdateFinished(bool success, const QString& message);
private:
void saveState(const QString& remoteVersion);
void loadState();
void runShell(const QString& script, const QString& workingDir);
QNetworkAccessManager m_network;
QProcess m_process; // runs the git pull + build script
QString m_lastCheckDate; // ISO date of the last successful check
QString m_lastKnownRemoteVersion; // latest version seen on the server
QString m_latestVersion; // version of the pending update
QString m_repoPath; // source repo dir when found
};