mirror of
https://github.com/passepartoutvpn/passepartout-apple.git
synced 2025-02-07 08:22:07 +00:00
Share import logic between browser and imported
This commit is contained in:
parent
2485c5b588
commit
0acef41a7f
@ -30,12 +30,14 @@ import PassepartoutCore
|
|||||||
|
|
||||||
private let log = SwiftyBeaver.self
|
private let log = SwiftyBeaver.self
|
||||||
|
|
||||||
|
protocol ImportedHostsViewControllerDelegate: class {
|
||||||
|
func importedHostsController(_: ImportedHostsViewController, didImport url: URL)
|
||||||
|
}
|
||||||
|
|
||||||
class ImportedHostsViewController: UITableViewController {
|
class ImportedHostsViewController: UITableViewController {
|
||||||
private lazy var pendingConfigurationURLs = TransientStore.shared.service.pendingConfigurationURLs().sortedCaseInsensitive()
|
private lazy var pendingConfigurationURLs = TransientStore.shared.service.pendingConfigurationURLs().sortedCaseInsensitive()
|
||||||
|
|
||||||
private var importer: HostImporter?
|
weak var delegate: ImportedHostsViewControllerDelegate?
|
||||||
|
|
||||||
private var parsingResult: OpenVPN.ConfigurationParser.Result?
|
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
@ -43,65 +45,8 @@ class ImportedHostsViewController: UITableViewController {
|
|||||||
title = L10n.App.ImportedHosts.title
|
title = L10n.App.ImportedHosts.title
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewWillAppear(_ animated: Bool) {
|
private func selectHost(withUrl url: URL) {
|
||||||
super.viewWillAppear(animated)
|
delegate?.importedHostsController(self, didImport: url)
|
||||||
|
|
||||||
parsingResult = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
override func viewDidAppear(_ animated: Bool) {
|
|
||||||
super.viewDidAppear(animated)
|
|
||||||
|
|
||||||
// guard !pendingConfigurationURLs.isEmpty else {
|
|
||||||
// let alert = UIAlertController.asAlert(
|
|
||||||
// title,
|
|
||||||
// L10n.Core.Organizer.Alerts.AddHost.message
|
|
||||||
// )
|
|
||||||
// alert.addCancelAction(L10n.Core.Global.ok) {
|
|
||||||
// self.close()
|
|
||||||
// }
|
|
||||||
// present(alert, animated: true, completion: nil)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
if let selectedIP = tableView.indexPathForSelectedRow {
|
|
||||||
tableView.deselectRow(at: selectedIP, animated: true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: Actions
|
|
||||||
|
|
||||||
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
|
|
||||||
|
|
||||||
// segue parses configuration file if not yet
|
|
||||||
if parsingResult == nil {
|
|
||||||
guard let cell = sender as? UITableViewCell, let indexPath = tableView.indexPath(for: cell) else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
let url = pendingConfigurationURLs[indexPath.row]
|
|
||||||
return tryParseURL(url, cell: cell)
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
private func tryParseURL(_ url: URL, cell: UITableViewCell?) -> Bool {
|
|
||||||
deselectSelectedRow()
|
|
||||||
|
|
||||||
importer = HostImporter(withConfigurationURL: url, parentViewController: self)
|
|
||||||
importer?.importHost(withPassphrase: nil, removeOnError: false, removeOnCancel: false) {
|
|
||||||
self.parsingResult = $0
|
|
||||||
self.perform(segue: StoryboardSegue.Organizer.importHostSegueIdentifier)
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
|
||||||
guard let wizard = segue.destination as? WizardHostViewController else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
wizard.parsingResult = parsingResult
|
|
||||||
|
|
||||||
// retain back button
|
|
||||||
wizard.navigationItem.leftBarButtonItem = nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction private func close() {
|
@IBAction private func close() {
|
||||||
@ -126,6 +71,11 @@ extension ImportedHostsViewController {
|
|||||||
cell.leftText = url.normalizedFilename
|
cell.leftText = url.normalizedFilename
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||||
|
let url = pendingConfigurationURLs[indexPath.row]
|
||||||
|
selectHost(withUrl: url)
|
||||||
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
|
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
|
||||||
return true
|
return true
|
||||||
|
@ -175,6 +175,8 @@ class OrganizerViewController: UITableViewController, StrongTableHost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vc.setProfile(selectedProfile)
|
vc.setProfile(selectedProfile)
|
||||||
|
} else if let vc = destination as? ImportedHostsViewController {
|
||||||
|
vc.delegate = self
|
||||||
} else if let vc = destination as? WizardHostViewController {
|
} else if let vc = destination as? WizardHostViewController {
|
||||||
vc.parsingResult = hostParsingResult
|
vc.parsingResult = hostParsingResult
|
||||||
}
|
}
|
||||||
@ -788,6 +790,14 @@ extension OrganizerViewController: UIDocumentPickerDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension OrganizerViewController: ImportedHostsViewControllerDelegate {
|
||||||
|
func importedHostsController(_: ImportedHostsViewController, didImport url: URL) {
|
||||||
|
dismiss(animated: true) {
|
||||||
|
self.tryParseHostURL(url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extension OrganizerViewController: MFMailComposeViewControllerDelegate {
|
extension OrganizerViewController: MFMailComposeViewControllerDelegate {
|
||||||
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
|
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
|
||||||
dismiss(animated: true, completion: nil)
|
dismiss(animated: true, completion: nil)
|
||||||
|
Loading…
Reference in New Issue
Block a user