aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-12-12 19:24:12 +0530
committerRoopesh Chander <roop@roopc.net>2018-12-12 19:24:18 +0530
commitaf78fa9a1ceac63b6302d7115c706757d2896263 (patch)
tree391bd6bb30368e331a3edb92159c983c2480e7d4 /WireGuard
parentErrorPresenter: Support onPresented for showErrorAlert(title:,message:) (diff)
downloadwireguard-apple-af78fa9a1ceac63b6302d7115c706757d2896263.tar.xz
wireguard-apple-af78fa9a1ceac63b6302d7115c706757d2896263.zip
Zip importing: importFromFile should take a completionHandler
Deletion of the being-imported file should be done in the completionHandler. Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard')
-rw-r--r--WireGuard/WireGuard/UI/iOS/AppDelegate.swift5
-rw-r--r--WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift15
2 files changed, 13 insertions, 7 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/AppDelegate.swift b/WireGuard/WireGuard/UI/iOS/AppDelegate.swift
index 5dca2ad6..d62890ee 100644
--- a/WireGuard/WireGuard/UI/iOS/AppDelegate.swift
+++ b/WireGuard/WireGuard/UI/iOS/AppDelegate.swift
@@ -27,8 +27,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
- mainVC?.tunnelsListVC?.importFromFile(url: url)
- _ = FileManager.deleteFile(at: url)
+ mainVC?.tunnelsListVC?.importFromFile(url: url) {
+ _ = FileManager.deleteFile(at: url)
+ }
return true
}
diff --git a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift
index b1102c47..66c44527 100644
--- a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift
@@ -165,7 +165,7 @@ class TunnelsListTableViewController: UIViewController {
self.present(scanQRCodeNC, animated: true)
}
- func importFromFile(url: URL) {
+ func importFromFile(url: URL, completionHandler: (() -> Void)?) {
guard let tunnelsManager = tunnelsManager else { return }
if (url.pathExtension == "zip") {
ZipImporter.importConfigFiles(from: url) { [weak self] result in
@@ -176,11 +176,12 @@ class TunnelsListTableViewController: UIViewController {
let configs: [TunnelConfiguration?] = result.value!
tunnelsManager.addMultiple(tunnelConfigurations: configs.compactMap { $0 }) { [weak self] (numberSuccessful) in
if numberSuccessful == configs.count {
+ completionHandler?()
return
}
ErrorPresenter.showErrorAlert(title: "Created \(numberSuccessful) tunnels",
message: "Created \(numberSuccessful) of \(configs.count) tunnels from zip archive",
- from: self)
+ from: self, onPresented: completionHandler)
}
}
} else /* if (url.pathExtension == "conf") -- we assume everything else is a conf */ {
@@ -189,13 +190,15 @@ class TunnelsListTableViewController: UIViewController {
let tunnelConfiguration = try? WgQuickConfigFileParser.parse(fileContents, name: fileBaseName) {
tunnelsManager.add(tunnelConfiguration: tunnelConfiguration) { [weak self] result in
if let error = result.error {
- ErrorPresenter.showErrorAlert(error: error, from: self)
+ ErrorPresenter.showErrorAlert(error: error, from: self, onPresented: completionHandler)
+ } else {
+ completionHandler?()
}
}
} else {
ErrorPresenter.showErrorAlert(title: "Unable to import tunnel",
message: "An error occured when importing the tunnel configuration.",
- from: self)
+ from: self, onPresented: completionHandler)
}
}
}
@@ -205,7 +208,9 @@ class TunnelsListTableViewController: UIViewController {
extension TunnelsListTableViewController: UIDocumentPickerDelegate {
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
- urls.forEach(importFromFile)
+ urls.forEach {
+ importFromFile(url: $0, completionHandler: nil)
+ }
}
}