passforios/pass/SettingsTableViewController.swift

86 lines
4.2 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-23 17:36:10 +08:00
SVProgressHUD.show(withStatus: "Prepare Repository")
//SVProgressHUD.showProgress(0.0, status: "Clone Remote Repository")
2017-01-19 21:15:47 +08:00
DispatchQueue.global(qos: .userInitiated).async {
2017-01-23 17:36:10 +08:00
let ret = PasswordStore.shared.cloneRepository(remoteRepoURL: Defaults[.gitRepositoryURL]!,
transferProgressBlock:{ (git_transfer_progress, stop) in
DispatchQueue.main.async {
SVProgressHUD.showProgress(Float(git_transfer_progress.pointee.received_objects)/Float(git_transfer_progress.pointee.total_objects), status: "Clone Remote Repository")
}
},
checkoutProgressBlock: { (path, completedSteps, totalSteps) in
DispatchQueue.main.async {
SVProgressHUD.showProgress(Float(completedSteps)/Float(totalSteps), status: "Checkout Master Branch")
}
})
DispatchQueue.main.async {
if ret {
2017-01-23 17:36:10 +08:00
SVProgressHUD.showSuccess(withStatus: "Done")
SVProgressHUD.dismiss(withDelay: 1)
NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated")))
} else {
2017-01-23 17:36:10 +08:00
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
}
}
}