Auto Updater: Show UI element also on macOS
authorMarkus Goetz <markus@woboq.com>
Fri, 27 Apr 2018 07:10:38 +0000 (09:10 +0200)
committerCamila (Rebase PR Action) <hello@camila.codes>
Tue, 24 Nov 2020 18:22:33 +0000 (18:22 +0000)
(cherry picked from commit dfdc2e1e87f99d387a042f4983c999fbb7fcf3d9)

src/gui/CMakeLists.txt
src/gui/generalsettings.cpp
src/gui/updater/sparkleupdater.h
src/gui/updater/sparkleupdater_mac.mm

index cf8af8fd2024b7eabaeea8514bdaf7413f180866..93929fa73dc4830799a042d22375d1410df6c9f4 100644 (file)
@@ -163,7 +163,7 @@ IF( APPLE )
     if(SPARKLE_FOUND AND BUILD_UPDATER)
        # Define this, we need to check in updater.cpp
        add_definitions( -DHAVE_SPARKLE )
-       list(APPEND updater_SRCS updater/sparkleupdater_mac.mm)
+       list(APPEND updater_SRCS updater/sparkleupdater_mac.mm updater/sparkleupdater.h)
    endif()
 ENDIF()
 
index 965af6130570b2106aefc99c5470faabb8569d3a..b9081da438144fa0c40242547e12d12eb1a89fad 100644 (file)
 #if defined(BUILD_UPDATER)
 #include "updater/updater.h"
 #include "updater/ocupdater.h"
+#ifdef Q_OS_MAC
+// FIXME We should unify those, but Sparkle does everything behind the scene transparently
+#include "updater/sparkleupdater.h"
+#endif
 #endif
 
 #include "ignorelisteditor.h"
@@ -248,28 +252,30 @@ void GeneralSettings::loadMiscSettings()
 #if defined(BUILD_UPDATER)
 void GeneralSettings::slotUpdateInfo()
 {
-    // Note: the sparkle-updater is not an OCUpdater
-    auto *updater = qobject_cast<OCUpdater *>(Updater::instance());
     if (ConfigFile().skipUpdateCheck()) {
-        updater = nullptr; // don't show update info if updates are disabled
+        // updater disabled on compile
+        _ui->updatesGroupBox->setVisible(false);
+        return;
     }
 
-    if (updater) {
-        connect(updater, &OCUpdater::downloadStateChanged, this, &GeneralSettings::slotUpdateInfo, Qt::UniqueConnection);
-        connect(_ui->restartButton, &QAbstractButton::clicked, updater, &OCUpdater::slotStartInstaller, Qt::UniqueConnection);
+    // Note: the sparkle-updater is not an OCUpdater
+    auto *ocupdater = qobject_cast<OCUpdater *>(Updater::instance());
+    if (ocupdater) {
+        connect(ocupdater, &OCUpdater::downloadStateChanged, this, &GeneralSettings::slotUpdateInfo, Qt::UniqueConnection);
+        connect(_ui->restartButton, &QAbstractButton::clicked, ocupdater, &OCUpdater::slotStartInstaller, Qt::UniqueConnection);
         connect(_ui->restartButton, &QAbstractButton::clicked, qApp, &QApplication::quit, Qt::UniqueConnection);
         connect(_ui->updateButton, &QAbstractButton::clicked, this, &GeneralSettings::slotUpdateCheckNow, Qt::UniqueConnection);
         connect(_ui->autoCheckForUpdatesCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::slotToggleAutoUpdateCheck);
 
-        QString status = updater->statusString();
+        QString status = ocupdater->statusString();
         Theme::replaceLinkColorStringBackgroundAware(status);
         _ui->updateStateLabel->setText(status);
 
-        _ui->restartButton->setVisible(updater->downloadState() == OCUpdater::DownloadComplete);
+        _ui->restartButton->setVisible(ocupdater->downloadState() == OCUpdater::DownloadComplete);
 
-        _ui->updateButton->setEnabled(updater->downloadState() != OCUpdater::CheckingServer &&
-                                      updater->downloadState() != OCUpdater::Downloading &&
-                                      updater->downloadState() != OCUpdater::DownloadComplete);
+        _ui->updateButton->setEnabled(ocupdater->downloadState() != OCUpdater::CheckingServer &&
+                                      ocupdater->downloadState() != OCUpdater::Downloading &&
+                                      ocupdater->downloadState() != OCUpdater::DownloadComplete);
 
         _ui->autoCheckForUpdatesCheckBox->setChecked(ConfigFile().autoUpdateCheck());
 
@@ -277,11 +283,19 @@ void GeneralSettings::slotUpdateInfo()
         _ui->updateChannel->setCurrentIndex(ConfigFile().updateChannel() == "beta" ? 1 : 0);
         connect(_ui->updateChannel, &QComboBox::currentTextChanged,
             this, &GeneralSettings::slotUpdateChannelChanged, Qt::UniqueConnection);
+    }
+#ifdef Q_OS_MAC
+    else if (auto sparkleUpdater = qobject_cast<SparkleUpdater *>(Updater::instance())) {
+        _ui->updateStateLabel->setText(sparkleUpdater->statusString());
+        _ui->restartButton->setVisible(false);
 
-    } else {
-        // can't have those infos from sparkle currently
-        _ui->updatesGroupBox->setVisible(false);
+        // Channel selection
+        _ui->updateChannel->setCurrentIndex(ConfigFile().updateChannel() == "beta" ? 1 : 0);
+        connect(_ui->updateChannel, &QComboBox::currentTextChanged,
+            this, &GeneralSettings::slotUpdateChannelChanged, Qt::UniqueConnection);
     }
+#endif
+
 }
 
 void GeneralSettings::slotUpdateChannelChanged(const QString &channel)
index 5a3c70eb77d4c6419ff7cef7143fc2d0b91e89d7..d565c6f6e17576efd04dec419a0f44aab5cb9800 100644 (file)
@@ -23,6 +23,7 @@ namespace OCC {
 
 class SparkleUpdater : public Updater
 {
+    Q_OBJECT
 public:
     SparkleUpdater(const QString &appCastUrl);
     ~SparkleUpdater();
@@ -32,6 +33,8 @@ public:
     void backgroundCheckForUpdate() override;
     bool handleStartup() override { return false; }
 
+    QString statusString();
+
 private:
     class Private;
     Private *d;
index cfb1189ad2b4043e2fd061f750a108453eb249b0..5bf43efdbc7cda1b111f108d8f187e4f036ea19e 100644 (file)
@@ -114,7 +114,7 @@ SparkleUpdater::~SparkleUpdater()
     delete d;
 }
 
-
+// FIXME: Should be changed to not instanicate the SparkleUpdater at all in this case
 bool autoUpdaterAllowed()
 {
     // See https://github.com/owncloud/client/issues/2931
@@ -143,4 +143,10 @@ void SparkleUpdater::backgroundCheckForUpdate()
     }
 }
 
+QString SparkleUpdater::statusString()
+{
+    // FIXME Show the real state depending on the callbacks
+    return QString();
+}
+
 } // namespace OCC