fix: Autoupdater

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

View File

@@ -5,60 +5,36 @@
#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 {
class UpdaterDialog : public QDialog {
Q_OBJECT Q_OBJECT
public: public:
explicit UpdaterDialog(QWidget* parent = nullptr); explicit UpdaterDialog(QWidget* parent = nullptr);
~UpdaterDialog() override; ~UpdaterDialog() override;
// Check for updates using the given URL
void CheckForUpdates(const std::string& update_url); void CheckForUpdates(const std::string& update_url);
// Show update available dialog private slots:
void ShowUpdateAvailable(const Updater::UpdateInfo& update_info); void OnUpdateCheckCompleted(bool has_update, const UpdateInfo& update_info);
// Show update checking dialog
void ShowUpdateChecking();
private slots:
void OnUpdateCheckCompleted(bool has_update, const Updater::UpdateInfo& update_info);
void OnUpdateDownloadProgress(int percentage, qint64 bytes_received, qint64 bytes_total); void OnUpdateDownloadProgress(int percentage, qint64 bytes_received, qint64 bytes_total);
void OnUpdateInstallProgress(int percentage, const QString& current_file); void OnUpdateInstallProgress(int percentage, const QString& current_file);
#ifdef _WIN32
void OnUpdateCompleted(Updater::UpdaterService::UpdateResult result, const QString& message); void OnUpdateCompleted(Updater::UpdaterService::UpdateResult result, const QString& message);
#else
void OnUpdateCompleted(int result, const QString& message);
#endif
void OnUpdateError(const QString& error_message); void OnUpdateError(const QString& error_message);
void OnDownloadButtonClicked(); void OnDownloadButtonClicked();
void OnCancelButtonClicked(); void OnCancelButtonClicked();
void OnCloseButtonClicked(); void OnCloseButtonClicked();
void OnRestartButtonClicked(); void OnRestartButtonClicked();
private: private:
void SetupUI(); void SetupUI();
void ShowCheckingState(); void ShowCheckingState();
void ShowNoUpdateState(); void ShowNoUpdateState();
@@ -67,25 +43,11 @@ private:
void ShowInstallingState(); void ShowInstallingState();
void ShowCompletedState(); void ShowCompletedState();
void ShowErrorState(); void ShowErrorState();
void UpdateDownloadProgress(int percentage, qint64 bytes_received, qint64 bytes_total); void UpdateDownloadProgress(int percentage, qint64 bytes_received, qint64 bytes_total);
void UpdateInstallProgress(int percentage, const QString& current_file); void UpdateInstallProgress(int percentage, const QString& current_file);
QString FormatBytes(qint64 bytes) const; QString FormatBytes(qint64 bytes) const;
#ifdef _WIN32
QString GetUpdateMessage(Updater::UpdaterService::UpdateResult result) const; 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 { enum class State {
Checking, Checking,
NoUpdate, NoUpdate,
@@ -95,11 +57,14 @@ private:
Completed, Completed,
Error Error
}; };
State current_state = State::Checking;
// Progress tracking std::unique_ptr<Ui::UpdaterDialog> ui;
qint64 total_download_size = 0; std::unique_ptr<Updater::UpdaterService> updater_service;
qint64 downloaded_bytes = 0; UpdateInfo current_update_info;
State current_state;
qint64 total_download_size;
qint64 downloaded_bytes;
QTimer* progress_timer; QTimer* progress_timer;
#endif // _WIN32 };
};
} // namespace Updater