iOS: Importing: If tunnelsManager isn't ready yet, we should wait for it

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander 2019-06-13 23:01:47 +05:30
parent 4ef7afe3ca
commit b286ede3c6
2 changed files with 14 additions and 4 deletions

View File

@ -34,10 +34,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
} }
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool { func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
guard let tunnelsManager = mainVC?.tunnelsManager else { return true } mainVC?.importFromDisposableFile(url: url)
TunnelImporter.importFromFile(urls: [url], into: tunnelsManager, sourceVC: mainVC, errorPresenterType: ErrorPresenter.self) {
_ = FileManager.deleteFile(at: url)
}
return true return true
} }

View File

@ -109,6 +109,19 @@ extension MainViewController {
onTunnelsManagerReady = showTunnelDetailBlock 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 { extension MainViewController: UISplitViewControllerDelegate {