Add switch to turn on/off remembering passphrase

If the switch is on, users need  to type passphrase of secret key once. The key will be stored in the Keychain.

If the switch is off, users have to fill in passphrase for each decryption including show password detail and long press to copy.
This commit is contained in:
Bob Sun 2017-02-28 12:25:52 +08:00
parent 1c45766b96
commit fa512e6c86
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
10 changed files with 138 additions and 37 deletions

View file

@ -11,7 +11,21 @@ import SwiftyUserDefaults
class GeneralSettingsTableViewController: BasicStaticTableViewController {
let hideUnknownSwitch = UISwitch()
let hideUnknownSwitch: UISwitch = {
let uiSwitch = UISwitch()
uiSwitch.onTintColor = Globals.blue
uiSwitch.sizeToFit()
uiSwitch.addTarget(self, action: #selector(hideUnknownSwitchAction(_:)), for: UIControlEvents.valueChanged)
return uiSwitch
}()
let rememberPassphraseSwitch: UISwitch = {
let uiSwitch = UISwitch()
uiSwitch.onTintColor = Globals.blue
uiSwitch.sizeToFit()
uiSwitch.addTarget(self, action: #selector(rememberPassphraseSwitchAction(_:)), for: UIControlEvents.valueChanged)
uiSwitch.isOn = Defaults[.isRememberPassphraseOn]
return uiSwitch
}()
override func viewDidLoad() {
navigationItemTitle = "General"
@ -20,7 +34,10 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
[[.title: "About Repository", .action: "segue", .link: "showAboutRepositorySegue"],],
// section 1
[[.title: "Hide Unknown Fields", .action: "none",],],
[
[.title: "Remember Phassphrase", .action: "none",],
[.title: "Hide Unknown Fields", .action: "none",],
],
]
super.viewDidLoad()
@ -31,8 +48,6 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
let cell = super.tableView(tableView, cellForRowAt: indexPath)
if cell.textLabel?.text == "Hide Unknown Fields" {
cell.accessoryType = .none
hideUnknownSwitch.onTintColor = UIColor(displayP3Red: 0, green: 122.0/255, blue: 1, alpha: 1)
hideUnknownSwitch.sizeToFit()
let detailButton = UIButton(type: .detailDisclosure)
hideUnknownSwitch.frame = CGRect(x: detailButton.bounds.width+10, y: 0, width: hideUnknownSwitch.bounds.width, height: hideUnknownSwitch.bounds.height)
detailButton.frame = CGRect(x: 0, y: 5, width: detailButton.bounds.width, height: detailButton.bounds.height)
@ -42,8 +57,11 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
accessoryView.addSubview(hideUnknownSwitch)
cell.accessoryView = accessoryView
cell.selectionStyle = .none
hideUnknownSwitch.addTarget(self, action: #selector(hideUnknownSwitchAction(_:)), for: UIControlEvents.valueChanged)
hideUnknownSwitch.isOn = Defaults[.isHideUnknownOn]
} else if cell.textLabel?.text == "Remember Phassphrase" {
cell.accessoryType = .none
cell.selectionStyle = .none
cell.accessoryView = rememberPassphraseSwitch
}
return cell
}
@ -58,4 +76,11 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
Defaults[.isHideUnknownOn] = hideUnknownSwitch.isOn
}
func rememberPassphraseSwitchAction(_ sender: Any?) {
Defaults[.isRememberPassphraseOn] = rememberPassphraseSwitch.isOn
if rememberPassphraseSwitch.isOn == false {
PasswordStore.shared.pgpKeyPassphrase = nil
}
}
}