diff --git a/pass/PasswordStore.swift b/pass/PasswordStore.swift index 65be9f4..c441b96 100644 --- a/pass/PasswordStore.swift +++ b/pass/PasswordStore.swift @@ -70,20 +70,14 @@ class PasswordStore { } - func initPGP(pgpKeyURL: URL, pgpKeyLocalPath: String) -> Bool { - do { - let pgpData = try Data(contentsOf: pgpKeyURL) - try pgpData.write(to: URL(fileURLWithPath: pgpKeyLocalPath), options: .atomic) - pgp.importKeys(fromFile: pgpKeyLocalPath, allowDuplicates: false) - let key = pgp.keys[0] - Defaults[.pgpKeyID] = key.keyID!.shortKeyString - if let gpgUser = key.users[0] as? PGPUser { - Defaults[.pgpKeyUserID] = gpgUser.userID - } - return true - } catch { - print("error") - return false + func initPGP(pgpKeyURL: URL, pgpKeyLocalPath: String) throws { + let pgpData = try Data(contentsOf: pgpKeyURL) + try pgpData.write(to: URL(fileURLWithPath: pgpKeyLocalPath), options: .atomic) + pgp.importKeys(fromFile: pgpKeyLocalPath, allowDuplicates: false) + let key = pgp.keys[0] + Defaults[.pgpKeyID] = key.keyID!.shortKeyString + if let gpgUser = key.users[0] as? PGPUser { + Defaults[.pgpKeyUserID] = gpgUser.userID } } diff --git a/pass/SettingsTableViewController.swift b/pass/SettingsTableViewController.swift index 7da381b..f11ff2d 100644 --- a/pass/SettingsTableViewController.swift +++ b/pass/SettingsTableViewController.swift @@ -82,14 +82,17 @@ class SettingsTableViewController: UITableViewController { SVProgressHUD.setDefaultMaskType(.black) SVProgressHUD.show(withStatus: "Fetching PGP Key") DispatchQueue.global(qos: .userInitiated).async { - let ret = PasswordStore.shared.initPGP(pgpKeyURL: Defaults[.pgpKeyURL]!, pgpKeyLocalPath: Globals.shared.secringPath) - - DispatchQueue.main.async { - if ret { + do { + try PasswordStore.shared.initPGP(pgpKeyURL: Defaults[.pgpKeyURL]!, pgpKeyLocalPath: Globals.shared.secringPath) + DispatchQueue.main.async { SVProgressHUD.showSuccess(withStatus: "Success") - } else { - SVProgressHUD.showError(withStatus: "Error") - } + SVProgressHUD.dismiss(withDelay: 1) + } + } catch { + DispatchQueue.main.async { + SVProgressHUD.showError(withStatus: error.localizedDescription) + SVProgressHUD.dismiss(withDelay: 3) + } } } }