aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift
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/UI/iOS/TunnelsListTableViewController.swift
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/UI/iOS/TunnelsListTableViewController.swift')
-rw-r--r--WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift39
1 files changed, 30 insertions, 9 deletions
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 {