Import: Support for importing a config file from file providers
This commit is contained in:
parent
9d340ab873
commit
f6620fed9a
|
@ -13,6 +13,7 @@
|
|||
6F6899A62180447E0012E523 /* x25519.c in Sources */ = {isa = PBXBuildFile; fileRef = 6F6899A52180447E0012E523 /* x25519.c */; };
|
||||
6F6899A8218044FC0012E523 /* Curve25519.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F6899A7218044FC0012E523 /* Curve25519.swift */; };
|
||||
6F6899AC218099F00012E523 /* WgQuickConfigFileParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F6899AB218099F00012E523 /* WgQuickConfigFileParser.swift */; };
|
||||
6F6899B02181B07B0012E523 /* FilePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F6899AF2181B07A0012E523 /* FilePicker.swift */; };
|
||||
6F693A562179E556008551C1 /* Endpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F693A552179E556008551C1 /* Endpoint.swift */; };
|
||||
6F7774E1217181B1006A79B3 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F7774DF217181B1006A79B3 /* MainViewController.swift */; };
|
||||
6F7774E2217181B1006A79B3 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F7774E0217181B1006A79B3 /* AppDelegate.swift */; };
|
||||
|
@ -35,6 +36,7 @@
|
|||
6F6899A52180447E0012E523 /* x25519.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = x25519.c; sourceTree = "<group>"; };
|
||||
6F6899A7218044FC0012E523 /* Curve25519.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Curve25519.swift; sourceTree = "<group>"; };
|
||||
6F6899AB218099F00012E523 /* WgQuickConfigFileParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WgQuickConfigFileParser.swift; sourceTree = "<group>"; };
|
||||
6F6899AF2181B07A0012E523 /* FilePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilePicker.swift; sourceTree = "<group>"; };
|
||||
6F693A552179E556008551C1 /* Endpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Endpoint.swift; sourceTree = "<group>"; };
|
||||
6F7774DF217181B1006A79B3 /* MainViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = "<group>"; };
|
||||
6F7774E0217181B1006A79B3 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
|
@ -99,6 +101,7 @@
|
|||
6F7774E321718281006A79B3 /* TunnelsListTableViewController.swift */,
|
||||
6F7774F221774263006A79B3 /* TunnelEditTableViewController.swift */,
|
||||
6F628C40217F47DB003482A3 /* TunnelDetailTableViewController.swift */,
|
||||
6F6899AF2181B07A0012E523 /* FilePicker.swift */,
|
||||
);
|
||||
path = iOS;
|
||||
sourceTree = "<group>";
|
||||
|
@ -253,6 +256,7 @@
|
|||
6F7774E82172020C006A79B3 /* Configuration.swift in Sources */,
|
||||
6F6899A8218044FC0012E523 /* Curve25519.swift in Sources */,
|
||||
6F628C41217F47DB003482A3 /* TunnelDetailTableViewController.swift in Sources */,
|
||||
6F6899B02181B07B0012E523 /* FilePicker.swift in Sources */,
|
||||
6F7774F321774263006A79B3 /* TunnelEditTableViewController.swift in Sources */,
|
||||
6F7774E1217181B1006A79B3 /* MainViewController.swift in Sources */,
|
||||
);
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue