diff options
author | Roopesh Chander <roop@roopc.net> | 2019-06-13 23:01:47 +0530 |
---|---|---|
committer | Roopesh Chander <roop@roopc.net> | 2019-06-13 23:02:54 +0530 |
commit | b286ede3c6215a123331c6c3e26a3e1d8de607fe (patch) | |
tree | 37a7e30c209ab5183d7b26c69dc6fd0ba9e74bed | |
parent | macOS: Tunnel detail: Handle deletion outside app, again (diff) | |
download | wireguard-apple-b286ede3c6215a123331c6c3e26a3e1d8de607fe.tar.xz wireguard-apple-b286ede3c6215a123331c6c3e26a3e1d8de607fe.zip |
iOS: Importing: If tunnelsManager isn't ready yet, we should wait for it
Signed-off-by: Roopesh Chander <roop@roopc.net>
-rw-r--r-- | WireGuard/WireGuard/UI/iOS/AppDelegate.swift | 5 | ||||
-rw-r--r-- | WireGuard/WireGuard/UI/iOS/ViewController/MainViewController.swift | 13 |
2 files changed, 14 insertions, 4 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/AppDelegate.swift b/WireGuard/WireGuard/UI/iOS/AppDelegate.swift index 8884d44..41a136e 100644 --- a/WireGuard/WireGuard/UI/iOS/AppDelegate.swift +++ b/WireGuard/WireGuard/UI/iOS/AppDelegate.swift @@ -34,10 +34,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { } func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool { - guard let tunnelsManager = mainVC?.tunnelsManager else { return true } - TunnelImporter.importFromFile(urls: [url], into: tunnelsManager, sourceVC: mainVC, errorPresenterType: ErrorPresenter.self) { - _ = FileManager.deleteFile(at: url) - } + mainVC?.importFromDisposableFile(url: url) return true } diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/MainViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/MainViewController.swift index c61302b..b37a4d4 100644 --- a/WireGuard/WireGuard/UI/iOS/ViewController/MainViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/ViewController/MainViewController.swift @@ -109,6 +109,19 @@ extension MainViewController { onTunnelsManagerReady = showTunnelDetailBlock } } + + func importFromDisposableFile(url: URL) { + let importFromFileBlock: (TunnelsManager) -> Void = { [weak self] tunnelsManager in + TunnelImporter.importFromFile(urls: [url], into: tunnelsManager, sourceVC: self, errorPresenterType: ErrorPresenter.self) { + _ = FileManager.deleteFile(at: url) + } + } + if let tunnelsManager = tunnelsManager { + importFromFileBlock(tunnelsManager) + } else { + onTunnelsManagerReady = importFromFileBlock + } + } } extension MainViewController: UISplitViewControllerDelegate { |