Refactor code, create abstract class ExternalUpdater

(Hopefully) this makes implementing updaters using external libraries easier on other platforms. To implement an updater on a new platform, create a new class that implements the pure virtual methods from `ExternalUpdater` and add code in the `UpdateChecker` initializer to initialize the new class.
This commit is contained in:
Kenneth Chew
2022-04-25 19:33:17 -04:00
parent 34adcec616
commit 05cd30ac06
8 changed files with 273 additions and 138 deletions

View File

@ -17,9 +17,10 @@
#include "net/NetJob.h"
#include "GoUpdate.h"
#include "ExternalUpdater.h"
#ifdef Q_OS_MAC
#include "updater/macsparkle/SparkleUpdater.h"
#include "MacSparkleUpdater.h"
#endif
class UpdateChecker : public QObject
@ -28,7 +29,7 @@ class UpdateChecker : public QObject
public:
UpdateChecker(shared_qobject_ptr<QNetworkAccessManager> nam, QString channelUrl, QString currentChannel, int currentBuild);
void checkForUpdate(QString updateChannel, bool notifyNoUpdate);
void checkForUpdate(const QString& updateChannel, bool notifyNoUpdate);
/*!
* Causes the update checker to download the channel list from the URL specified in config.h (generated by CMake).
@ -58,12 +59,10 @@ public:
*/
bool hasChannels() const;
#ifdef Q_OS_MAC
/*!
* Returns a pointer to the Sparkle updater.
* Returns a pointer to an object that controls the external updater, or nullptr if an external updater is not used.
*/
SparkleUpdater *getSparkleUpdater();
#endif
ExternalUpdater *getExternalUpdater();
signals:
//! Signal emitted when an update is available. Passes the URL for the repo and the ID and name for the version.
@ -129,8 +128,13 @@ private:
QString m_newRepoUrl;
#ifdef Q_OS_MAC
SparkleUpdater *m_sparkleUpdater = new SparkleUpdater();
#endif
/*!
* If not a nullptr, then the updater here will be used instead of the old updater that uses GoUpdate when
* checking for updates.
*
* As a result, signals from this class won't be emitted, and most of the functions in this class other
* than checkForUpdate are not useful. Call functions from this external updater object instead.
*/
ExternalUpdater *m_externalUpdater = nullptr;
};