Updater: Make sparkle updater respect release channel
authorChristian Kamm <mail@ckamm.de>
Fri, 18 May 2018 12:17:13 +0000 (14:17 +0200)
committerCamila (Rebase PR Action) <hello@camila.codes>
Tue, 24 Nov 2020 18:22:33 +0000 (18:22 +0000)
src/gui/generalsettings.cpp
src/gui/updater/sparkleupdater.h
src/gui/updater/sparkleupdater_mac.mm
src/gui/updater/updater.cpp

index b9081da438144fa0c40242547e12d12eb1a89fad..789bc27b39ba6fbf7fa7582a42c226f6e2bfb6c8 100644 (file)
@@ -252,7 +252,7 @@ void GeneralSettings::loadMiscSettings()
 #if defined(BUILD_UPDATER)
 void GeneralSettings::slotUpdateInfo()
 {
-    if (ConfigFile().skipUpdateCheck()) {
+    if (ConfigFile().skipUpdateCheck() || !Updater::instance()) {
         // updater disabled on compile
         _ui->updatesGroupBox->setVisible(false);
         return;
@@ -278,24 +278,18 @@ void GeneralSettings::slotUpdateInfo()
                                       ocupdater->downloadState() != OCUpdater::DownloadComplete);
 
         _ui->autoCheckForUpdatesCheckBox->setChecked(ConfigFile().autoUpdateCheck());
-
-        // Channel selection
-        _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);
-
-        // Channel selection
-        _ui->updateChannel->setCurrentIndex(ConfigFile().updateChannel() == "beta" ? 1 : 0);
-        connect(_ui->updateChannel, &QComboBox::currentTextChanged,
-            this, &GeneralSettings::slotUpdateChannelChanged, Qt::UniqueConnection);
     }
 #endif
 
+    // Channel selection
+    _ui->updateChannel->setCurrentIndex(ConfigFile().updateChannel() == "beta" ? 1 : 0);
+    connect(_ui->updateChannel, &QComboBox::currentTextChanged,
+        this, &GeneralSettings::slotUpdateChannelChanged, Qt::UniqueConnection);
 }
 
 void GeneralSettings::slotUpdateChannelChanged(const QString &channel)
@@ -306,6 +300,12 @@ void GeneralSettings::slotUpdateChannelChanged(const QString &channel)
         updater->setUpdateUrl(Updater::updateUrl());
         updater->checkForUpdate();
     }
+#ifdef Q_OS_MAC
+    else if (auto *updater = qobject_cast<SparkleUpdater *>(Updater::instance())) {
+        updater->setUpdateUrl(Updater::updateUrl());
+        updater->checkForUpdate();
+    }
+#endif
 }
 
 void GeneralSettings::slotUpdateCheckNow()
index d565c6f6e17576efd04dec419a0f44aab5cb9800..d03e76360684b882d72db45dbfc8cfd2c4bc6091 100644 (file)
@@ -25,9 +25,11 @@ class SparkleUpdater : public Updater
 {
     Q_OBJECT
 public:
-    SparkleUpdater(const QString &appCastUrl);
+    SparkleUpdater(const QUrl &appCastUrl);
     ~SparkleUpdater();
 
+    void setUpdateUrl(const QUrl &url);
+
     // unused in this updater
     void checkForUpdate() override;
     void backgroundCheckForUpdate() override;
index 5bf43efdbc7cda1b111f108d8f187e4f036ea19e..1ba1e2c235d69ce0eed26e6a30497270580040f8 100644 (file)
@@ -83,7 +83,7 @@ class SparkleUpdater::Private
 };
 
 // Delete ~/Library//Preferences/com.owncloud.desktopclient.plist to re-test
-SparkleUpdater::SparkleUpdater(const QString& appCastUrl)
+SparkleUpdater::SparkleUpdater(const QUrl& appCastUrl)
     : Updater()
 {
     d = new Private;
@@ -99,9 +99,7 @@ SparkleUpdater::SparkleUpdater(const QString& appCastUrl)
     [d->updater resetUpdateCycle];
     [d->updater retain];
 
-    NSURL* url = [NSURL URLWithString:
-            [NSString stringWithUTF8String: appCastUrl.toUtf8().data()]];
-    [d->updater setFeedURL: url];
+    setUpdateUrl(appCastUrl);
 
     // Sparkle 1.8 required
     NSString *userAgent = [NSString stringWithUTF8String: Utility::userAgentString().data()];
@@ -114,6 +112,13 @@ SparkleUpdater::~SparkleUpdater()
     delete d;
 }
 
+void SparkleUpdater::setUpdateUrl(const QUrl &url)
+{
+    NSURL* nsurl = [NSURL URLWithString:
+            [NSString stringWithUTF8String: url.toString().toUtf8().data()]];
+    [d->updater setFeedURL: nsurl];
+}
+
 // FIXME: Should be changed to not instanicate the SparkleUpdater at all in this case
 bool autoUpdaterAllowed()
 {
index 36fd3f06fdb64f34a2cfa19f403709631421e99c..9867db7f8bf5047d60a490d6a14174cc424022bc 100644 (file)
@@ -130,7 +130,7 @@ Updater *Updater::create()
     }
 
 #if defined(Q_OS_MAC) && defined(HAVE_SPARKLE)
-    return new SparkleUpdater(url.toString());
+    return new SparkleUpdater(url);
 #elif defined(Q_OS_WIN32)
     // the best we can do is notify about updates
     return new NSISUpdater(url);