aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard
diff options
context:
space:
mode:
authorJeroen Leenarts <jeroen.leenarts@gmail.com>2018-09-25 20:59:15 +0200
committerJeroen Leenarts <jeroen.leenarts@gmail.com>2018-09-25 20:59:15 +0200
commitad28815bef5dae3d8029f1c3ff0039696f5c36e8 (patch)
treeafb55dcb108bb5ace95c9e244afcd6ae52e681a3 /WireGuard
parentMove copy button a bit up towards title line. (diff)
downloadwireguard-apple-ad28815bef5dae3d8029f1c3ff0039696f5c36e8.tar.xz
wireguard-apple-ad28815bef5dae3d8029f1c3ff0039696f5c36e8.zip
Ask for title when scaning a QR.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'WireGuard')
-rw-r--r--WireGuard/Coordinators/AppCoordinator.swift4
-rw-r--r--WireGuard/ViewControllers/QRScanViewController.swift16
2 files changed, 18 insertions, 2 deletions
diff --git a/WireGuard/Coordinators/AppCoordinator.swift b/WireGuard/Coordinators/AppCoordinator.swift
index 1ae11a5..d8cf5db 100644
--- a/WireGuard/Coordinators/AppCoordinator.swift
+++ b/WireGuard/Coordinators/AppCoordinator.swift
@@ -524,6 +524,10 @@ extension AppCoordinator: QRScanViewControllerDelegate {
qrScanViewController.navigationController?.popViewController(animated: true)
showTunnelInfoViewController(tunnel: tunnel, context: tunnel.managedObjectContext!)
}
+
+ func didCancel(qrScanViewController: QRScanViewController) {
+ qrScanViewController.navigationController?.popViewController(animated: true)
+ }
}
extension AppCoordinator: SettingsTableViewControllerDelegate {
diff --git a/WireGuard/ViewControllers/QRScanViewController.swift b/WireGuard/ViewControllers/QRScanViewController.swift
index 811602e..c174637 100644
--- a/WireGuard/ViewControllers/QRScanViewController.swift
+++ b/WireGuard/ViewControllers/QRScanViewController.swift
@@ -12,6 +12,7 @@ import UIKit
protocol QRScanViewControllerDelegate: class {
func didSave(tunnel: Tunnel, qrScanViewController: QRScanViewController)
+ func didCancel(qrScanViewController: QRScanViewController)
}
class QRScanViewController: UIViewController {
@@ -102,8 +103,19 @@ class QRScanViewController: UIViewController {
func scanDidComplete(withCode code: String) {
do {
let tunnel = try Tunnel.fromConfig(code, context: viewContext)
- try viewContext.save()
- delegate?.didSave(tunnel: tunnel, qrScanViewController: self)
+ let alert = UIAlertController(title: NSLocalizedString("Enter a title for new tunnel", comment: ""), message: nil, preferredStyle: .alert)
+ alert.addTextField(configurationHandler: nil)
+ alert.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style: .cancel, handler: nil))
+ alert.addAction(UIAlertAction(title: NSLocalizedString("Save", comment: ""), style: .default, handler: { [weak self] _ in
+ do {
+ tunnel.title = alert.textFields?[0].text
+ try self?.viewContext.save()
+ self?.delegate?.didSave(tunnel: tunnel, qrScanViewController: self!)
+ } catch {
+ self?.scanDidEncounterError(title: "Invalid Code", message: "The scanned code is not a valid WireGuard config file.")
+ }
+ }))
+
} catch {
scanDidEncounterError(title: "Invalid Code", message: "The scanned code is not a valid WireGuard config file.")
}