fix: Autoupdater

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

View File

@@ -5,27 +5,15 @@
#include <memory>
#include <QDialog>
#include <QProgressBar>
#include <QLabel>
#include <QPushButton>
#include <QTextBrowser>
#include <QTimer>
#ifdef _WIN32
#include "citron/updater/updater_service.h"
#else
// Forward declarations for non-Windows platforms
namespace Updater {
struct UpdateInfo;
class UpdaterService;
}
#endif
namespace Ui {
class UpdaterDialog;
}
namespace Updater {
class UpdaterDialog : public QDialog {
Q_OBJECT
@@ -33,26 +21,14 @@ public:
explicit UpdaterDialog(QWidget* parent = nullptr);
~UpdaterDialog() override;
// Check for updates using the given URL
void CheckForUpdates(const std::string& update_url);
// Show update available dialog
void ShowUpdateAvailable(const Updater::UpdateInfo& update_info);
// Show update checking dialog
void ShowUpdateChecking();
private slots:
void OnUpdateCheckCompleted(bool has_update, const Updater::UpdateInfo& update_info);
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);
#ifdef _WIN32
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 OnDownloadButtonClicked();
void OnCancelButtonClicked();
void OnCloseButtonClicked();
@@ -67,25 +43,11 @@ private:
void ShowInstallingState();
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,
@@ -95,11 +57,14 @@ private:
Completed,
Error
};
State current_state = State::Checking;
// Progress tracking
qint64 total_download_size = 0;
qint64 downloaded_bytes = 0;
std::unique_ptr<Ui::UpdaterDialog> ui;
std::unique_ptr<Updater::UpdaterService> updater_service;
UpdateInfo current_update_info;
State current_state;
qint64 total_download_size;
qint64 downloaded_bytes;
QTimer* progress_timer;
#endif // _WIN32
};
} // namespace Updater