passforios/pass/SettingsTableViewController.swift

76 lines
3.1 KiB
Swift
Raw Normal View History

2017-01-19 21:15:47 +08:00
//
// SettingsTableViewController.swift
// pass
//
// Created by Mingshen Sun on 18/1/2017.
// Copyright © 2017 Bob Sun. All rights reserved.
//
import UIKit
import SVProgressHUD
import CoreData
import SwiftyUserDefaults
2017-01-19 21:15:47 +08:00
class SettingsTableViewController: UITableViewController {
@IBOutlet weak var pgpKeyTableViewCell: UITableViewCell!
2017-01-19 21:15:47 +08:00
@IBAction func cancel(segue: UIStoryboardSegue) {
}
@IBAction func save(segue: UIStoryboardSegue) {
if let controller = segue.source as? GitServerSettingTableViewController {
if Defaults[.gitRepositoryURL] == nil || controller.gitRepositoryURLTextField.text != Defaults[.gitRepositoryURL]!.absoluteString {
Defaults[.gitRepositoryURL] = URL(string: controller.gitRepositoryURLTextField.text!)
SVProgressHUD.setDefaultMaskType(.black)
2017-01-19 21:15:47 +08:00
SVProgressHUD.show(withStatus: "Cloning Remote Repository")
2017-01-19 21:15:47 +08:00
DispatchQueue.global(qos: .userInitiated).async {
let ret = PasswordStore.shared.cloneRemoteRepo(remoteRepoURL: Defaults[.gitRepositoryURL]!)
DispatchQueue.main.async {
if ret {
SVProgressHUD.dismiss()
SVProgressHUD.setMaximumDismissTimeInterval(1)
SVProgressHUD.showSuccess(withStatus: "Success")
NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated")))
} else {
SVProgressHUD.showError(withStatus: "Error")
2017-01-19 21:15:47 +08:00
}
}
}
}
} else if let controller = segue.source as? PGPKeySettingTableViewController {
if Defaults[.pgpKeyURL] != URL(string: controller.pgpKeyURLTextField.text!) {
Defaults[.pgpKeyURL] = URL(string: controller.pgpKeyURLTextField.text!)
Defaults[.pgpKeyPassphrase] = controller.pgpKeyPassphraseTextField.text!
2017-01-19 21:15:47 +08:00
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 {
SVProgressHUD.showSuccess(withStatus: "Success")
} else {
SVProgressHUD.showError(withStatus: "Error")
}
}
}
2017-01-19 21:15:47 +08:00
}
2017-01-19 21:15:47 +08:00
}
}
override func viewDidLoad() {
super.viewDidLoad()
if Defaults[.pgpKeyID] == "" {
pgpKeyTableViewCell.detailTextLabel?.text = "Not Set"
2017-01-19 21:15:47 +08:00
} else {
pgpKeyTableViewCell.detailTextLabel?.text = Defaults[.pgpKeyID]
2017-01-19 21:15:47 +08:00
}
}
}