move database operations to the main thread to avoid async problems
This commit is contained in:
parent
56cb5d94ee
commit
9f4830dc2a
3 changed files with 15 additions and 24 deletions
|
|
@ -22,15 +22,11 @@ class AdvancedSettingsTableViewController: UITableViewController {
|
|||
let alert = UIAlertController(title: "Erase Password Store Data?", message: "This will delete all local data and settings. Password store data on your remote server will not be affected.", preferredStyle: UIAlertControllerStyle.alert)
|
||||
alert.addAction(UIAlertAction(title: "Erase Password Data", style: UIAlertActionStyle.destructive, handler: {[unowned self] (action) -> Void in
|
||||
SVProgressHUD.show(withStatus: "Erasing ...")
|
||||
DispatchQueue.global(qos: .userInitiated).sync {
|
||||
PasswordStore.shared.erase()
|
||||
DispatchQueue.main.async {
|
||||
NotificationCenter.default.post(Notification(name: Notification.Name("passwordStoreErased")))
|
||||
self.navigationController!.popViewController(animated: true)
|
||||
SVProgressHUD.showSuccess(withStatus: "Done")
|
||||
SVProgressHUD.dismiss(withDelay: 1)
|
||||
}
|
||||
}
|
||||
PasswordStore.shared.erase()
|
||||
NotificationCenter.default.post(Notification(name: Notification.Name("passwordStoreErased")))
|
||||
self.navigationController!.popViewController(animated: true)
|
||||
SVProgressHUD.showSuccess(withStatus: "Done")
|
||||
SVProgressHUD.dismiss(withDelay: 1)
|
||||
}))
|
||||
alert.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.cancel, handler:nil))
|
||||
self.present(alert, animated: true, completion: nil)
|
||||
|
|
|
|||
|
|
@ -71,15 +71,16 @@ class PasswordRepositorySettingsTableViewController: BasicStaticTableViewControl
|
|||
SVProgressHUD.showProgress(Float(completedSteps)/Float(totalSteps), status: "Checkout Master Branch")
|
||||
}
|
||||
})
|
||||
|
||||
DispatchQueue.main.async {
|
||||
PasswordStore.shared.updatePasswordEntityCoreData()
|
||||
Defaults[.lastUpdatedTime] = Date()
|
||||
NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated")))
|
||||
Defaults[.gitRepositoryURL] = URL(string: gitRepostiroyURL)
|
||||
Defaults[.gitRepositoryUsername] = username
|
||||
Defaults[.gitRepositoryPassword] = password
|
||||
Defaults[.gitRepositoryAuthenticationMethod] = auth
|
||||
SVProgressHUD.showSuccess(withStatus: "Done")
|
||||
SVProgressHUD.dismiss(withDelay: 1)
|
||||
|
||||
Defaults[.lastUpdatedTime] = Date()
|
||||
|
||||
NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated")))
|
||||
|
||||
}
|
||||
} catch {
|
||||
DispatchQueue.main.async {
|
||||
|
|
@ -91,11 +92,6 @@ class PasswordRepositorySettingsTableViewController: BasicStaticTableViewControl
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
Defaults[.gitRepositoryURL] = URL(string: gitRepostiroyURL)
|
||||
Defaults[.gitRepositoryUsername] = username
|
||||
Defaults[.gitRepositoryPassword] = password
|
||||
Defaults[.gitRepositoryAuthenticationMethod] = auth
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,7 +115,6 @@ class PasswordStore {
|
|||
print(error)
|
||||
}
|
||||
storeRepository = try GTRepository(url: storeURL)
|
||||
updatePasswordEntityCoreData()
|
||||
gitCredential = credential
|
||||
}
|
||||
|
||||
|
|
@ -129,15 +128,13 @@ class PasswordStore {
|
|||
]
|
||||
let remote = try GTRemote(name: "origin", in: storeRepository!)
|
||||
try storeRepository?.pull((storeRepository?.currentBranch())!, from: remote, withOptions: options, progress: transferProgressBlock)
|
||||
// updatePasswordEntityCoreData()
|
||||
}
|
||||
|
||||
func updatePasswordEntityCoreData() {
|
||||
deleteCoreData(entityName: "PasswordEntity")
|
||||
deleteCoreData(entityName: "PasswordCategoryEntity")
|
||||
|
||||
let fm = FileManager.default
|
||||
fm.enumerator(atPath: storeURL.path)?.forEach({ (e) in
|
||||
fm.enumerator(atPath: self.storeURL.path)?.forEach({ (e) in
|
||||
if let e = e as? String, let url = URL(string: e) {
|
||||
if url.pathExtension == "gpg" {
|
||||
let passwordEntity = PasswordEntity(context: context)
|
||||
|
|
@ -355,6 +352,8 @@ class PasswordStore {
|
|||
|
||||
func erase() {
|
||||
Utils.removeFileIfExists(at: storeURL)
|
||||
Utils.removeFileIfExists(at: tempStoreURL)
|
||||
|
||||
Utils.removeFileIfExists(atPath: Globals.pgpPublicKeyPath)
|
||||
Utils.removeFileIfExists(atPath: Globals.pgpPrivateKeyPath)
|
||||
Utils.removeFileIfExists(at: Globals.sshPrivateKeyURL)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue