feat(update): add self-update check via Gitea releases API
tests / build-test (push) Has been cancelled
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:
6 files changed
+424
-6
No files matched your search
+93
-3
@@ -188,6 +188,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) {
|
||||
m_pacman = dynamic_cast<PacmanManager*>(m_pluginManager->managerFor("pacman"));
|
||||
|
||||
m_historyManager = new HistoryManager();
|
||||
m_updateManager = new UpdateManager(this);
|
||||
|
||||
setupUI();
|
||||
setupMenuBar();
|
||||
@@ -214,11 +215,18 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) {
|
||||
|
||||
refreshDashboard();
|
||||
updateStatusBar();
|
||||
|
||||
// Check for app updates once per day (or on first launch). The delay lets
|
||||
// the window appear first so the status bar message is visible.
|
||||
if (m_updateManager->shouldCheck()) {
|
||||
QTimer::singleShot(1500, this, &MainWindow::onCheckForUpdates);
|
||||
}
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
delete m_pluginManager; // owns every provider, built-in and external
|
||||
delete m_historyManager;
|
||||
delete m_updateManager;
|
||||
}
|
||||
|
||||
void MainWindow::setupUI() {
|
||||
@@ -1050,11 +1058,13 @@ void MainWindow::setupMenuBar() {
|
||||
[this]() { applyCredentialMode(CredentialMode::AtLaunch); });
|
||||
|
||||
QMenu* helpMenu = menuBar->addMenu("Aide");
|
||||
helpMenu->addAction("Vérifier les mises à jour", this, &MainWindow::onCheckForUpdates);
|
||||
helpMenu->addSeparator();
|
||||
helpMenu->addAction("À propos", [this]() {
|
||||
QMessageBox::about(this, "PacManager",
|
||||
"<h2>PacManager v1.0.0</h2>"
|
||||
"<p>Gestionnaire de paquets pour Arch Linux (pacman).</p>"
|
||||
);
|
||||
QString("<h2>PacManager v%1</h2>"
|
||||
"<p>Gestionnaire de paquets pour Arch Linux (pacman).</p>")
|
||||
.arg(UpdateManager::currentVersion()));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2087,3 +2097,83 @@ void MainWindow::refreshProvidersTable() {
|
||||
m_providerDescription->clear();
|
||||
}
|
||||
}
|
||||
|
||||
// Starts an update check against the Gitea releases API. Used both at launch
|
||||
// (once per day) and from the Aide menu.
|
||||
void MainWindow::onCheckForUpdates() {
|
||||
statusBar()->showMessage("Vérification des mises à jour...");
|
||||
connect(m_updateManager, &UpdateManager::checkFinished,
|
||||
this, &MainWindow::onUpdateCheckFinished);
|
||||
m_updateManager->checkForUpdates();
|
||||
}
|
||||
|
||||
// Handles the result of a release check: offers to self-update when a newer
|
||||
// version exists, otherwise a status bar confirmation. Errors are reported
|
||||
// silently in the status bar so a network failure never blocks the app.
|
||||
void MainWindow::onUpdateCheckFinished(bool hasUpdate, const QString& latestVersion,
|
||||
const QString& errorMessage) {
|
||||
disconnect(m_updateManager, &UpdateManager::checkFinished,
|
||||
this, &MainWindow::onUpdateCheckFinished);
|
||||
|
||||
if (!errorMessage.isEmpty()) {
|
||||
statusBar()->showMessage(errorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hasUpdate) {
|
||||
statusBar()->showMessage(
|
||||
QString("PacManager est à jour (v%1)").arg(UpdateManager::currentVersion()));
|
||||
return;
|
||||
}
|
||||
|
||||
// Ask the user whether to update now or skip. When the source repo is
|
||||
// available the update runs in the background (git pull + build); the
|
||||
// running binary stays untouched until the next launch.
|
||||
QMessageBox box(this);
|
||||
box.setWindowTitle("Mise à jour disponible");
|
||||
box.setIcon(QMessageBox::Information);
|
||||
box.setTextFormat(Qt::RichText);
|
||||
box.setText(QString("<h3>PacManager v%1 est disponible</h3>"
|
||||
"<p>Vous utilisez actuellement la version %2.</p>")
|
||||
.arg(latestVersion, UpdateManager::currentVersion()));
|
||||
|
||||
QPushButton* updateBtn = box.addButton("Mettre à jour", QMessageBox::AcceptRole);
|
||||
QPushButton* skipBtn = box.addButton("Plus tard", QMessageBox::RejectRole);
|
||||
|
||||
if (!m_updateManager->canSelfUpdate()) {
|
||||
// No source checkout: only point to the releases page.
|
||||
box.setInformativeText(
|
||||
"Le dépôt source n'est pas disponible sur ce système.\n"
|
||||
"Téléchargez la nouvelle version depuis la page des releases.");
|
||||
updateBtn->setEnabled(false);
|
||||
}
|
||||
|
||||
box.exec();
|
||||
|
||||
if (box.clickedButton() == updateBtn) {
|
||||
statusBar()->showMessage("Mise à jour en cours en arrière-plan...");
|
||||
connect(m_updateManager, &UpdateManager::selfUpdateFinished,
|
||||
this, &MainWindow::onSelfUpdateFinished);
|
||||
m_updateManager->performSelfUpdate();
|
||||
}
|
||||
// "Plus tard" (or closing the dialog) simply skips the update.
|
||||
}
|
||||
|
||||
// Called when the background git pull + build finishes. Reports the result in
|
||||
// a dialog so the user knows whether to restart the app.
|
||||
void MainWindow::onSelfUpdateFinished(bool success, const QString& message) {
|
||||
disconnect(m_updateManager, &UpdateManager::selfUpdateFinished,
|
||||
this, &MainWindow::onSelfUpdateFinished);
|
||||
|
||||
if (success) {
|
||||
QMessageBox::information(this, "Mise à jour terminée",
|
||||
QString("<h3>PacManager a été mis à jour</h3>"
|
||||
"<p>La nouvelle version sera active au prochain démarrage.</p>"
|
||||
"<pre>%1</pre>")
|
||||
.arg(message.toHtmlEscaped()));
|
||||
} else {
|
||||
QMessageBox::warning(this, "Échec de la mise à jour",
|
||||
QString("<p>La mise à jour a échoué :</p><pre>%1</pre>")
|
||||
.arg(message.toHtmlEscaped()));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user