QR Code: Error out on duplicate name

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander 2018-11-01 01:36:28 +05:30
parent 050f8aa679
commit bede8a17ad
2 changed files with 10 additions and 7 deletions

View File

@ -6,7 +6,7 @@ import CoreData
import UIKit import UIKit
protocol QRScanViewControllerDelegate: class { protocol QRScanViewControllerDelegate: class {
func scannedQRCode(tunnelConfiguration: TunnelConfiguration, qrScanViewController: QRScanViewController) func addScannedQRCode(tunnelConfiguration: TunnelConfiguration, qrScanViewController: QRScanViewController, completionHandler: (() ->Void)?)
} }
class QRScanViewController: UIViewController { class QRScanViewController: UIViewController {
@ -119,9 +119,10 @@ class QRScanViewController: UIViewController {
if (title.isEmpty) { return } if (title.isEmpty) { return }
tunnelConfiguration.interface.name = title tunnelConfiguration.interface.name = title
if let s = self { if let s = self {
s.delegate?.scannedQRCode(tunnelConfiguration: tunnelConfiguration, qrScanViewController: s) s.delegate?.addScannedQRCode(tunnelConfiguration: tunnelConfiguration, qrScanViewController: s) {
s.dismiss(animated: true, completion: nil) s.dismiss(animated: true, completion: nil)
} }
}
})) }))
present(alert, animated: true) present(alert, animated: true)
} }

View File

@ -214,11 +214,13 @@ extension TunnelsListTableViewController: UIDocumentPickerDelegate {
// MARK: QRScanViewControllerDelegate // MARK: QRScanViewControllerDelegate
extension TunnelsListTableViewController: QRScanViewControllerDelegate { extension TunnelsListTableViewController: QRScanViewControllerDelegate {
func scannedQRCode(tunnelConfiguration: TunnelConfiguration, qrScanViewController: QRScanViewController) { func addScannedQRCode(tunnelConfiguration: TunnelConfiguration, qrScanViewController: QRScanViewController,
tunnelsManager?.add(tunnelConfiguration: tunnelConfiguration) { [weak self] (tunnel, error) in completionHandler: (() ->Void)?) {
tunnelsManager?.add(tunnelConfiguration: tunnelConfiguration) { (tunnel, error) in
if let error = error { if let error = error {
print("Could not add tunnel: \(error)") ErrorPresenter.showErrorAlert(error: error, from: qrScanViewController, onDismissal: completionHandler)
self?.showErrorAlert(title: "Could not save scanned config", message: "Internal error") } else {
completionHandler?()
} }
} }
} }