Pull out error handling from completionHandler for nckit lockunlock
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Wed, 31 Jul 2024 07:16:59 +0000 (15:16 +0800)
committerMatthieu Gallien <matthieu_gallien@yahoo.fr>
Thu, 12 Sep 2024 08:15:58 +0000 (10:15 +0200)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/Locking/LockViewController.swift

index d261c095510e41383c6e11c77fe419f070fc2b72..d170fc26b41e9181bfafd0b23bb1138bfaaa2f3b 100644 (file)
@@ -174,21 +174,20 @@ class LockViewController: NSViewController {
             descriptionLabel.stringValue =
                 "Communicating with server, \(locking ? "locking" : "unlocking") file…"
             
-            await withCheckedContinuation { continuation in
+            let error = await withCheckedContinuation { continuation in
                 kit.lockUnlockFile(
                     serverUrlFileName: itemServerRelativePath,
                     shouldLock: locking,
-                    completion: { account, error in
-                        if error == .success {
-                            self.descriptionLabel.stringValue =
-                                "File \(self.locking ? "locked" : "unlocked")!"
-                            continuation.resume()
-                        } else {
-                            self.presentError("Could not lock file: \(error).")
-                        }
+                    completion: { _, error in
+                        continuation.resume(returning: error)
                     }
                 )
             }
+            if error == .success {
+                descriptionLabel.stringValue = "File \(self.locking ? "locked" : "unlocked")!"
+            } else {
+                presentError("Could not lock file: \(error.errorDescription).")
+            }
         } catch let error {
             presentError("Could not lock file: \(error).")
         }