Check for client updates on startup (#5359)

This commit is contained in:
RickyRister 2024-12-28 13:29:59 -08:00 committed by GitHub
parent e0829a75d2
commit df9c5ae53c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 142 additions and 10 deletions

View file

@ -61,6 +61,7 @@ GeneralSettingsPage::GeneralSettingsPage()
// updates
SettingsCache &settings = SettingsCache::instance();
startupUpdateCheckCheckBox.setChecked(settings.getCheckUpdatesOnStartup());
updateNotificationCheckBox.setChecked(settings.getNotifyAboutUpdates());
newVersionOracleCheckBox.setChecked(settings.getNotifyAboutNewVersion());
@ -68,6 +69,8 @@ GeneralSettingsPage::GeneralSettingsPage()
connect(&languageBox, SIGNAL(currentIndexChanged(int)), this, SLOT(languageBoxChanged(int)));
connect(&updateReleaseChannelBox, SIGNAL(currentIndexChanged(int)), &settings, SLOT(setUpdateReleaseChannel(int)));
connect(&startupUpdateCheckCheckBox, &QCheckBox::QT_STATE_CHANGED, &settings,
&SettingsCache::setCheckUpdatesOnStartup);
connect(&updateNotificationCheckBox, &QCheckBox::QT_STATE_CHANGED, &settings, &SettingsCache::setNotifyAboutUpdate);
connect(&newVersionOracleCheckBox, &QCheckBox::QT_STATE_CHANGED, &settings,
&SettingsCache::setNotifyAboutNewVersion);
@ -78,9 +81,10 @@ GeneralSettingsPage::GeneralSettingsPage()
personalGrid->addWidget(&languageBox, 0, 1);
personalGrid->addWidget(&updateReleaseChannelLabel, 1, 0);
personalGrid->addWidget(&updateReleaseChannelBox, 1, 1);
personalGrid->addWidget(&updateNotificationCheckBox, 3, 0, 1, 2);
personalGrid->addWidget(&newVersionOracleCheckBox, 4, 0, 1, 2);
personalGrid->addWidget(&showTipsOnStartup, 5, 0, 1, 2);
personalGrid->addWidget(&startupUpdateCheckCheckBox, 3, 0, 1, 2);
personalGrid->addWidget(&updateNotificationCheckBox, 4, 0, 1, 2);
personalGrid->addWidget(&newVersionOracleCheckBox, 5, 0, 1, 2);
personalGrid->addWidget(&showTipsOnStartup, 6, 0, 1, 2);
personalGroupBox = new QGroupBox;
personalGroupBox->setLayout(personalGrid);
@ -288,6 +292,7 @@ void GeneralSettingsPage::retranslateUi()
customCardDatabasePathLabel.setText(tr("Custom database directory:"));
tokenDatabasePathLabel.setText(tr("Token database:"));
updateReleaseChannelLabel.setText(tr("Update channel"));
startupUpdateCheckCheckBox.setText(tr("Check for client updates on startup"));
updateNotificationCheckBox.setText(tr("Notify if a feature supported by the server is missing in my client"));
newVersionOracleCheckBox.setText(tr("Automatically run Oracle when running a new version of Cockatrice"));
showTipsOnStartup.setText(tr("Show tips on startup"));

View file

@ -65,6 +65,7 @@ private:
QGroupBox *personalGroupBox;
QGroupBox *pathsGroupBox;
QComboBox languageBox;
QCheckBox startupUpdateCheckCheckBox;
QCheckBox updateNotificationCheckBox;
QCheckBox newVersionOracleCheckBox;
QComboBox updateReleaseChannelBox;

View file

@ -1,5 +1,6 @@
#include "dlg_update.h"
#include "../client/network/client_update_checker.h"
#include "../client/network/release_channel.h"
#include "../client/ui/window_main.h"
#include "../settings/cache_settings.h"
@ -71,11 +72,6 @@ DlgUpdate::DlgUpdate(QWidget *parent) : QDialog(parent)
connect(uDownloader, SIGNAL(progressMade(qint64, qint64)), this, SLOT(downloadProgressMade(qint64, qint64)));
connect(uDownloader, SIGNAL(error(QString)), this, SLOT(downloadError(QString)));
ReleaseChannel *channel = SettingsCache::instance().getUpdateReleaseChannel();
connect(channel, SIGNAL(finishedCheck(bool, bool, Release *)), this,
SLOT(finishedUpdateCheck(bool, bool, Release *)));
connect(channel, SIGNAL(error(QString)), this, SLOT(updateCheckError(QString)));
// Check for updates
beginUpdateCheck();
}
@ -110,7 +106,12 @@ void DlgUpdate::beginUpdateCheck()
progress->setMinimum(0);
progress->setMaximum(0);
setLabel(tr("Checking for updates..."));
SettingsCache::instance().getUpdateReleaseChannel()->checkForUpdates();
auto checker = new ClientUpdateChecker(this);
connect(checker, SIGNAL(finishedCheck(bool, bool, Release *)), this,
SLOT(finishedUpdateCheck(bool, bool, Release *)));
connect(checker, SIGNAL(error(QString)), this, SLOT(updateCheckError(QString)));
checker->check();
}
void DlgUpdate::finishedUpdateCheck(bool needToUpdate, bool isCompatible, Release *release)