aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-10-25 14:35:23 +0530
committerRoopesh Chander <roop@roopc.net>2018-10-27 15:13:02 +0530
commitff7adb8bc84d9397ac7ab7d9b452f9adf8b3b95f (patch)
treed826e4f3f5ffd9b8ff6e03e5d8b4c395efb09c88 /WireGuard/WireGuard
parentiPad: Fix modal presentation style (diff)
downloadwireguard-apple-ff7adb8bc84d9397ac7ab7d9b452f9adf8b3b95f.tar.xz
wireguard-apple-ff7adb8bc84d9397ac7ab7d9b452f9adf8b3b95f.zip
Import: Support for importing a config file from file providers
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard')
-rw-r--r--WireGuard/WireGuard/UI/iOS/FilePicker.swift18
-rw-r--r--WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift39
2 files changed, 48 insertions, 9 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/FilePicker.swift b/WireGuard/WireGuard/UI/iOS/FilePicker.swift
new file mode 100644
index 0000000..25da7b9
--- /dev/null
+++ b/WireGuard/WireGuard/UI/iOS/FilePicker.swift
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: MIT
+// Copyright © 2018 WireGuard LLC. All rights reserved.
+
+import UIKit
+
+class FileImportViewController: UIDocumentPickerViewController {
+ enum DocumentType: String {
+ case wgQuickConfigFile = "com.wireguard.config.quick"
+ }
+
+ init(documentTypes: [DocumentType]) {
+ super.init(documentTypes: documentTypes.map { $0.rawValue }, in: .import)
+ }
+
+ required init?(coder aDecoder: NSCoder) {
+ fatalError("init(coder:) has not been implemented")
+ }
+}
diff --git a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift
index 08b8145..26e70ab 100644
--- a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift
@@ -40,16 +40,21 @@ class TunnelsListTableViewController: UITableViewController {
let alert = UIAlertController(title: "",
message: "Add a tunnel",
preferredStyle: .actionSheet)
- alert.addAction(
- UIAlertAction(title: "Create from scratch", style: .default) { [weak self] (action) in
- if let s = self, let tunnelsManager = s.tunnelsManager {
- s.presentViewControllerForTunnelCreation(tunnelsManager: tunnelsManager, tunnelConfiguration: nil)
- }
+ let importFileAction = UIAlertAction(title: "Import wg-quick config (.conf)", style: .default) { [weak self] (action) in
+ self?.presentViewControllerForFileImport()
+ }
+ alert.addAction(importFileAction)
+
+ let createFromScratchAction = UIAlertAction(title: "Create from scratch", style: .default) { [weak self] (action) in
+ if let s = self, let tunnelsManager = s.tunnelsManager {
+ s.presentViewControllerForTunnelCreation(tunnelsManager: tunnelsManager, tunnelConfiguration: nil)
}
- )
- alert.addAction(
- UIAlertAction(title: "Cancel", style: .cancel)
- )
+ }
+ alert.addAction(createFromScratchAction)
+
+ let cancelAction = UIAlertAction(title: "Cancel", style: .cancel)
+ alert.addAction(cancelAction)
+
// popoverPresentationController will be nil on iPhone and non-nil on iPad
alert.popoverPresentationController?.barButtonItem = self.navigationItem.rightBarButtonItem
self.present(alert, animated: true, completion: nil)
@@ -83,6 +88,12 @@ class TunnelsListTableViewController: UITableViewController {
self.present(editNC, animated: true)
}
+ func presentViewControllerForFileImport() {
+ let filePicker = FileImportViewController(documentTypes: [.wgQuickConfigFile])
+ filePicker.delegate = self
+ self.present(filePicker, animated: true)
+ }
+
func showErrorAlert(title: String, message: String) {
let okAction = UIAlertAction(title: "Ok", style: .default)
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
@@ -107,6 +118,16 @@ extension TunnelsListTableViewController: TunnelEditTableViewControllerDelegate
}
}
+// MARK: UIDocumentPickerDelegate
+
+extension TunnelsListTableViewController: UIDocumentPickerDelegate {
+ func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
+ if let url = urls.first {
+ openForEditing(configFileURL: url)
+ }
+ }
+}
+
// MARK: UITableViewDataSource
extension TunnelsListTableViewController {