diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index f016dc76..12761da1 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -283,7 +283,7 @@ public: updateLaunchAction(); } - void createMainToolbarActions(QMainWindow *MainWindow) + void createMainToolbarActions(MainWindow *MainWindow) { actionAddInstance = TranslatedAction(MainWindow); actionAddInstance->setObjectName(QStringLiteral("actionAddInstance")); @@ -1027,6 +1027,13 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow { updater->checkForUpdate(APPLICATION->settings()->get("UpdateChannel").toString(), false); } + +#ifdef Q_OS_MAC + connect(APPLICATION->updateChecker()->getSparkleUpdater(), + &SparkleUpdater::canCheckForUpdatesChanged, + this, + &MainWindow::updatesAllowedChanged); +#endif } setSelectedInstanceById(APPLICATION->settings()->get("SelectedInstance").toString()); diff --git a/launcher/updater/UpdateChecker.cpp b/launcher/updater/UpdateChecker.cpp index efdb6093..ad159841 100644 --- a/launcher/updater/UpdateChecker.cpp +++ b/launcher/updater/UpdateChecker.cpp @@ -44,8 +44,28 @@ bool UpdateChecker::hasChannels() const return !m_channels.isEmpty(); } +#ifdef Q_OS_MAC +SparkleUpdater* UpdateChecker::getSparkleUpdater() +{ + return m_sparkleUpdater; +} +#endif + void UpdateChecker::checkForUpdate(QString updateChannel, bool notifyNoUpdate) { +#ifdef Q_OS_MAC + m_sparkleUpdater->setAllowedChannel(updateChannel); + if (notifyNoUpdate) + { + qDebug() << "Checking for updates."; + m_sparkleUpdater->checkForUpdates(); + } + else + { + // Sparkle already handles automatic update checks. + return; + } +#else qDebug() << "Checking for updates."; // If the channel list hasn't loaded yet, load it and defer checking for updates until @@ -109,6 +129,7 @@ void UpdateChecker::checkForUpdate(QString updateChannel, bool notifyNoUpdate) connect(indexJob.get(), &NetJob::succeeded, [this, notifyNoUpdate](){ updateCheckFinished(notifyNoUpdate); }); connect(indexJob.get(), &NetJob::failed, this, &UpdateChecker::updateCheckFailed); indexJob->start(); +#endif } void UpdateChecker::updateCheckFinished(bool notifyNoUpdate) diff --git a/launcher/updater/UpdateChecker.h b/launcher/updater/UpdateChecker.h index 13ee4efd..c569e49a 100644 --- a/launcher/updater/UpdateChecker.h +++ b/launcher/updater/UpdateChecker.h @@ -18,6 +18,10 @@ #include "net/NetJob.h" #include "GoUpdate.h" +#ifdef Q_OS_MAC +#include "updater/macsparkle/SparkleUpdater.h" +#endif + class UpdateChecker : public QObject { Q_OBJECT @@ -54,6 +58,13 @@ public: */ bool hasChannels() const; +#ifdef Q_OS_MAC + /*! + * Returns a pointer to the Sparkle updater. + */ + SparkleUpdater *getSparkleUpdater(); +#endif + signals: //! Signal emitted when an update is available. Passes the URL for the repo and the ID and name for the version. void updateAvailable(GoUpdate::Status status); @@ -117,5 +128,9 @@ private: QString m_currentRepoUrl; QString m_newRepoUrl; + +#ifdef Q_OS_MAC + SparkleUpdater *m_sparkleUpdater = new SparkleUpdater(); +#endif };