mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-24 23:53:54 -07:00
Check for client updates on startup (#5359)
This commit is contained in:
parent
e0829a75d2
commit
df9c5ae53c
13 changed files with 142 additions and 10 deletions
35
cockatrice/src/client/network/client_update_checker.cpp
Normal file
35
cockatrice/src/client/network/client_update_checker.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#include "client_update_checker.h"
|
||||
|
||||
#include "../../settings/cache_settings.h"
|
||||
#include "release_channel.h"
|
||||
|
||||
ClientUpdateChecker::ClientUpdateChecker(QObject *parent) : QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void ClientUpdateChecker::check()
|
||||
{
|
||||
auto releaseChannel = SettingsCache::instance().getUpdateReleaseChannel();
|
||||
|
||||
finishedCheckConnection =
|
||||
connect(releaseChannel, &ReleaseChannel::finishedCheck, this, &ClientUpdateChecker::actFinishedCheck);
|
||||
errorConnection = connect(releaseChannel, &ReleaseChannel::error, this, &ClientUpdateChecker::actError);
|
||||
|
||||
releaseChannel->checkForUpdates();
|
||||
}
|
||||
|
||||
void ClientUpdateChecker::actFinishedCheck(bool needToUpdate, bool isCompatible, Release *release)
|
||||
{
|
||||
disconnect(finishedCheckConnection);
|
||||
disconnect(errorConnection);
|
||||
|
||||
emit finishedCheck(needToUpdate, isCompatible, release);
|
||||
}
|
||||
|
||||
void ClientUpdateChecker::actError(const QString &errorString)
|
||||
{
|
||||
disconnect(finishedCheckConnection);
|
||||
disconnect(errorConnection);
|
||||
|
||||
emit error(errorString);
|
||||
}
|
||||
45
cockatrice/src/client/network/client_update_checker.h
Normal file
45
cockatrice/src/client/network/client_update_checker.h
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#ifndef CLIENT_UPDATE_CHECKER_H
|
||||
#define CLIENT_UPDATE_CHECKER_H
|
||||
#include <QObject>
|
||||
|
||||
class Release;
|
||||
|
||||
/**
|
||||
* We use a singleton instance of UpdateChannel, which can cause interference and feedback loops when multiple objects
|
||||
* connect to it.
|
||||
*
|
||||
* This class encapsulates the usage of that UpdateChannel to ensure that the check only happens once per connection and
|
||||
* the connection is destroyed after it's been used.
|
||||
*/
|
||||
class ClientUpdateChecker : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QMetaObject::Connection finishedCheckConnection;
|
||||
QMetaObject::Connection errorConnection;
|
||||
|
||||
void actFinishedCheck(bool needToUpdate, bool isCompatible, Release *release);
|
||||
void actError(const QString &errorString);
|
||||
|
||||
public:
|
||||
explicit ClientUpdateChecker(QObject *parent = nullptr);
|
||||
/**
|
||||
* Actually performs the check, using the currently selected update channel in the settings.
|
||||
* Any resulting signals will only be sent once.
|
||||
* This method should only be called ONCE per instance.
|
||||
*/
|
||||
void check();
|
||||
|
||||
signals:
|
||||
/**
|
||||
* Forwarded from UpdateChannel::finishedCheck
|
||||
*/
|
||||
void finishedCheck(bool needToUpdate, bool isCompatible, Release *release);
|
||||
|
||||
/**
|
||||
* Forwarded from UpdateChannel::error
|
||||
*/
|
||||
void error(const QString &errorString);
|
||||
};
|
||||
|
||||
#endif // CLIENT_UPDATE_CHECKER_H
|
||||
|
|
@ -112,7 +112,7 @@ void StableReleaseChannel::releaseListFinished()
|
|||
QVariantMap resultMap = jsonResponse.toVariant().toMap();
|
||||
if (!(resultMap.contains("name") && resultMap.contains("html_url") && resultMap.contains("tag_name") &&
|
||||
resultMap.contains("published_at"))) {
|
||||
qWarning() << "Invalid received from the release update server.";
|
||||
qWarning() << "Invalid received from the release update server:" << resultMap;
|
||||
emit error(tr("Invalid reply received from the release update server."));
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@
|
|||
#include "../../settings/cache_settings.h"
|
||||
#include "../../utility/logger.h"
|
||||
#include "../get_text_with_max.h"
|
||||
#include "../network/client_update_checker.h"
|
||||
#include "../network/release_channel.h"
|
||||
#include "../tabs/tab_game.h"
|
||||
#include "../tabs/tab_supervisor.h"
|
||||
#include "pb/event_connection_closed.pb.h"
|
||||
|
|
@ -879,6 +881,10 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
|
||||
void MainWindow::startupConfigCheck()
|
||||
{
|
||||
if (SettingsCache::instance().getCheckUpdatesOnStartup()) {
|
||||
actCheckClientUpdates();
|
||||
}
|
||||
|
||||
if (SettingsCache::instance().getClientVersion() == CLIENT_INFO_NOT_SET) {
|
||||
// no config found, 99% new clean install
|
||||
qDebug() << "Startup: old client version empty, assuming first start after clean install";
|
||||
|
|
@ -1223,6 +1229,21 @@ void MainWindow::actCheckServerUpdates()
|
|||
connect(hps, &HandlePublicServers::sigPublicServersDownloadedSuccessfully, [=]() { hps->deleteLater(); });
|
||||
}
|
||||
|
||||
void MainWindow::actCheckClientUpdates()
|
||||
{
|
||||
auto checker = new ClientUpdateChecker(this);
|
||||
connect(checker, &ClientUpdateChecker::finishedCheck, this, &MainWindow::checkClientUpdatesFinished);
|
||||
checker->check();
|
||||
}
|
||||
|
||||
void MainWindow::checkClientUpdatesFinished(bool needToUpdate, bool /* isCompatible */, Release * /* release */)
|
||||
{
|
||||
if (needToUpdate) {
|
||||
DlgUpdate dlg(this);
|
||||
dlg.exec();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::refreshShortcuts()
|
||||
{
|
||||
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@
|
|||
#include <QSystemTrayIcon>
|
||||
#include <QtNetwork>
|
||||
|
||||
class Release;
|
||||
class DlgConnect;
|
||||
class DlgViewLog;
|
||||
class GameReplay;
|
||||
|
|
@ -49,6 +50,7 @@ class MainWindow : public QMainWindow
|
|||
public slots:
|
||||
void actCheckCardUpdates();
|
||||
void actCheckServerUpdates();
|
||||
void actCheckClientUpdates();
|
||||
private slots:
|
||||
void updateTabMenu(const QList<QMenu *> &newMenuList);
|
||||
void statusChanged(ClientStatus _status);
|
||||
|
|
@ -95,6 +97,8 @@ private slots:
|
|||
void cardDatabaseNewSetsFound(int numUnknownSets, QStringList unknownSetsNames);
|
||||
void cardDatabaseAllNewSetsEnabled();
|
||||
|
||||
void checkClientUpdatesFinished(bool needToUpdate, bool isCompatible, Release *release);
|
||||
|
||||
void actOpenCustomFolder();
|
||||
void actOpenCustomsetsFolder();
|
||||
void actAddCustomSet();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue