]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
Replace private class with an interfacing class to bridge Obj-C delegate class and...
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Wed, 22 Feb 2023 22:00:48 +0000 (23:00 +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/updater/sparkleupdater.h
src/gui/updater/sparkleupdater_mac.mm

index a07ea5353193e38c6e880369fd800c022fa74703..d6e7566f34701f176e4e4e976563e1e57c1c36ec 100644 (file)
@@ -37,9 +37,10 @@ public:
 
     QString statusString();
 
+    class SparkleInterface;
+
 private:
-    class Private;
-    std::unique_ptr<Private> d;
+    std::unique_ptr<SparkleInterface> _interface;
 };
 
 } // namespace OCC
index 4a0be02602039a86b0712731895621fdd4c1f940..33769bbe1e1411f85ed28b605260b2bc83dd44af 100644 (file)
 #include "updater/sparkleupdater.h"
 
 @interface NCSparkleUpdaterDelegate : NSObject <SUUpdaterDelegate>
+
+@property (readwrite, assign) OCC::SparkleUpdater::SparkleInterface *owner;
+
+- (instancetype)initWithOwner:(OCC::SparkleUpdater::SparkleInterface *)owner;
 - (BOOL)updaterMayCheckForUpdates:(SUUpdater *)bundle;
+
 @end
-@implementation NCSparkleUpdaterDelegate //(SUUpdaterDelegateInformalProtocol)
+
+@implementation NCSparkleUpdaterDelegate
+
+- (instancetype)initWithOwner:(OCC::SparkleUpdater::SparkleInterface *)owner
+{
+    self = [super init];
+    if (self) {
+        _owner = owner;
+    }
+    return self;
+}
 
 - (BOOL)updaterMayCheckForUpdates:(SUUpdater *)bundle
 {
@@ -57,7 +72,7 @@
     qCDebug(OCC::lcUpdater) << "About to install update.";
 }
 
-- (void) updater:(SUUpdater *)updater didAbortWithError:(NSError *)error
+- (void)updater:(SUUpdater *)updater didAbortWithError:(NSError *)error
 {
     Q_UNUSED(updater)
     qCDebug(OCC::lcUpdater) << error.description;
     qCDebug(OCC::lcUpdater) << "Finished loading appcast.";
 }
 
-
 @end
 
 
 namespace OCC {
 
-class Q_DECL_HIDDEN SparkleUpdater::Private
+class Q_DECL_HIDDEN SparkleUpdater::SparkleInterface
 {
 public:
-    ~Private()
+    ~SparkleInterface()
     {
         [updater release];
         [delegate release];
@@ -92,33 +106,32 @@ public:
 // Delete ~/Library//Preferences/com.owncloud.desktopclient.plist to re-test
 SparkleUpdater::SparkleUpdater(const QUrl& appCastUrl)
     : Updater()
-    , d(std::make_unique<Private>())
+    , _interface(std::make_unique<SparkleInterface>())
 {
-    d->delegate = [[NCSparkleUpdaterDelegate alloc] init];
-    [d->delegate retain];
+    _interface->delegate = [[NCSparkleUpdaterDelegate alloc] init];
+    [_interface->delegate retain];
 
-    d->updater = [SUUpdater sharedUpdater];
-    [d->updater setDelegate:d->delegate];
-    [d->updater setAutomaticallyChecksForUpdates:YES];
-    [d->updater setAutomaticallyDownloadsUpdates:NO];
-    [d->updater setSendsSystemProfile:NO];
-    [d->updater resetUpdateCycle];
-    [d->updater retain];
+    _interface->updater = [SUUpdater sharedUpdater];
+    [_interface->updater setDelegate:_interface->delegate];
+    [_interface->updater setAutomaticallyChecksForUpdates:YES];
+    [_interface->updater setAutomaticallyDownloadsUpdates:NO];
+    [_interface->updater setSendsSystemProfile:NO];
+    [_interface->updater resetUpdateCycle];
+    [_interface->updater retain];
 
     setUpdateUrl(appCastUrl);
 
     // Sparkle 1.8 required
     NSString *userAgent = [NSString stringWithUTF8String: Utility::userAgentString().data()];
-    [d->updater setUserAgentString: userAgent];
+    [_interface->updater setUserAgentString: userAgent];
 }
 
 SparkleUpdater::~SparkleUpdater() = default;
 
 void SparkleUpdater::setUpdateUrl(const QUrl &url)
 {
-    NSURL* nsurl = [NSURL URLWithString:
-            [NSString stringWithUTF8String: url.toString().toUtf8().data()]];
-    [d->updater setFeedURL: nsurl];
+    NSURL* nsurl = [NSURL URLWithString:[NSString stringWithUTF8String:url.toString().toUtf8().data()]];
+    [_interface->updater setFeedURL: nsurl];
 }
 
 // FIXME: Should be changed to not instantiate the SparkleUpdater at all in this case
@@ -145,7 +158,7 @@ void SparkleUpdater::checkForUpdate()
 {
     qCDebug(OCC::lcUpdater) << "Checking for updates.";
     if (autoUpdaterAllowed()) {
-        [d->updater checkForUpdates: NSApp];
+        [_interface->updater checkForUpdates: NSApp];
     }
 }
 
@@ -153,7 +166,7 @@ void SparkleUpdater::backgroundCheckForUpdate()
 {
     qCDebug(OCC::lcUpdater) << "launching background check";
     if (autoUpdaterAllowed()) {
-        [d->updater checkForUpdatesInBackground];
+        [_interface->updater checkForUpdatesInBackground];
     }
 }