]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
Add ability for sparkle updater to notify UI when state has changed
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Thu, 23 Feb 2023 01:18:46 +0000 (02:18 +0100)
committerMatthieu Gallien <matthieu_gallien@yahoo.fr>
Sat, 22 Jul 2023 09:16:39 +0000 (11:16 +0200)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/generalsettings.cpp
src/gui/updater/sparkleupdater.h
src/gui/updater/sparkleupdater_mac.mm

index eb468939629fd89815bced68938dbf8a25a9d18b..af2d8acee8b33843eac50e55a34adde1385070a5 100644 (file)
@@ -304,9 +304,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
 
index d6e7566f34701f176e4e4e976563e1e57c1c36ec..c736763e0a96357fb32e61b7d6017b3fb1cf014e 100644 (file)
@@ -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;
 };
index 04636cf79417af8010d2abf360603120e686de1a..61380974e0d51216ab875158353201ff1fdd6eb2 100644 (file)
 #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;
     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.
     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];