show transfer progress
This commit is contained in:
parent
1b0f8fcb05
commit
a4b26b3bd3
3 changed files with 36 additions and 12 deletions
|
|
@ -54,7 +54,9 @@ class PasswordStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func cloneRepository(remoteRepoURL: URL) -> Bool {
|
func cloneRepository(remoteRepoURL: URL,
|
||||||
|
transferProgressBlock: @escaping (UnsafePointer<git_transfer_progress>, UnsafeMutablePointer<ObjCBool>) -> Void,
|
||||||
|
checkoutProgressBlock: @escaping (String?, UInt, UInt) -> Void) -> Bool {
|
||||||
print("start cloning remote repo")
|
print("start cloning remote repo")
|
||||||
let fm = FileManager.default
|
let fm = FileManager.default
|
||||||
if (storeRepository != nil) {
|
if (storeRepository != nil) {
|
||||||
|
|
@ -66,19 +68,21 @@ class PasswordStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
storeRepository = try GTRepository.clone(from: remoteRepoURL, toWorkingDirectory: storeURL, options: nil, transferProgressBlock: nil, checkoutProgressBlock: nil)
|
print("start cloning...")
|
||||||
|
storeRepository = try GTRepository.clone(from: remoteRepoURL, toWorkingDirectory: storeURL, options: nil, transferProgressBlock:transferProgressBlock, checkoutProgressBlock: checkoutProgressBlock)
|
||||||
updatePasswordEntityCoreData()
|
updatePasswordEntityCoreData()
|
||||||
return true
|
return true
|
||||||
} catch {
|
} catch {
|
||||||
|
storeRepository = nil
|
||||||
print(error)
|
print(error)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func pullRepository() -> Bool {
|
func pullRepository(transferProgressBlock: @escaping (UnsafePointer<git_transfer_progress>, UnsafeMutablePointer<ObjCBool>) -> Void) -> Bool {
|
||||||
print("pullRepoisitory")
|
print("pullRepoisitory")
|
||||||
do {
|
do {
|
||||||
let remote = try GTRemote(name: "origin", in: storeRepository!)
|
let remote = try GTRemote(name: "origin", in: storeRepository!)
|
||||||
try storeRepository?.pull((storeRepository?.currentBranch())!, from: remote, withOptions: nil, progress: nil)
|
try storeRepository?.pull((storeRepository?.currentBranch())!, from: remote, withOptions: nil, progress: transferProgressBlock)
|
||||||
updatePasswordEntityCoreData()
|
updatePasswordEntityCoreData()
|
||||||
return true
|
return true
|
||||||
} catch {
|
} catch {
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,18 @@ class PasswordsTableViewController: UITableViewController {
|
||||||
let searchController = UISearchController(searchResultsController: nil)
|
let searchController = UISearchController(searchResultsController: nil)
|
||||||
|
|
||||||
@IBAction func refreshPasswords(_ sender: UIBarButtonItem) {
|
@IBAction func refreshPasswords(_ sender: UIBarButtonItem) {
|
||||||
|
SVProgressHUD.setDefaultMaskType(.black)
|
||||||
|
SVProgressHUD.show(withStatus: "Pull Remote Repository")
|
||||||
DispatchQueue.global(qos: .userInitiated).async {
|
DispatchQueue.global(qos: .userInitiated).async {
|
||||||
if PasswordStore.shared.pullRepository() {
|
if PasswordStore.shared.pullRepository(transferProgressBlock: {(git_transfer_progress, stop) in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
SVProgressHUD.showProgress(Float(git_transfer_progress.pointee.received_objects)/Float(git_transfer_progress.pointee.total_objects), status: "Pull Remote Repository")
|
||||||
|
}
|
||||||
|
}) {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
SVProgressHUD.showSuccess(withStatus: "Done")
|
||||||
|
SVProgressHUD.dismiss(withDelay: 1)
|
||||||
|
}
|
||||||
print("pull success")
|
print("pull success")
|
||||||
self.passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData()
|
self.passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData()
|
||||||
self.tableView.reloadData()
|
self.tableView.reloadData()
|
||||||
|
|
|
||||||
|
|
@ -24,19 +24,29 @@ class SettingsTableViewController: UITableViewController {
|
||||||
Defaults[.gitRepositoryURL] = URL(string: controller.gitRepositoryURLTextField.text!)
|
Defaults[.gitRepositoryURL] = URL(string: controller.gitRepositoryURLTextField.text!)
|
||||||
|
|
||||||
SVProgressHUD.setDefaultMaskType(.black)
|
SVProgressHUD.setDefaultMaskType(.black)
|
||||||
SVProgressHUD.show(withStatus: "Cloning Remote Repository")
|
SVProgressHUD.show(withStatus: "Prepare Repository")
|
||||||
|
//SVProgressHUD.showProgress(0.0, status: "Clone Remote Repository")
|
||||||
|
|
||||||
DispatchQueue.global(qos: .userInitiated).async {
|
DispatchQueue.global(qos: .userInitiated).async {
|
||||||
let ret = PasswordStore.shared.cloneRepository(remoteRepoURL: Defaults[.gitRepositoryURL]!)
|
let ret = PasswordStore.shared.cloneRepository(remoteRepoURL: Defaults[.gitRepositoryURL]!,
|
||||||
|
transferProgressBlock:{ (git_transfer_progress, stop) in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
SVProgressHUD.showProgress(Float(git_transfer_progress.pointee.received_objects)/Float(git_transfer_progress.pointee.total_objects), status: "Clone Remote Repository")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
checkoutProgressBlock: { (path, completedSteps, totalSteps) in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
SVProgressHUD.showProgress(Float(completedSteps)/Float(totalSteps), status: "Checkout Master Branch")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
if ret {
|
if ret {
|
||||||
SVProgressHUD.dismiss()
|
SVProgressHUD.showSuccess(withStatus: "Done")
|
||||||
SVProgressHUD.setMaximumDismissTimeInterval(1)
|
SVProgressHUD.dismiss(withDelay: 1)
|
||||||
SVProgressHUD.showSuccess(withStatus: "Success")
|
NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated")))
|
||||||
NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated")))
|
|
||||||
} else {
|
} else {
|
||||||
SVProgressHUD.showError(withStatus: "Error")
|
SVProgressHUD.showError(withStatus: "Error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue