Pull out error handling from completionHandler for nckit lockunlock

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2024-07-31 15:16:59 +08:00 коммит произвёл Matthieu Gallien
Родитель 516fc7cc10
Коммит d312d009f7
1 изменённых файлов: 8 добавлений и 9 удалений

Просмотреть файл

@ -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).")
}