Move codes to an embed framework

- Move bundle/group identifiers to passKit/Global
- Fix Core Data
- Change Defaults to SharedDefaults
This commit is contained in:
Yishi Lin 2017-06-13 11:42:49 +08:00
parent 850dc75820
commit d2ba620ae4
45 changed files with 1062 additions and 523 deletions

View file

@ -7,6 +7,7 @@
//
import UIKit
import passKit
class AboutRepositoryTableViewController: BasicStaticTableViewController {

View file

@ -7,7 +7,7 @@
//
import UIKit
import SwiftyUserDefaults
import passKit
class AddPasswordTableViewController: PasswordEditorTableViewController {
var tempContent: String = ""
@ -20,7 +20,7 @@ class AddPasswordTableViewController: PasswordEditorTableViewController {
[[.type: PasswordEditorCellType.additionsCell, .title: "additions"]],
[[.type: PasswordEditorCellType.scanQRCodeCell]]
]
if let lengthSetting = Globals.passwordDefaultLength[Defaults[.passwordGeneratorFlavor]],
if let lengthSetting = Globals.passwordDefaultLength[SharedDefaults[.passwordGeneratorFlavor]],
lengthSetting.max > lengthSetting.min {
tableData[1].append([.type: PasswordEditorCellType.passwordLengthCell, .title: "passwordlength"])
}

View file

@ -8,7 +8,7 @@
import UIKit
import SVProgressHUD
import SwiftyUserDefaults
import passKit
class AdvancedSettingsTableViewController: UITableViewController {
@ -28,7 +28,7 @@ class AdvancedSettingsTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
encryptInASCIIArmoredSwitch.isOn = Defaults[.encryptInArmored]
encryptInASCIIArmoredSwitch.isOn = SharedDefaults[.encryptInArmored]
encryptInASCIIArmoredTableViewCell.accessoryView = encryptInASCIIArmoredSwitch
encryptInASCIIArmoredTableViewCell.selectionStyle = .none
setGitSignatureText()
@ -39,7 +39,7 @@ class AdvancedSettingsTableViewController: UITableViewController {
let gitSignatureEmail = passwordStore.gitSignatureForNow.email!
self.gitSignatureTableViewCell.detailTextLabel?.font = UIFont.systemFont(ofSize: 14)
self.gitSignatureTableViewCell.detailTextLabel?.text = "\(gitSignatureName) <\(gitSignatureEmail)>"
if Defaults[.gitSignatureName] == nil && Defaults[.gitSignatureEmail] == nil {
if SharedDefaults[.gitSignatureName] == nil && SharedDefaults[.gitSignatureEmail] == nil {
self.gitSignatureTableViewCell.detailTextLabel?.font = UIFont.systemFont(ofSize: 17)
gitSignatureTableViewCell.detailTextLabel?.text = "Not Set"
}
@ -85,7 +85,7 @@ class AdvancedSettingsTableViewController: UITableViewController {
}
func encryptInASCIIArmoredAction(_ sender: Any?) {
Defaults[.encryptInArmored] = encryptInASCIIArmoredSwitch.isOn
SharedDefaults[.encryptInArmored] = encryptInASCIIArmoredSwitch.isOn
}
@IBAction func cancelGitConfigSetting(segue: UIStoryboardSegue) {
@ -95,8 +95,8 @@ class AdvancedSettingsTableViewController: UITableViewController {
if let controller = segue.source as? GitConfigSettingTableViewController {
if let gitSignatureName = controller.nameTextField.text,
let gitSignatureEmail = controller.emailTextField.text {
Defaults[.gitSignatureName] = gitSignatureName.isEmpty ? nil : gitSignatureName
Defaults[.gitSignatureEmail] = gitSignatureEmail.isEmpty ? nil : gitSignatureEmail
SharedDefaults[.gitSignatureName] = gitSignatureName.isEmpty ? nil : gitSignatureName
SharedDefaults[.gitSignatureEmail] = gitSignatureEmail.isEmpty ? nil : gitSignatureEmail
}
setGitSignatureText()
}

View file

@ -9,6 +9,7 @@
import UIKit
import SafariServices
import MessageUI
import passKit
enum CellDataType {

View file

@ -8,6 +8,7 @@
import UIKit
import ObjectiveGit
import passKit
class CommitLogsTableViewController: UITableViewController {
var commits: [GTCommit] = []

View file

@ -7,7 +7,7 @@
//
import UIKit
import SwiftyUserDefaults
import passKit
class EditPasswordTableViewController: PasswordEditorTableViewController {
override func viewDidLoad() {
@ -18,7 +18,7 @@ class EditPasswordTableViewController: PasswordEditorTableViewController {
[[.type: PasswordEditorCellType.scanQRCodeCell],
[.type: PasswordEditorCellType.deletePasswordCell]]
]
if let lengthSetting = Globals.passwordDefaultLength[Defaults[.passwordGeneratorFlavor]],
if let lengthSetting = Globals.passwordDefaultLength[SharedDefaults[.passwordGeneratorFlavor]],
lengthSetting.max > lengthSetting.min {
tableData[1].append([.type: PasswordEditorCellType.passwordLengthCell, .title: "passwordlength"])
}

View file

@ -7,7 +7,7 @@
//
import UIKit
import SwiftyUserDefaults
import passKit
class GeneralSettingsTableViewController: BasicStaticTableViewController {
let passwordStore = PasswordStore.shared
@ -33,7 +33,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
uiSwitch.onTintColor = Globals.blue
uiSwitch.sizeToFit()
uiSwitch.addTarget(self, action: #selector(rememberPassphraseSwitchAction(_:)), for: UIControlEvents.valueChanged)
uiSwitch.isOn = Defaults[.isRememberPassphraseOn]
uiSwitch.isOn = SharedDefaults[.isRememberPassphraseOn]
return uiSwitch
}()
@ -42,7 +42,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
uiSwitch.onTintColor = Globals.blue
uiSwitch.sizeToFit()
uiSwitch.addTarget(self, action: #selector(showFolderSwitchAction(_:)), for: UIControlEvents.valueChanged)
uiSwitch.isOn = Defaults[.isShowFolderOn]
uiSwitch.isOn = SharedDefaults[.isShowFolderOn]
return uiSwitch
}()
@ -85,7 +85,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
accessoryView.addSubview(hideUnknownSwitch)
cell.accessoryView = accessoryView
cell.selectionStyle = .none
hideUnknownSwitch.isOn = Defaults[.isHideUnknownOn]
hideUnknownSwitch.isOn = SharedDefaults[.isHideUnknownOn]
case "Hide OTP Fields":
cell.accessoryType = .none
let detailButton = UIButton(type: .detailDisclosure)
@ -97,7 +97,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
accessoryView.addSubview(hideOTPSwitch)
cell.accessoryView = accessoryView
cell.selectionStyle = .none
hideOTPSwitch.isOn = Defaults[.isHideOTPOn]
hideOTPSwitch.isOn = SharedDefaults[.isHideOTPOn]
case "Remember Passphrase":
cell.accessoryType = .none
cell.selectionStyle = .none
@ -108,7 +108,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
cell.accessoryView = showFolderSwitch
case "Password Generator Flavor":
cell.accessoryType = .disclosureIndicator
cell.detailTextLabel?.text = Defaults[.passwordGeneratorFlavor]
cell.detailTextLabel?.text = SharedDefaults[.passwordGeneratorFlavor]
default: break
}
return cell
@ -127,7 +127,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
var randomFlavorActionTitle = ""
var appleFlavorActionTitle = ""
if Defaults[.passwordGeneratorFlavor] == "Random" {
if SharedDefaults[.passwordGeneratorFlavor] == "Random" {
randomFlavorActionTitle = "✓ Random String"
appleFlavorActionTitle = "Apple's Keychain Style"
} else {
@ -135,12 +135,12 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
appleFlavorActionTitle = "✓ Apple's Keychain Style"
}
let randomFlavorAction = UIAlertAction(title: randomFlavorActionTitle, style: .default) { _ in
Defaults[.passwordGeneratorFlavor] = "Random"
SharedDefaults[.passwordGeneratorFlavor] = "Random"
sourceCell.detailTextLabel?.text = "Random"
}
let appleFlavorAction = UIAlertAction(title: appleFlavorActionTitle, style: .default) { _ in
Defaults[.passwordGeneratorFlavor] = "Apple"
SharedDefaults[.passwordGeneratorFlavor] = "Apple"
sourceCell.detailTextLabel?.text = "Apple"
}
@ -167,24 +167,24 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
}
func hideUnknownSwitchAction(_ sender: Any?) {
Defaults[.isHideUnknownOn] = hideUnknownSwitch.isOn
SharedDefaults[.isHideUnknownOn] = hideUnknownSwitch.isOn
NotificationCenter.default.post(name: .passwordDetailDisplaySettingChanged, object: nil)
}
func hideOTPSwitchAction(_ sender: Any?) {
Defaults[.isHideOTPOn] = hideOTPSwitch.isOn
SharedDefaults[.isHideOTPOn] = hideOTPSwitch.isOn
NotificationCenter.default.post(name: .passwordDetailDisplaySettingChanged, object: nil)
}
func rememberPassphraseSwitchAction(_ sender: Any?) {
Defaults[.isRememberPassphraseOn] = rememberPassphraseSwitch.isOn
SharedDefaults[.isRememberPassphraseOn] = rememberPassphraseSwitch.isOn
if rememberPassphraseSwitch.isOn == false {
passwordStore.pgpKeyPassphrase = nil
}
}
func showFolderSwitchAction(_ sender: Any?) {
Defaults[.isShowFolderOn] = showFolderSwitch.isOn
SharedDefaults[.isShowFolderOn] = showFolderSwitch.isOn
NotificationCenter.default.post(name: .passwordDisplaySettingChanged, object: nil)
}

View file

@ -8,6 +8,7 @@
import UIKit
import SwiftyUserDefaults
import passKit
class GitConfigSettingTableViewController: UITableViewController {
let passwordStore = PasswordStore.shared
@ -22,8 +23,8 @@ class GitConfigSettingTableViewController: UITableViewController {
let signature = passwordStore.gitSignatureForNow
nameTextField.placeholder = signature.name
emailTextField.placeholder = signature.email
nameTextField.text = Defaults[.gitSignatureName]
emailTextField.text = Defaults[.gitSignatureEmail]
nameTextField.text = SharedDefaults[.gitSignatureName]
emailTextField.text = SharedDefaults[.gitSignatureEmail]
}
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {

View file

@ -7,7 +7,7 @@
//
import UIKit
import SwiftyUserDefaults
import passKit
class GitSSHKeyArmorSettingTableViewController: UITableViewController, UITextViewDelegate, QRScannerControllerDelegate {
@IBOutlet weak var armorPrivateKeyTextView: UITextView!
@ -73,7 +73,7 @@ class GitSSHKeyArmorSettingTableViewController: UITableViewController, UITextVie
override func viewDidLoad() {
super.viewDidLoad()
armorPrivateKeyTextView.text = Defaults[.gitSSHPrivateKeyArmor]
armorPrivateKeyTextView.text = SharedDefaults[.gitSSHPrivateKeyArmor]
armorPrivateKeyTextView.delegate = self
scanPrivateKeyCell?.textLabel?.text = "Scan Private Key QR Codes"
@ -83,13 +83,13 @@ class GitSSHKeyArmorSettingTableViewController: UITableViewController, UITextVie
}
@IBAction func doneButtonTapped(_ sender: Any) {
Defaults[.gitSSHPrivateKeyArmor] = armorPrivateKeyTextView.text
SharedDefaults[.gitSSHPrivateKeyArmor] = armorPrivateKeyTextView.text
do {
try passwordStore.initGitSSHKey(with: armorPrivateKeyTextView.text, .secret)
try passwordStore.initGitSSHKey(with: armorPrivateKeyTextView.text)
} catch {
Utils.alert(title: "Cannot Save", message: "Cannot Save SSH Key", controller: self, completion: nil)
}
Defaults[.gitSSHKeySource] = "armor"
SharedDefaults[.gitSSHKeySource] = "armor"
self.navigationController!.popViewController(animated: true)
}

View file

@ -7,8 +7,8 @@
//
import UIKit
import SwiftyUserDefaults
import SVProgressHUD
import passKit
class GitServerSettingTableViewController: UITableViewController {
@ -19,7 +19,7 @@ class GitServerSettingTableViewController: UITableViewController {
let passwordStore = PasswordStore.shared
var sshLabel: UILabel? = nil
var authenticationMethod = Defaults[.gitAuthenticationMethod] ?? "Password"
var authenticationMethod = SharedDefaults[.gitAuthenticationMethod] ?? "Password"
private func checkAuthenticationMethod(method: String) {
let passwordCheckView = authPasswordCell.viewWithTag(1001)!
@ -47,10 +47,10 @@ class GitServerSettingTableViewController: UITableViewController {
}
override func viewDidLoad() {
super.viewDidLoad()
if let url = Defaults[.gitURL] {
if let url = SharedDefaults[.gitURL] {
gitURLTextField.text = url.absoluteString
}
usernameTextField.text = Defaults[.gitUsername]
usernameTextField.text = SharedDefaults[.gitUsername]
sshLabel = authSSHKeyCell.subviews[0].subviews[0] as? UILabel
checkAuthenticationMethod(method: authenticationMethod)
authSSHKeyCell.accessoryType = .detailButton
@ -110,9 +110,9 @@ class GitServerSettingTableViewController: UITableViewController {
}
})
DispatchQueue.main.async {
Defaults[.gitURL] = URL(string: gitRepostiroyURL)
Defaults[.gitUsername] = username
Defaults[.gitAuthenticationMethod] = auth
SharedDefaults[.gitURL] = URL(string: gitRepostiroyURL)
SharedDefaults[.gitUsername] = username
SharedDefaults[.gitAuthenticationMethod] = auth
SVProgressHUD.showSuccess(withStatus: "Done")
SVProgressHUD.dismiss(withDelay: 1)
self.performSegue(withIdentifier: "saveGitServerSettingSegue", sender: self)
@ -167,11 +167,11 @@ class GitServerSettingTableViewController: UITableViewController {
var armorActionTitle = "ASCII-Armor Encrypted Key"
var fileActionTitle = "Use Imported Keys"
if Defaults[.gitSSHKeySource] == "url" {
if SharedDefaults[.gitSSHKeySource] == "url" {
urlActionTitle = "\(urlActionTitle)"
} else if Defaults[.gitSSHKeySource] == "armor" {
} else if SharedDefaults[.gitSSHKeySource] == "armor" {
armorActionTitle = "\(armorActionTitle)"
} else if Defaults[.gitSSHKeySource] == "file" {
} else if SharedDefaults[.gitSSHKeySource] == "file" {
fileActionTitle = "\(fileActionTitle)"
}
let urlAction = UIAlertAction(title: urlActionTitle, style: .default) { _ in
@ -187,7 +187,7 @@ class GitServerSettingTableViewController: UITableViewController {
if passwordStore.gitSSHKeyExists() {
// might keys updated via iTunes, or downloaded/pasted inside the app
let fileAction = UIAlertAction(title: fileActionTitle, style: .default) { _ in
Defaults[.gitSSHKeySource] = "file"
SharedDefaults[.gitSSHKeySource] = "file"
}
optionMenu.addAction(fileAction)
} else {
@ -199,10 +199,10 @@ class GitServerSettingTableViewController: UITableViewController {
optionMenu.addAction(fileAction)
}
if Defaults[.gitSSHKeySource] != nil {
if SharedDefaults[.gitSSHKeySource] != nil {
let deleteAction = UIAlertAction(title: "Remove Git SSH Keys", style: .destructive) { _ in
self.passwordStore.removeGitSSHKeys()
Defaults[.gitSSHKeySource] = nil
SharedDefaults[.gitSSHKeySource] = nil
if let sshLabel = self.sshLabel {
sshLabel.isEnabled = false
self.checkAuthenticationMethod(method: "Password")

View file

@ -8,6 +8,7 @@
import UIKit
import AVFoundation
import passKit
class OTPScannerController: QRScannerController {

View file

@ -7,7 +7,7 @@
//
import UIKit
import SwiftyUserDefaults
import passKit
class PGPKeyArmorSettingTableViewController: UITableViewController, UITextViewDelegate, QRScannerControllerDelegate {
@IBOutlet weak var armorPublicKeyTextView: UITextView!
@ -92,8 +92,8 @@ class PGPKeyArmorSettingTableViewController: UITableViewController, UITextViewDe
override func viewDidLoad() {
super.viewDidLoad()
armorPublicKeyTextView.text = Defaults[.pgpPublicKeyArmor]
armorPrivateKeyTextView.text = Defaults[.pgpPrivateKeyArmor]
armorPublicKeyTextView.text = SharedDefaults[.pgpPublicKeyArmor]
armorPrivateKeyTextView.text = SharedDefaults[.pgpPrivateKeyArmor]
pgpPassphrase = passwordStore.pgpKeyPassphrase
scanPublicKeyCell?.textLabel?.text = "Scan Public Key QR Codes"
@ -126,7 +126,7 @@ class PGPKeyArmorSettingTableViewController: UITableViewController, UITextViewDe
// no
savePassphraseAlert.addAction(UIAlertAction(title: "No", style: UIAlertActionStyle.default) { _ in
self.pgpPassphrase = nil
Defaults[.isRememberPassphraseOn] = false
SharedDefaults[.isRememberPassphraseOn] = false
self.performSegue(withIdentifier: "savePGPKeySegue", sender: self)
})
// yes
@ -135,7 +135,7 @@ class PGPKeyArmorSettingTableViewController: UITableViewController, UITextViewDe
let alert = UIAlertController(title: "Passphrase", message: "Please fill in the passphrase of your PGP secret key.", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: {_ in
self.pgpPassphrase = alert.textFields?.first?.text
Defaults[.isRememberPassphraseOn] = true
SharedDefaults[.isRememberPassphraseOn] = true
self.performSegue(withIdentifier: "savePGPKeySegue", sender: self)
}))
alert.addTextField(configurationHandler: {(textField: UITextField!) in

View file

@ -7,7 +7,7 @@
//
import UIKit
import SwiftyUserDefaults
import passKit
class PGPKeySettingTableViewController: UITableViewController {
@ -19,8 +19,8 @@ class PGPKeySettingTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
tableView.rowHeight = UITableViewAutomaticDimension
pgpPublicKeyURLTextField.text = Defaults[.pgpPublicKeyURL]?.absoluteString
pgpPrivateKeyURLTextField.text = Defaults[.pgpPrivateKeyURL]?.absoluteString
pgpPublicKeyURLTextField.text = SharedDefaults[.pgpPublicKeyURL]?.absoluteString
pgpPrivateKeyURLTextField.text = SharedDefaults[.pgpPrivateKeyURL]?.absoluteString
pgpPassphrase = passwordStore.pgpKeyPassphrase
}
@ -51,7 +51,7 @@ class PGPKeySettingTableViewController: UITableViewController {
// no
savePassphraseAlert.addAction(UIAlertAction(title: "No", style: UIAlertActionStyle.default) { _ in
self.pgpPassphrase = nil
Defaults[.isRememberPassphraseOn] = false
SharedDefaults[.isRememberPassphraseOn] = false
self.performSegue(withIdentifier: "savePGPKeySegue", sender: self)
})
// yes
@ -60,7 +60,7 @@ class PGPKeySettingTableViewController: UITableViewController {
let alert = UIAlertController(title: "Passphrase", message: "Please fill in the passphrase of your PGP secret key.", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: {_ in
self.pgpPassphrase = alert.textFields?.first?.text
Defaults[.isRememberPassphraseOn] = true
SharedDefaults[.isRememberPassphraseOn] = true
self.performSegue(withIdentifier: "savePGPKeySegue", sender: self)
}))
alert.addTextField(configurationHandler: {(textField: UITextField!) in

View file

@ -8,8 +8,8 @@
import UIKit
import FavIcon
import SwiftyUserDefaults
import SVProgressHUD
import passKit
class PasswordDetailTableViewController: UITableViewController, UIGestureRecognizerDelegate {
var passwordEntity: PasswordEntity?
@ -134,7 +134,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
self.present(alert, animated: true, completion: nil)
}
let _ = sem.wait(timeout: DispatchTime.distantFuture)
if Defaults[.isRememberPassphraseOn] {
if SharedDefaults[.isRememberPassphraseOn] {
self.passwordStore.pgpKeyPassphrase = passphrase
}
return passphrase
@ -281,8 +281,8 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
let filteredAdditionKeys = password.additionKeys.filter {
$0.lowercased() != "username" &&
$0.lowercased() != "password" &&
(!$0.hasPrefix("unknown") || !Defaults[.isHideUnknownOn]) &&
(!Password.otpKeywords.contains($0) || !Defaults[.isHideOTPOn]) }
(!$0.hasPrefix("unknown") || !SharedDefaults[.isHideUnknownOn]) &&
(!Password.otpKeywords.contains($0) || !SharedDefaults[.isHideOTPOn]) }
if filteredAdditionKeys.count > 0 {
section = TableSection(type: .addition, header: "additions")

View file

@ -7,8 +7,8 @@
//
import UIKit
import SwiftyUserDefaults
import OneTimePassword
import passKit
enum PasswordEditorCellType {
case nameCell, fillPasswordCell, passwordLengthCell, additionsCell, deletePasswordCell, scanQRCodeCell
@ -95,7 +95,7 @@ class PasswordEditorTableViewController: UITableViewController, FillPasswordTabl
return fillPasswordCell!
case .passwordLengthCell:
passwordLengthCell = tableView.dequeueReusableCell(withIdentifier: "passwordLengthCell", for: indexPath) as? SliderTableViewCell
let lengthSetting = Globals.passwordDefaultLength[Defaults[.passwordGeneratorFlavor]] ??
let lengthSetting = Globals.passwordDefaultLength[SharedDefaults[.passwordGeneratorFlavor]] ??
Globals.passwordDefaultLength["Random"]
passwordLengthCell?.reset(title: "Length",
minimumValue: lengthSetting?.min ?? 0,

View file

@ -8,8 +8,7 @@
import UIKit
import SVProgressHUD
import SwiftyUserDefaults
import PasscodeLock
import passKit
fileprivate class PasswordsTableEntry : NSObject {
var title: String
@ -87,7 +86,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
filteredPasswordsTableEntries.removeAll()
var passwordEntities = [PasswordEntity]()
var passwordAllEntities = [PasswordEntity]()
if Defaults[.isShowFolderOn] {
if SharedDefaults[.isShowFolderOn] {
passwordEntities = self.passwordStore.fetchPasswordEntityCoreData(parent: parent)
} else {
passwordEntities = self.passwordStore.fetchPasswordEntityCoreData(withDir: false)
@ -139,12 +138,12 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
SVProgressHUD.show(withStatus: "Sync Password Store")
let numberOfLocalCommits = self.passwordStore.numberOfLocalCommits()
var gitCredential: GitCredential
if Defaults[.gitAuthenticationMethod] == "Password" {
gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: Defaults[.gitUsername]!, controller: self))
if SharedDefaults[.gitAuthenticationMethod] == "Password" {
gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: SharedDefaults[.gitUsername]!, controller: self))
} else {
gitCredential = GitCredential(
credential: GitCredential.Credential.ssh(
userName: Defaults[.gitUsername]!,
userName: SharedDefaults[.gitUsername]!,
privateKeyFile: Globals.gitSSHPrivateKeyURL,
controller: self
)
@ -184,7 +183,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if Defaults[.isShowFolderOn] {
if SharedDefaults[.isShowFolderOn] {
searchController.searchBar.scopeButtonTitles = ["Current", "All"]
} else {
searchController.searchBar.scopeButtonTitles = nil
@ -238,7 +237,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longPressAction(_:)))
longPressGestureRecognizer.minimumPressDuration = 0.6
if Defaults[.isShowFolderOn] && searchController.searchBar.selectedScopeButtonIndex == 0{
if SharedDefaults[.isShowFolderOn] && searchController.searchBar.selectedScopeButtonIndex == 0{
let cell = tableView.dequeueReusableCell(withIdentifier: "passwordTableViewCell", for: indexPath)
let entry = getPasswordEntry(by: indexPath)
@ -296,7 +295,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
}
func backAction(_ sender: Any?) {
guard Defaults[.isShowFolderOn] else { return }
guard SharedDefaults[.isShowFolderOn] else { return }
var anim: CATransition? = transitionFromLeft
if parentPasswordEntity == nil {
anim = nil
@ -363,7 +362,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
// bring back
SVProgressHUD.show(withStatus: "Decrypting")
}
if Defaults[.isRememberPassphraseOn] {
if SharedDefaults[.isRememberPassphraseOn] {
self.passwordStore.pgpKeyPassphrase = passphrase
}
return passphrase

View file

@ -7,6 +7,7 @@
//
import UIKit
import passKit
class RawPasswordViewController: UIViewController {

View file

@ -7,8 +7,8 @@
//
import UIKit
import SwiftyUserDefaults
import SVProgressHUD
import passKit
class SSHKeySettingTableViewController: UITableViewController {
@ -17,7 +17,7 @@ class SSHKeySettingTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
privateKeyURLTextField.text = Defaults[.gitSSHPrivateKeyURL]?.absoluteString
privateKeyURLTextField.text = SharedDefaults[.gitSSHPrivateKeyURL]?.absoluteString
}
@ -27,14 +27,14 @@ class SSHKeySettingTableViewController: UITableViewController {
return
}
Defaults[.gitSSHPrivateKeyURL] = privateKeyURL
SharedDefaults[.gitSSHPrivateKeyURL] = privateKeyURL
do {
try Data(contentsOf: privateKeyURL).write(to: URL(fileURLWithPath: Globals.gitSSHPrivateKeyPath), options: .atomic)
} catch {
Utils.alert(title: "Error", message: error.localizedDescription, controller: self, completion: nil)
}
Defaults[.gitSSHKeySource] = "url"
SharedDefaults[.gitSSHKeySource] = "url"
self.navigationController!.popViewController(animated: true)
}

View file

@ -9,9 +9,9 @@
import UIKit
import SVProgressHUD
import CoreData
import SwiftyUserDefaults
import PasscodeLock
import LocalAuthentication
import passKit
class SettingsTableViewController: UITableViewController {
@ -27,26 +27,27 @@ class SettingsTableViewController: UITableViewController {
@IBOutlet weak var passcodeTableViewCell: UITableViewCell!
@IBOutlet weak var passwordRepositoryTableViewCell: UITableViewCell!
let passwordStore = PasswordStore.shared
var passcodeLockConfig = PasscodeLockConfiguration.shared
@IBAction func cancelPGPKey(segue: UIStoryboardSegue) {
}
@IBAction func savePGPKey(segue: UIStoryboardSegue) {
if let controller = segue.source as? PGPKeySettingTableViewController {
Defaults[.pgpPrivateKeyURL] = URL(string: controller.pgpPrivateKeyURLTextField.text!)
Defaults[.pgpPublicKeyURL] = URL(string: controller.pgpPublicKeyURLTextField.text!)
if Defaults[.isRememberPassphraseOn] {
SharedDefaults[.pgpPrivateKeyURL] = URL(string: controller.pgpPrivateKeyURLTextField.text!)
SharedDefaults[.pgpPublicKeyURL] = URL(string: controller.pgpPublicKeyURLTextField.text!)
if SharedDefaults[.isRememberPassphraseOn] {
self.passwordStore.pgpKeyPassphrase = controller.pgpPassphrase
}
Defaults[.pgpKeySource] = "url"
SharedDefaults[.pgpKeySource] = "url"
SVProgressHUD.setDefaultMaskType(.black)
SVProgressHUD.setDefaultStyle(.light)
SVProgressHUD.show(withStatus: "Fetching PGP Key")
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
do {
try self.passwordStore.initPGPKey(from: Defaults[.pgpPublicKeyURL]!, keyType: .public)
try self.passwordStore.initPGPKey(from: Defaults[.pgpPrivateKeyURL]!, keyType: .secret)
try self.passwordStore.initPGPKey(from: SharedDefaults[.pgpPublicKeyURL]!, keyType: .public)
try self.passwordStore.initPGPKey(from: SharedDefaults[.pgpPrivateKeyURL]!, keyType: .secret)
DispatchQueue.main.async {
self.pgpKeyTableViewCell.detailTextLabel?.text = self.passwordStore.pgpKeyID
SVProgressHUD.showSuccess(withStatus: "Success")
@ -62,13 +63,13 @@ class SettingsTableViewController: UITableViewController {
}
} else if let controller = segue.source as? PGPKeyArmorSettingTableViewController {
Defaults[.pgpKeySource] = "armor"
if Defaults[.isRememberPassphraseOn] {
SharedDefaults[.pgpKeySource] = "armor"
if SharedDefaults[.isRememberPassphraseOn] {
self.passwordStore.pgpKeyPassphrase = controller.pgpPassphrase
}
Defaults[.pgpPublicKeyArmor] = controller.armorPublicKeyTextView.text!
Defaults[.pgpPrivateKeyArmor] = controller.armorPrivateKeyTextView.text!
SharedDefaults[.pgpPublicKeyArmor] = controller.armorPublicKeyTextView.text!
SharedDefaults[.pgpPrivateKeyArmor] = controller.armorPrivateKeyTextView.text!
SVProgressHUD.setDefaultMaskType(.black)
SVProgressHUD.setDefaultStyle(.light)
@ -94,7 +95,7 @@ class SettingsTableViewController: UITableViewController {
private func saveImportedPGPKey() {
// load keys
Defaults[.pgpKeySource] = "file"
SharedDefaults[.pgpKeySource] = "file"
SVProgressHUD.setDefaultMaskType(.black)
SVProgressHUD.setDefaultStyle(.light)
@ -120,7 +121,7 @@ class SettingsTableViewController: UITableViewController {
}
@IBAction func saveGitServerSetting(segue: UIStoryboardSegue) {
self.passwordRepositoryTableViewCell.detailTextLabel?.text = Defaults[.gitURL]?.host
self.passwordRepositoryTableViewCell.detailTextLabel?.text = SharedDefaults[.gitURL]?.host
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
@ -138,7 +139,7 @@ class SettingsTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(SettingsTableViewController.actOnPasswordStoreErasedNotification), name: .passwordStoreErased, object: nil)
self.passwordRepositoryTableViewCell.detailTextLabel?.text = Defaults[.gitURL]?.host
self.passwordRepositoryTableViewCell.detailTextLabel?.text = SharedDefaults[.gitURL]?.host
touchIDTableViewCell.accessoryView = touchIDSwitch
setPGPKeyTableViewCellDetailText()
setPasswordRepositoryTableViewCellDetailText()
@ -170,13 +171,13 @@ class SettingsTableViewController: UITableViewController {
private func setPasscodeLockTouchIDCells() {
if PasscodeLockRepository().hasPasscode {
self.passcodeTableViewCell.detailTextLabel?.text = "On"
Globals.passcodeConfiguration.isTouchIDAllowed = true
touchIDSwitch.isOn = Defaults[.isTouchIDOn]
passcodeLockConfig.isTouchIDAllowed = true
touchIDSwitch.isOn = SharedDefaults[.isTouchIDOn]
} else {
self.passcodeTableViewCell.detailTextLabel?.text = "Off"
Globals.passcodeConfiguration.isTouchIDAllowed = false
Defaults[.isTouchIDOn] = false
touchIDSwitch.isOn = Defaults[.isTouchIDOn]
passcodeLockConfig.isTouchIDAllowed = false
SharedDefaults[.isTouchIDOn] = false
touchIDSwitch.isOn = SharedDefaults[.isTouchIDOn]
}
}
@ -189,10 +190,10 @@ class SettingsTableViewController: UITableViewController {
}
private func setPasswordRepositoryTableViewCellDetailText() {
if Defaults[.gitURL] == nil {
if SharedDefaults[.gitURL] == nil {
passwordRepositoryTableViewCell.detailTextLabel?.text = "Not Set"
} else {
passwordRepositoryTableViewCell.detailTextLabel?.text = Defaults[.gitURL]!.host
passwordRepositoryTableViewCell.detailTextLabel?.text = SharedDefaults[.gitURL]!.host
}
}
@ -202,12 +203,12 @@ class SettingsTableViewController: UITableViewController {
setPasscodeLockTouchIDCells()
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.passcodeLockPresenter = PasscodeLockPresenter(mainWindow: appDelegate.window, configuration: Globals.passcodeConfiguration)
appDelegate.passcodeLockPresenter = PasscodeLockPresenter(mainWindow: appDelegate.window, configuration: passcodeLockConfig)
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if tableView.cellForRow(at: indexPath) == passcodeTableViewCell {
if Defaults[.passcodeKey] != nil{
if SharedDefaults[.passcodeKey] != nil{
showPasscodeActionSheet()
} else {
setPasscodeLock()
@ -219,17 +220,17 @@ class SettingsTableViewController: UITableViewController {
}
func touchIDSwitchAction(uiSwitch: UISwitch) {
if !Globals.passcodeConfiguration.isTouchIDAllowed || !isTouchIDEnabled() {
if !passcodeLockConfig.isTouchIDAllowed || !isTouchIDEnabled() {
// switch off
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(500)) {
uiSwitch.isOn = Defaults[.isTouchIDOn] // false
uiSwitch.isOn = SharedDefaults[.isTouchIDOn] // false
Utils.alert(title: "Notice", message: "Please enable Touch ID and set the passcode lock first.", controller: self, completion: nil)
}
} else {
Defaults[.isTouchIDOn] = uiSwitch.isOn
SharedDefaults[.isTouchIDOn] = uiSwitch.isOn
}
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.passcodeLockPresenter = PasscodeLockPresenter(mainWindow: appDelegate.window, configuration: Globals.passcodeConfiguration)
appDelegate.passcodeLockPresenter = PasscodeLockPresenter(mainWindow: appDelegate.window, configuration: passcodeLockConfig)
}
func showPGPKeyActionSheet() {
@ -238,11 +239,11 @@ class SettingsTableViewController: UITableViewController {
var armorActionTitle = "ASCII-Armor Encrypted Key"
var fileActionTitle = "Use Imported Keys"
if Defaults[.pgpKeySource] == "url" {
if SharedDefaults[.pgpKeySource] == "url" {
urlActionTitle = "\(urlActionTitle)"
} else if Defaults[.pgpKeySource] == "armor" {
} else if SharedDefaults[.pgpKeySource] == "armor" {
armorActionTitle = "\(armorActionTitle)"
} else if Defaults[.pgpKeySource] == "file" {
} else if SharedDefaults[.pgpKeySource] == "file" {
fileActionTitle = "\(fileActionTitle)"
}
let urlAction = UIAlertAction(title: urlActionTitle, style: .default) { _ in
@ -262,7 +263,7 @@ class SettingsTableViewController: UITableViewController {
// no
savePassphraseAlert.addAction(UIAlertAction(title: "No", style: UIAlertActionStyle.default) { _ in
self.passwordStore.pgpKeyPassphrase = nil
Defaults[.isRememberPassphraseOn] = false
SharedDefaults[.isRememberPassphraseOn] = false
self.saveImportedPGPKey()
})
// yes
@ -271,7 +272,7 @@ class SettingsTableViewController: UITableViewController {
let alert = UIAlertController(title: "Passphrase", message: "Please fill in the passphrase of your PGP secret key.", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: {_ in
self.passwordStore.pgpKeyPassphrase = alert.textFields?.first?.text
Defaults[.isRememberPassphraseOn] = true
SharedDefaults[.isRememberPassphraseOn] = true
self.saveImportedPGPKey()
}))
alert.addTextField(configurationHandler: {(textField: UITextField!) in
@ -293,7 +294,7 @@ class SettingsTableViewController: UITableViewController {
}
if Defaults[.pgpKeySource] != nil {
if SharedDefaults[.pgpKeySource] != nil {
let deleteAction = UIAlertAction(title: "Remove PGP Keys", style: .destructive) { _ in
self.passwordStore.removePGPKeys()
self.pgpKeyTableViewCell.detailTextLabel?.text = "Not Set"
@ -307,15 +308,15 @@ class SettingsTableViewController: UITableViewController {
}
func showPasscodeActionSheet() {
let passcodeChangeViewController = PasscodeLockViewController(state: .change, configuration: Globals.passcodeConfiguration)
let passcodeRemoveViewController = PasscodeLockViewController(state: .remove, configuration: Globals.passcodeConfiguration)
let passcodeChangeViewController = PasscodeLockViewController(state: .change, configuration: passcodeLockConfig)
let passcodeRemoveViewController = PasscodeLockViewController(state: .remove, configuration: passcodeLockConfig)
let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
let removePasscodeAction = UIAlertAction(title: "Remove Passcode", style: .destructive) { [weak self] _ in
passcodeRemoveViewController.successCallback = { _ in
self?.setPasscodeLockTouchIDCells()
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.passcodeLockPresenter = PasscodeLockPresenter(mainWindow: appDelegate.window, configuration: Globals.passcodeConfiguration)
appDelegate.passcodeLockPresenter = PasscodeLockPresenter(mainWindow: appDelegate.window, configuration: (self?.passcodeLockConfig)!)
}
self?.present(passcodeRemoveViewController, animated: true, completion: nil)
}
@ -334,7 +335,7 @@ class SettingsTableViewController: UITableViewController {
}
func setPasscodeLock() {
let passcodeSetViewController = PasscodeLockViewController(state: .set, configuration: Globals.passcodeConfiguration)
let passcodeSetViewController = PasscodeLockViewController(state: .set, configuration: passcodeLockConfig)
passcodeSetViewController.successCallback = { _ in
self.setPasscodeLockTouchIDCells()
}