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.
|
|
|
|
|
//
|
|
|
|
|
|
2023-01-26 23:00:32 +08:00
|
|
|
import AuthenticationServices
|
2017-06-13 11:42:49 +08:00
|
|
|
import passKit
|
2020-06-28 21:25:40 +02:00
|
|
|
import SVProgressHUD
|
|
|
|
|
import UIKit
|
2017-02-07 16:45:14 +08:00
|
|
|
|
|
|
|
|
class AdvancedSettingsTableViewController: UITableViewController {
|
2020-06-28 21:25:40 +02:00
|
|
|
@IBOutlet var encryptInASCIIArmoredTableViewCell: UITableViewCell!
|
|
|
|
|
@IBOutlet var gitSignatureTableViewCell: UITableViewCell!
|
|
|
|
|
@IBOutlet var eraseDataTableViewCell: UITableViewCell!
|
|
|
|
|
@IBOutlet var discardChangesTableViewCell: UITableViewCell!
|
2023-01-26 23:00:32 +08:00
|
|
|
@IBOutlet var clearSuggestionsTableViewCell: UITableViewCell!
|
2017-03-16 22:39:03 -07:00
|
|
|
let passwordStore = PasswordStore.shared
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2021-12-27 23:58:02 +01:00
|
|
|
private lazy var encryptInASCIIArmoredSwitch: UISwitch = {
|
2017-03-23 19:38:43 -07:00
|
|
|
let uiSwitch = UISwitch()
|
2019-10-01 22:36:22 +02:00
|
|
|
uiSwitch.onTintColor = Colors.systemBlue
|
2017-03-23 19:38:43 -07:00
|
|
|
uiSwitch.sizeToFit()
|
2021-10-03 05:46:07 +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()
|
2020-01-02 00:48:00 +01:00
|
|
|
encryptInASCIIArmoredSwitch.isOn = Defaults.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 ?? ""
|
2020-06-28 21:25:40 +02:00
|
|
|
gitSignatureTableViewCell.detailTextLabel?.font = UIFont.preferredFont(forTextStyle: .footnote)
|
|
|
|
|
gitSignatureTableViewCell.detailTextLabel?.text = "\(gitSignatureName) <\(gitSignatureEmail)>"
|
|
|
|
|
if Defaults.gitSignatureName == nil, Defaults.gitSignatureEmail == nil {
|
|
|
|
|
gitSignatureTableViewCell.detailTextLabel?.font = UIFont.preferredFont(forTextStyle: .body)
|
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)
|
2020-07-05 00:16:22 +02:00
|
|
|
alert.addAction(
|
2021-12-28 02:57:11 +01:00
|
|
|
UIAlertAction(title: "ErasePasswordStoreData".localize(), style: UIAlertAction.Style.destructive) { [unowned self] _ in
|
2020-07-05 00:16:22 +02:00
|
|
|
SVProgressHUD.show(withStatus: "Erasing...".localize())
|
2023-03-10 06:33:19 +01:00
|
|
|
passwordStore.erase()
|
|
|
|
|
navigationController!.popViewController(animated: true)
|
2020-07-05 00:16:22 +02:00
|
|
|
SVProgressHUD.showSuccess(withStatus: "Done".localize())
|
|
|
|
|
SVProgressHUD.dismiss(withDelay: 1)
|
|
|
|
|
}
|
|
|
|
|
)
|
2020-04-17 23:56:14 -07:00
|
|
|
alert.addAction(UIAlertAction.dismiss())
|
2020-06-28 21:25:40 +02:00
|
|
|
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)
|
2020-07-05 00:16:22 +02:00
|
|
|
alert.addAction(
|
2021-12-28 02:57:11 +01:00
|
|
|
UIAlertAction(title: "DiscardAllLocalChanges".localize(), style: UIAlertAction.Style.destructive) { [unowned self] _ in
|
2020-07-05 00:16:22 +02:00
|
|
|
SVProgressHUD.show(withStatus: "Resetting...".localize())
|
|
|
|
|
do {
|
2023-03-10 06:33:19 +01:00
|
|
|
let numberDiscarded = try passwordStore.reset()
|
|
|
|
|
navigationController!.popViewController(animated: true)
|
2020-07-05 00:16:22 +02:00
|
|
|
SVProgressHUD.showSuccess(withStatus: "DiscardedCommits(%d)".localize(numberDiscarded))
|
|
|
|
|
SVProgressHUD.dismiss(withDelay: 1)
|
|
|
|
|
} catch {
|
|
|
|
|
Utils.alert(title: "Error".localize(), message: error.localizedDescription, controller: self, completion: nil)
|
|
|
|
|
}
|
2017-03-04 01:15:28 +08:00
|
|
|
}
|
2020-07-05 00:16:22 +02:00
|
|
|
)
|
2020-04-17 23:56:14 -07:00
|
|
|
alert.addAction(UIAlertAction.dismiss())
|
2020-06-28 21:25:40 +02:00
|
|
|
present(alert, animated: true, completion: nil)
|
2023-01-26 23:00:32 +08:00
|
|
|
} else if tableView.cellForRow(at: indexPath) == clearSuggestionsTableViewCell {
|
|
|
|
|
ASCredentialIdentityStore.shared.removeAllCredentialIdentities { _, error in
|
2023-04-23 22:01:37 +02:00
|
|
|
if let error {
|
2023-01-26 23:00:32 +08:00
|
|
|
SVProgressHUD.showError(withStatus: "FailedToClearQuickTypeSuggestions".localize(error))
|
|
|
|
|
SVProgressHUD.dismiss(withDelay: 1)
|
|
|
|
|
} else {
|
|
|
|
|
SVProgressHUD.showSuccess(withStatus: "Done".localize())
|
|
|
|
|
SVProgressHUD.dismiss(withDelay: 1)
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-07 16:45:14 +08:00
|
|
|
}
|
|
|
|
|
}
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2021-01-31 13:17:37 +01:00
|
|
|
override func tableView(_: UITableView, heightForRowAt _: IndexPath) -> CGFloat {
|
2021-01-05 23:27:35 -08:00
|
|
|
UITableView.automaticDimension
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-31 13:17:37 +01:00
|
|
|
override func tableView(_: UITableView, estimatedHeightForRowAt _: IndexPath) -> CGFloat {
|
2021-01-05 23:27:35 -08:00
|
|
|
UITableView.automaticDimension
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-28 21:25:40 +02:00
|
|
|
@objc
|
|
|
|
|
func encryptInASCIIArmoredAction(_: Any?) {
|
2020-01-02 00:48:00 +01:00
|
|
|
Defaults.encryptInArmored = encryptInASCIIArmoredSwitch.isOn
|
2017-03-23 19:38:43 -07:00
|
|
|
}
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2020-06-28 21:25:40 +02:00
|
|
|
@IBAction
|
2020-07-05 22:49:53 +02:00
|
|
|
private func saveGitConfigSetting(segue: UIStoryboardSegue) {
|
2020-02-12 23:28:04 +01:00
|
|
|
if let controller = segue.source as? GitConfigSettingsTableViewController {
|
2017-04-27 22:48:11 -07:00
|
|
|
if let gitSignatureName = controller.nameTextField.text,
|
2020-11-07 12:06:28 +01:00
|
|
|
let gitSignatureEmail = controller.emailTextField.text {
|
2020-01-02 00:48:00 +01:00
|
|
|
Defaults.gitSignatureName = gitSignatureName.isEmpty ? nil : gitSignatureName
|
|
|
|
|
Defaults.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
|
|
|
}
|