Cleanup code of error handling
This commit is contained in:
parent
9a3131943f
commit
2bfb36c527
8 changed files with 17 additions and 43 deletions
|
|
@ -230,10 +230,14 @@ class GitServerSettingTableViewController: UITableViewController {
|
||||||
// might keys updated via iTunes, or downloaded/pasted inside the app
|
// might keys updated via iTunes, or downloaded/pasted inside the app
|
||||||
fileActionTitle.append(" (Import)")
|
fileActionTitle.append(" (Import)")
|
||||||
let fileAction = UIAlertAction(title: fileActionTitle, style: .default) { _ in
|
let fileAction = UIAlertAction(title: fileActionTitle, style: .default) { _ in
|
||||||
self.passwordStore.gitSSHKeyImportFromFileSharing()
|
do {
|
||||||
SharedDefaults[.gitSSHKeySource] = "file"
|
try self.passwordStore.gitSSHKeyImportFromFileSharing()
|
||||||
SVProgressHUD.showSuccess(withStatus: "Imported")
|
SharedDefaults[.gitSSHKeySource] = "file"
|
||||||
SVProgressHUD.dismiss(withDelay: 1)
|
SVProgressHUD.showSuccess(withStatus: "Imported")
|
||||||
|
SVProgressHUD.dismiss(withDelay: 1)
|
||||||
|
} catch {
|
||||||
|
Utils.alert(title: "Error", message: error.localizedDescription, controller: self, completion: nil)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
optionMenu.addAction(fileAction)
|
optionMenu.addAction(fileAction)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -410,7 +410,6 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
SVProgressHUD.dismiss(withDelay: 0.6)
|
SVProgressHUD.dismiss(withDelay: 0.6)
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
print(error)
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
// remove the wrong passphrase so that users could enter it next time
|
// remove the wrong passphrase so that users could enter it next time
|
||||||
self.passwordStore.pgpKeyPassphrase = nil
|
self.passwordStore.pgpKeyPassphrase = nil
|
||||||
|
|
|
||||||
|
|
@ -80,9 +80,7 @@ class QRScannerController: UIViewController, AVCaptureMetadataOutputObjectsDeleg
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch {
|
} catch {
|
||||||
print(error)
|
|
||||||
scannerOutput.text = error.localizedDescription
|
scannerOutput.text = error.localizedDescription
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,9 +91,9 @@ class SettingsTableViewController: UITableViewController, UITabBarControllerDele
|
||||||
SVProgressHUD.setDefaultMaskType(.black)
|
SVProgressHUD.setDefaultMaskType(.black)
|
||||||
SVProgressHUD.setDefaultStyle(.light)
|
SVProgressHUD.setDefaultStyle(.light)
|
||||||
SVProgressHUD.show(withStatus: "Fetching PGP Key")
|
SVProgressHUD.show(withStatus: "Fetching PGP Key")
|
||||||
passwordStore.pgpKeyImportFromFileSharing()
|
|
||||||
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
||||||
do {
|
do {
|
||||||
|
try self.passwordStore.pgpKeyImportFromFileSharing()
|
||||||
try self.passwordStore.initPGPKeys()
|
try self.passwordStore.initPGPKeys()
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.pgpKeyTableViewCell.detailTextLabel?.text = self.passwordStore.pgpKeyID
|
self.pgpKeyTableViewCell.detailTextLabel?.text = self.passwordStore.pgpKeyID
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,6 @@ class CredentialProviderViewController: ASCredentialProviderViewController, UITa
|
||||||
self.extensionContext.completeRequest(withSelectedCredential: passwordCredential, completionHandler: nil)
|
self.extensionContext.completeRequest(withSelectedCredential: passwordCredential, completionHandler: nil)
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
print(error)
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
// remove the wrong passphrase so that users could enter it next time
|
// remove the wrong passphrase so that users could enter it next time
|
||||||
self.passwordStore.pgpKeyPassphrase = nil
|
self.passwordStore.pgpKeyPassphrase = nil
|
||||||
|
|
|
||||||
|
|
@ -189,7 +189,6 @@ class ExtensionViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
print(error)
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
// remove the wrong passphrase so that users could enter it next time
|
// remove the wrong passphrase so that users could enter it next time
|
||||||
self.passwordStore.pgpKeyPassphrase = nil
|
self.passwordStore.pgpKeyPassphrase = nil
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,7 @@ import KeychainAccess
|
||||||
public class Utils {
|
public class Utils {
|
||||||
public static func getPasswordFromKeychain(name: String) -> String? {
|
public static func getPasswordFromKeychain(name: String) -> String? {
|
||||||
let keychain = Keychain(service: Globals.bundleIdentifier, accessGroup: Globals.groupIdentifier)
|
let keychain = Keychain(service: Globals.bundleIdentifier, accessGroup: Globals.groupIdentifier)
|
||||||
do {
|
return (try? keychain.getString(name)) ?? nil
|
||||||
return try keychain.getString(name)
|
|
||||||
} catch {
|
|
||||||
print(error)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func addPasswordToKeychain(name: String, password: String?) {
|
public static func addPasswordToKeychain(name: String, password: String?) {
|
||||||
|
|
@ -28,20 +23,12 @@ public class Utils {
|
||||||
|
|
||||||
public static func removeKeychain(name: String) {
|
public static func removeKeychain(name: String) {
|
||||||
let keychain = Keychain(service: Globals.bundleIdentifier, accessGroup: Globals.groupIdentifier)
|
let keychain = Keychain(service: Globals.bundleIdentifier, accessGroup: Globals.groupIdentifier)
|
||||||
do {
|
try? keychain.remove(name)
|
||||||
try keychain.remove(name)
|
|
||||||
} catch {
|
|
||||||
print(error)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func removeAllKeychain() {
|
public static func removeAllKeychain() {
|
||||||
let keychain = Keychain(service: Globals.bundleIdentifier, accessGroup: Globals.groupIdentifier)
|
let keychain = Keychain(service: Globals.bundleIdentifier, accessGroup: Globals.groupIdentifier)
|
||||||
do {
|
try? keychain.removeAll()
|
||||||
try keychain.removeAll()
|
|
||||||
} catch {
|
|
||||||
print(error)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public static func copyToPasteboard(textToCopy: String?) {
|
public static func copyToPasteboard(textToCopy: String?) {
|
||||||
guard textToCopy != nil else {
|
guard textToCopy != nil else {
|
||||||
|
|
|
||||||
|
|
@ -528,10 +528,6 @@ public class PasswordStore {
|
||||||
private func gitMv(from: String, to: String) throws {
|
private func gitMv(from: String, to: String) throws {
|
||||||
let fromURL = storeURL.appendingPathComponent(from)
|
let fromURL = storeURL.appendingPathComponent(from)
|
||||||
let toURL = storeURL.appendingPathComponent(to)
|
let toURL = storeURL.appendingPathComponent(to)
|
||||||
guard fm.fileExists(atPath: fromURL.path) else {
|
|
||||||
print("\(from) not exist")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
try fm.moveItem(at: fromURL, to: toURL)
|
try fm.moveItem(at: fromURL, to: toURL)
|
||||||
try gitAdd(path: to)
|
try gitAdd(path: to)
|
||||||
try gitRm(path: from)
|
try gitRm(path: from)
|
||||||
|
|
@ -872,20 +868,12 @@ public class PasswordStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func gitSSHKeyImportFromFileSharing() {
|
public func gitSSHKeyImportFromFileSharing() throws {
|
||||||
do {
|
try fm.moveItem(atPath: Globals.iTunesFileSharingSSHPrivate, toPath: Globals.gitSSHPrivateKeyPath)
|
||||||
try fm.moveItem(atPath: Globals.iTunesFileSharingSSHPrivate, toPath: Globals.gitSSHPrivateKeyPath)
|
|
||||||
} catch {
|
|
||||||
print(error)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func pgpKeyImportFromFileSharing() {
|
public func pgpKeyImportFromFileSharing() throws {
|
||||||
do {
|
try fm.moveItem(atPath: Globals.iTunesFileSharingPGPPublic, toPath: Globals.pgpPublicKeyPath)
|
||||||
try fm.moveItem(atPath: Globals.iTunesFileSharingPGPPublic, toPath: Globals.pgpPublicKeyPath)
|
try fm.moveItem(atPath: Globals.iTunesFileSharingPGPPrivate, toPath: Globals.pgpPrivateKeyPath)
|
||||||
try fm.moveItem(atPath: Globals.iTunesFileSharingPGPPrivate, toPath: Globals.pgpPrivateKeyPath)
|
|
||||||
} catch {
|
|
||||||
print(error)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue