fix: Autoupdater

This commit is contained in:
collecting
2025-10-24 10:38:02 +00:00
parent 5628d07b9c
commit d5f1589341

View File

@@ -5,101 +5,66 @@
#include <memory> #include <memory>
#include <QDialog> #include <QDialog>
#include <QProgressBar>
#include <QLabel>
#include <QPushButton>
#include <QTextBrowser>
#include <QTimer> #include <QTimer>
#ifdef _WIN32
#include "citron/updater/updater_service.h" #include "citron/updater/updater_service.h"
#else
// Forward declarations for non-Windows platforms
namespace Updater {
struct UpdateInfo;
class UpdaterService;
}
#endif
namespace Ui { namespace Ui {
class UpdaterDialog; class UpdaterDialog;
} }
class UpdaterDialog : public QDialog { namespace Updater {
Q_OBJECT
public: class UpdaterDialog : public QDialog {
explicit UpdaterDialog(QWidget* parent = nullptr); Q_OBJECT
~UpdaterDialog() override;
// Check for updates using the given URL public:
void CheckForUpdates(const std::string& update_url); explicit UpdaterDialog(QWidget* parent = nullptr);
~UpdaterDialog() override;
// Show update available dialog void CheckForUpdates(const std::string& update_url);
void ShowUpdateAvailable(const Updater::UpdateInfo& update_info);
// Show update checking dialog private slots:
void ShowUpdateChecking(); void OnUpdateCheckCompleted(bool has_update, const UpdateInfo& update_info);
void OnUpdateDownloadProgress(int percentage, qint64 bytes_received, qint64 bytes_total);
void OnUpdateInstallProgress(int percentage, const QString& current_file);
void OnUpdateCompleted(Updater::UpdaterService::UpdateResult result, const QString& message);
void OnUpdateError(const QString& error_message);
void OnDownloadButtonClicked();
void OnCancelButtonClicked();
void OnCloseButtonClicked();
void OnRestartButtonClicked();
private slots: private:
void OnUpdateCheckCompleted(bool has_update, const Updater::UpdateInfo& update_info); void SetupUI();
void OnUpdateDownloadProgress(int percentage, qint64 bytes_received, qint64 bytes_total); void ShowCheckingState();
void OnUpdateInstallProgress(int percentage, const QString& current_file); void ShowNoUpdateState();
#ifdef _WIN32 void ShowUpdateAvailableState();
void OnUpdateCompleted(Updater::UpdaterService::UpdateResult result, const QString& message); void ShowDownloadingState();
#else void ShowInstallingState();
void OnUpdateCompleted(int result, const QString& message); void ShowCompletedState();
#endif void ShowErrorState();
void OnUpdateError(const QString& error_message); void UpdateDownloadProgress(int percentage, qint64 bytes_received, qint64 bytes_total);
void UpdateInstallProgress(int percentage, const QString& current_file);
QString FormatBytes(qint64 bytes) const;
QString GetUpdateMessage(Updater::UpdaterService::UpdateResult result) const;
void OnDownloadButtonClicked(); enum class State {
void OnCancelButtonClicked(); Checking,
void OnCloseButtonClicked(); NoUpdate,
void OnRestartButtonClicked(); UpdateAvailable,
Downloading,
Installing,
Completed,
Error
};
private: std::unique_ptr<Ui::UpdaterDialog> ui;
void SetupUI(); std::unique_ptr<Updater::UpdaterService> updater_service;
void ShowCheckingState(); UpdateInfo current_update_info;
void ShowNoUpdateState(); State current_state;
void ShowUpdateAvailableState(); qint64 total_download_size;
void ShowDownloadingState(); qint64 downloaded_bytes;
void ShowInstallingState(); QTimer* progress_timer;
void ShowCompletedState();
void ShowErrorState();
void UpdateDownloadProgress(int percentage, qint64 bytes_received, qint64 bytes_total);
void UpdateInstallProgress(int percentage, const QString& current_file);
QString FormatBytes(qint64 bytes) const;
#ifdef _WIN32
QString GetUpdateMessage(Updater::UpdaterService::UpdateResult result) const;
#else
QString GetUpdateMessage(int result) const;
#endif
private:
#ifdef _WIN32
std::unique_ptr<Ui::UpdaterDialog> ui;
std::unique_ptr<Updater::UpdaterService> updater_service;
Updater::UpdateInfo current_update_info;
// UI state
enum class State {
Checking,
NoUpdate,
UpdateAvailable,
Downloading,
Installing,
Completed,
Error
}; };
State current_state = State::Checking;
// Progress tracking } // namespace Updater
qint64 total_download_size = 0;
qint64 downloaded_bytes = 0;
QTimer* progress_timer;
#endif // _WIN32
};