From b286ede3c6215a123331c6c3e26a3e1d8de607fe Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Thu, 13 Jun 2019 23:01:47 +0530 Subject: [PATCH] iOS: Importing: If tunnelsManager isn't ready yet, we should wait for it Signed-off-by: Roopesh Chander --- WireGuard/WireGuard/UI/iOS/AppDelegate.swift | 5 +---- .../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 { -- 2.47.2