WireguardApp: iOS: Moved tunnelsManager initialization to AppDelegate

Signed-off-by: Alessio Nossa <alessio.nossa@gmail.com>
This commit is contained in:
Alessio Nossa
2022-01-29 17:17:05 +01:00
parent ab1e96fcdc
commit ceabb4ea34
2 changed files with 38 additions and 18 deletions
@@ -11,6 +11,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var mainVC: MainViewController?
var isLaunchedForSpecificAction = false
var tunnelsManager: TunnelsManager?
static let tunnelsManagerReadyNotificationName: Notification.Name = Notification.Name(rawValue: "com.wireguard.ios.tunnelsManagerReadyNotification")
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Logger.configureGlobal(tagged: "APP", withFilePath: FileManager.logFileURL?.path)
@@ -29,6 +33,25 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
self.mainVC = mainVC
// Create the tunnels manager, and when it's ready, inform tunnelsListVC
TunnelsManager.create { [weak self] result in
guard let self = self else { return }
switch result {
case .failure(let error):
ErrorPresenter.showErrorAlert(error: error, from: self.mainVC)
case .success(let tunnelsManager):
self.tunnelsManager = tunnelsManager
self.mainVC?.tunnelsListVC?.setTunnelsManager(tunnelsManager: tunnelsManager)
tunnelsManager.activationDelegate = self.mainVC
NotificationCenter.default.post(name: AppDelegate.tunnelsManagerReadyNotificationName,
object: self,
userInfo: nil)
}
}
return true
}