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 {