From 5439ad0f5b9e170ba63dafe2df5d7bfc99113423 Mon Sep 17 00:00:00 2001 From: Yishi Lin Date: Mon, 20 May 2019 02:19:48 +0800 Subject: [PATCH] Fix #173 --- .../GitServerSettingTableViewController.swift | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/pass/Controllers/GitServerSettingTableViewController.swift b/pass/Controllers/GitServerSettingTableViewController.swift index b43a5bd..11dfdf3 100644 --- a/pass/Controllers/GitServerSettingTableViewController.swift +++ b/pass/Controllers/GitServerSettingTableViewController.swift @@ -98,8 +98,9 @@ class GitServerSettingTableViewController: UITableViewController { } // Remember git credential password/passphrase temporarily, ask whether users want this after a successful clone. SharedDefaults[.isRememberGitCredentialPassphraseOn] = true + let group = DispatchGroup() let dispatchQueue = DispatchQueue.global(qos: .userInitiated) - dispatchQueue.async { + dispatchQueue.async(group: group) { do { try self.passwordStore.cloneRepository(remoteRepoURL: URL(string: gitRepostiroyURL)!, credential: gitCredential, @@ -111,16 +112,28 @@ class GitServerSettingTableViewController: UITableViewController { } }, checkoutProgressBlock: { (path, completedSteps, totalSteps) in - DispatchQueue.main.async { - SVProgressHUD.showProgress(Float(completedSteps)/Float(totalSteps), status: "CheckingOutBranch".localize(branchName)) + DispatchQueue.main.async { SVProgressHUD.showProgress(Float(completedSteps)/Float(totalSteps), status: "CheckingOutBranch".localize(branchName)) } }) + } catch { DispatchQueue.main.async { - SharedDefaults[.gitURL] = URL(string: gitRepostiroyURL) - SharedDefaults[.gitUsername] = username - SharedDefaults[.gitBranchName] = branchName - SharedDefaults[.gitAuthenticationMethod] = auth - SVProgressHUD.dismiss() + let error = error as NSError + var message = error.localizedDescription + if let underlyingError = error.userInfo[NSUnderlyingErrorKey] as? NSError { + message = "\(message)\n\("UnderlyingError".localize()): \(underlyingError.localizedDescription)" + } + Utils.alert(title: "Error".localize(), message: message, controller: self, completion: nil) + } + } + } + group.notify(queue: dispatchQueue) { + NSLog("clone done") + DispatchQueue.main.async { + SharedDefaults[.gitURL] = URL(string: gitRepostiroyURL) + SharedDefaults[.gitUsername] = username + SharedDefaults[.gitBranchName] = branchName + SharedDefaults[.gitAuthenticationMethod] = auth + SVProgressHUD.dismiss { let savePassphraseAlert = UIAlertController(title: "Done".localize(), message: "WantToSaveGitCredential?".localize(), preferredStyle: UIAlertController.Style.alert) // no savePassphraseAlert.addAction(UIAlertAction(title: "No".localize(), style: UIAlertAction.Style.default) { _ in @@ -136,15 +149,6 @@ class GitServerSettingTableViewController: UITableViewController { }) self.present(savePassphraseAlert, animated: true, completion: nil) } - } catch { - DispatchQueue.main.async { - let error = error as NSError - var message = error.localizedDescription - if let underlyingError = error.userInfo[NSUnderlyingErrorKey] as? NSError { - message = "\(message)\n\("UnderlyingError".localize()): \(underlyingError.localizedDescription)" - } - Utils.alert(title: "Error".localize(), message: message, controller: self, completion: nil) - } } } }