2017-02-07 16:45:14 +08:00
|
|
|
//
|
|
|
|
|
// AdvancedSettingsTableViewController.swift
|
|
|
|
|
// pass
|
|
|
|
|
//
|
|
|
|
|
// Created by Mingshen Sun on 7/2/2017.
|
|
|
|
|
// Copyright © 2017 Bob Sun. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import UIKit
|
2017-02-07 16:52:07 +08:00
|
|
|
import SVProgressHUD
|
2017-06-13 11:42:49 +08:00
|
|
|
import passKit
|
2017-02-07 16:45:14 +08:00
|
|
|
|
|
|
|
|
class AdvancedSettingsTableViewController: UITableViewController {
|
|
|
|
|
|
2017-03-23 19:38:43 -07:00
|
|
|
@IBOutlet weak var encryptInASCIIArmoredTableViewCell: UITableViewCell!
|
2017-04-10 23:02:42 +08:00
|
|
|
@IBOutlet weak var gitSignatureTableViewCell: UITableViewCell!
|
2017-02-07 16:45:14 +08:00
|
|
|
@IBOutlet weak var eraseDataTableViewCell: UITableViewCell!
|
2017-03-04 01:15:28 +08:00
|
|
|
@IBOutlet weak var discardChangesTableViewCell: UITableViewCell!
|
2017-03-16 22:39:03 -07:00
|
|
|
let passwordStore = PasswordStore.shared
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2017-03-23 19:38:43 -07:00
|
|
|
let encryptInASCIIArmoredSwitch: UISwitch = {
|
|
|
|
|
let uiSwitch = UISwitch()
|
|
|
|
|
uiSwitch.onTintColor = Globals.blue
|
|
|
|
|
uiSwitch.sizeToFit()
|
2019-05-01 17:49:27 +02:00
|
|
|
uiSwitch.addTarget(self, action: #selector(encryptInASCIIArmoredAction(_:)), for: UIControl.Event.valueChanged)
|
2017-03-23 19:38:43 -07:00
|
|
|
return uiSwitch
|
|
|
|
|
}()
|
2017-03-16 22:39:03 -07:00
|
|
|
|
2017-02-07 16:45:14 +08:00
|
|
|
override func viewDidLoad() {
|
|
|
|
|
super.viewDidLoad()
|
2017-06-13 11:42:49 +08:00
|
|
|
encryptInASCIIArmoredSwitch.isOn = SharedDefaults[.encryptInArmored]
|
2017-03-23 19:38:43 -07:00
|
|
|
encryptInASCIIArmoredTableViewCell.accessoryView = encryptInASCIIArmoredSwitch
|
|
|
|
|
encryptInASCIIArmoredTableViewCell.selectionStyle = .none
|
2017-04-27 21:48:10 -07:00
|
|
|
setGitSignatureText()
|
|
|
|
|
}
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2017-04-27 21:48:10 -07:00
|
|
|
private func setGitSignatureText() {
|
2019-06-09 22:18:54 -07:00
|
|
|
let gitSignatureName = passwordStore.gitSignatureForNow?.name ?? ""
|
|
|
|
|
let gitSignatureEmail = passwordStore.gitSignatureForNow?.email ?? ""
|
2017-04-27 22:48:11 -07:00
|
|
|
self.gitSignatureTableViewCell.detailTextLabel?.font = UIFont.systemFont(ofSize: 14)
|
|
|
|
|
self.gitSignatureTableViewCell.detailTextLabel?.text = "\(gitSignatureName) <\(gitSignatureEmail)>"
|
2017-06-13 11:42:49 +08:00
|
|
|
if SharedDefaults[.gitSignatureName] == nil && SharedDefaults[.gitSignatureEmail] == nil {
|
2017-04-27 22:48:11 -07:00
|
|
|
self.gitSignatureTableViewCell.detailTextLabel?.font = UIFont.systemFont(ofSize: 17)
|
2019-01-14 20:57:45 +01:00
|
|
|
gitSignatureTableViewCell.detailTextLabel?.text = "NotSet".localize()
|
2017-04-10 23:02:42 +08:00
|
|
|
}
|
2017-02-07 16:45:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
2017-03-22 17:50:32 -07:00
|
|
|
tableView.deselectRow(at: indexPath, animated: true)
|
2017-02-07 16:45:14 +08:00
|
|
|
if tableView.cellForRow(at: indexPath) == eraseDataTableViewCell {
|
2019-05-01 17:49:27 +02:00
|
|
|
let alert = UIAlertController(title: "ErasePasswordStoreData?".localize(), message: "EraseExplanation.".localize(), preferredStyle: UIAlertController.Style.alert)
|
|
|
|
|
alert.addAction(UIAlertAction(title: "ErasePasswordStoreData".localize(), style: UIAlertAction.Style.destructive, handler: {[unowned self] (action) -> Void in
|
2019-01-14 20:57:45 +01:00
|
|
|
SVProgressHUD.show(withStatus: "Erasing...".localize())
|
2017-03-16 22:39:03 -07:00
|
|
|
self.passwordStore.erase()
|
2017-02-15 11:15:11 +08:00
|
|
|
self.navigationController!.popViewController(animated: true)
|
2019-01-14 20:57:45 +01:00
|
|
|
SVProgressHUD.showSuccess(withStatus: "Done".localize())
|
2017-02-15 11:15:11 +08:00
|
|
|
SVProgressHUD.dismiss(withDelay: 1)
|
2017-02-07 16:45:14 +08:00
|
|
|
}))
|
2019-05-01 17:49:27 +02:00
|
|
|
alert.addAction(UIAlertAction(title: "Dismiss".localize(), style: UIAlertAction.Style.cancel, handler:nil))
|
2017-02-07 16:45:14 +08:00
|
|
|
self.present(alert, animated: true, completion: nil)
|
2017-03-04 01:15:28 +08:00
|
|
|
} else if tableView.cellForRow(at: indexPath) == discardChangesTableViewCell {
|
2019-05-01 17:49:27 +02:00
|
|
|
let alert = UIAlertController(title: "DiscardAllLocalChanges?".localize(), message: "DiscardExplanation.".localize(), preferredStyle: UIAlertController.Style.alert)
|
|
|
|
|
alert.addAction(UIAlertAction(title: "DiscardAllLocalChanges".localize(), style: UIAlertAction.Style.destructive, handler: {[unowned self] (action) -> Void in
|
2019-01-14 20:57:45 +01:00
|
|
|
SVProgressHUD.show(withStatus: "Resetting...".localize())
|
2017-04-27 21:57:30 -07:00
|
|
|
do {
|
|
|
|
|
let numberDiscarded = try self.passwordStore.reset()
|
|
|
|
|
self.navigationController!.popViewController(animated: true)
|
2019-01-14 20:57:45 +01:00
|
|
|
SVProgressHUD.showSuccess(withStatus: "DiscardedCommits(%d)".localize(numberDiscarded))
|
2017-04-27 21:57:30 -07:00
|
|
|
SVProgressHUD.dismiss(withDelay: 1)
|
|
|
|
|
} catch {
|
2019-01-14 20:57:45 +01:00
|
|
|
Utils.alert(title: "Error".localize(), message: error.localizedDescription, controller: self, completion: nil)
|
2017-03-04 01:15:28 +08:00
|
|
|
}
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2017-03-04 01:15:28 +08:00
|
|
|
}))
|
2019-05-01 17:49:27 +02:00
|
|
|
alert.addAction(UIAlertAction(title: "Dismiss".localize(), style: UIAlertAction.Style.cancel, handler:nil))
|
2017-03-04 01:15:28 +08:00
|
|
|
self.present(alert, animated: true, completion: nil)
|
2017-02-07 16:45:14 +08:00
|
|
|
}
|
|
|
|
|
}
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2017-09-23 16:29:03 +08:00
|
|
|
@objc func encryptInASCIIArmoredAction(_ sender: Any?) {
|
2017-06-13 11:42:49 +08:00
|
|
|
SharedDefaults[.encryptInArmored] = encryptInASCIIArmoredSwitch.isOn
|
2017-03-23 19:38:43 -07:00
|
|
|
}
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2017-04-10 23:02:42 +08:00
|
|
|
@IBAction func saveGitConfigSetting(segue: UIStoryboardSegue) {
|
|
|
|
|
if let controller = segue.source as? GitConfigSettingTableViewController {
|
2017-04-27 22:48:11 -07:00
|
|
|
if let gitSignatureName = controller.nameTextField.text,
|
|
|
|
|
let gitSignatureEmail = controller.emailTextField.text {
|
2017-06-13 11:42:49 +08:00
|
|
|
SharedDefaults[.gitSignatureName] = gitSignatureName.isEmpty ? nil : gitSignatureName
|
|
|
|
|
SharedDefaults[.gitSignatureEmail] = gitSignatureEmail.isEmpty ? nil : gitSignatureEmail
|
2017-04-10 23:02:42 +08:00
|
|
|
}
|
2017-04-27 21:48:10 -07:00
|
|
|
setGitSignatureText()
|
2017-04-10 23:02:42 +08:00
|
|
|
}
|
|
|
|
|
}
|
2017-02-07 16:45:14 +08:00
|
|
|
|
|
|
|
|
}
|