瀏覽代碼

Add ability for sparkle updater to notify UI when state has changed

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
Claudio Cambra 3 年之前
父節點
當前提交
757ea941e3
共有 3 個文件被更改,包括 50 次插入23 次删除
  1. 3 1
      src/gui/generalsettings.cpp
  2. 4 0
      src/gui/updater/sparkleupdater.h
  3. 43 22
      src/gui/updater/sparkleupdater_mac.mm

+ 3 - 1
src/gui/generalsettings.cpp

@@ -300,9 +300,11 @@ void GeneralSettings::slotUpdateInfo()
                                       ocupdater->downloadState() != OCUpdater::DownloadComplete);
     }
 #if defined(Q_OS_MAC) && defined(HAVE_SPARKLE)
-    else if (auto sparkleUpdater = qobject_cast<SparkleUpdater *>(updater)) {
+    else if (const auto sparkleUpdater = qobject_cast<SparkleUpdater *>(updater)) {
+        connect(sparkleUpdater, &SparkleUpdater::statusChanged, this, &GeneralSettings::slotUpdateInfo, Qt::UniqueConnection);
         _ui->updateStateLabel->setText(sparkleUpdater->statusString());
         _ui->restartButton->setVisible(false);
+        _ui->updateButton->setEnabled(true);
     }
 #endif
 

+ 4 - 0
src/gui/updater/sparkleupdater.h

@@ -24,6 +24,7 @@ namespace OCC {
 class SparkleUpdater : public Updater
 {
     Q_OBJECT
+
 public:
     SparkleUpdater(const QUrl &appCastUrl);
     ~SparkleUpdater();
@@ -39,6 +40,9 @@ public:
 
     class SparkleInterface;
 
+signals:
+    void statusChanged();
+
 private:
     std::unique_ptr<SparkleInterface> _interface;
 };

+ 43 - 22
src/gui/updater/sparkleupdater_mac.mm

@@ -22,6 +22,35 @@
 #include "configfile.h"
 #include "updater/sparkleupdater.h"
 
+@class NCSparkleUpdaterDelegate;
+
+class Q_DECL_HIDDEN OCC::SparkleUpdater::SparkleInterface
+{
+public:
+    explicit SparkleInterface(SparkleUpdater *parent)
+        : q(parent)
+    {
+    }
+
+    ~SparkleInterface()
+    {
+        [updater release];
+        [delegate release];
+    }
+
+    void statusChanged()
+    {
+        emit q->statusChanged();
+    }
+
+    SUUpdater* updater;
+    NCSparkleUpdaterDelegate *delegate;
+
+private:
+    SparkleUpdater * const q;
+};
+
+
 @interface NCSparkleUpdaterDelegate : NSObject <SUUpdaterDelegate>
 
 @property (readwrite, assign) OCC::SparkleUpdater::SparkleInterface *owner;
@@ -49,12 +78,18 @@
     return YES;
 }
 
+- (void)notifyChange
+{
+    _owner->statusChanged();
+}
+
 // Sent when a valid update is found by the update driver.
 - (void)updater:(SUUpdater *)updater didFindValidUpdate:(SUAppcastItem *)update
 {
     Q_UNUSED(updater)
     Q_UNUSED(update)
     qCDebug(OCC::lcUpdater) << "Found a valid update.";
+    [self notifyChange];
 }
 
 // Sent when a valid update is not found.
@@ -62,6 +97,7 @@
 {
     Q_UNUSED(update)
     qCDebug(OCC::lcUpdater) << "No valid update found.";
+    [self notifyChange];
 }
 
 // Sent immediately before installing the specified update.
@@ -70,53 +106,38 @@
     Q_UNUSED(updater)
     Q_UNUSED(update)
     qCDebug(OCC::lcUpdater) << "About to install update.";
+    [self notifyChange];
 }
 
 - (void)updater:(SUUpdater *)updater didAbortWithError:(NSError *)error
 {
     Q_UNUSED(updater)
     qCDebug(OCC::lcUpdater) << error.description;
+    [self notifyChange];
 }
 
 - (void)updater:(SUUpdater *)updater didFinishLoadingAppcast:(SUAppcast *)appcast
 {
     Q_UNUSED(updater)
     Q_UNUSED(appcast)
+
     qCDebug(OCC::lcUpdater) << "Finished loading appcast.";
+    [self notifyChange];
 }
 
-@end
-
-
-namespace OCC {
 
-class Q_DECL_HIDDEN SparkleUpdater::SparkleInterface
-{
-public:
-    explicit SparkleInterface(SparkleUpdater *parent)
-        : q(parent)
-    {
-    }
 
-    ~SparkleInterface()
-    {
-        [updater release];
-        [delegate release];
-    }
+@end
 
-    SUUpdater* updater;
-    NCSparkleUpdaterDelegate *delegate;
 
-private:
-    SparkleUpdater * const q;
-};
+namespace OCC {
 
 // Delete ~/Library//Preferences/com.owncloud.desktopclient.plist to re-test
 SparkleUpdater::SparkleUpdater(const QUrl& appCastUrl)
     : Updater()
     , _interface(std::make_unique<SparkleInterface>(this))
 {
-    _interface->delegate = [[NCSparkleUpdaterDelegate alloc] init];
+    _interface->delegate = [[NCSparkleUpdaterDelegate alloc] initWithOwner:_interface.get()];
     [_interface->delegate retain];
 
     _interface->updater = [SUUpdater sharedUpdater];