diff options
| author | Bug Magnet <marco.nikic@mullvad.net> | 2023-09-13 16:55:52 +0200 |
|---|---|---|
| committer | Bug Magnet <marco.nikic@mullvad.net> | 2023-09-13 16:55:52 +0200 |
| commit | dd0358439ecac2bfc8915471272eb3f93248eb3e (patch) | |
| tree | 6089597d59bfc7be122d3038016af19112e22e54 | |
| parent | 571d6bd61dfb7151ca28ebd4cce0516f710b7c9f (diff) | |
| parent | 094d8c783fd6bcd826415fefd3eac84a6887f9c7 (diff) | |
| download | mullvadvpn-dd0358439ecac2bfc8915471272eb3f93248eb3e.tar.xz mullvadvpn-dd0358439ecac2bfc8915471272eb3f93248eb3e.zip | |
Merge branch 'fix-swiftlint-warnings-in-xcode-ios-AppDelegate-296'
| -rw-r--r-- | ios/MullvadVPN/AppDelegate.swift | 102 |
1 files changed, 60 insertions, 42 deletions
diff --git a/ios/MullvadVPN/AppDelegate.swift b/ios/MullvadVPN/AppDelegate.swift index 46d913e381..8c1487f916 100644 --- a/ios/MullvadVPN/AppDelegate.swift +++ b/ios/MullvadVPN/AppDelegate.swift @@ -49,25 +49,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { - configureLogging() - - logger = Logger(label: "AppDelegate") - let containerURL = ApplicationConfiguration.containerURL + configureLogging() + addressCache = REST.AddressCache(canWriteToCache: true, cacheDirectory: containerURL) addressCache.loadFromFile() - proxyFactory = REST.ProxyFactory.makeProxyFactory( - transportProvider: REST.AnyTransportProvider { [weak self] in - return self?.transportMonitor.makeTransport() - }, - addressCache: addressCache - ) - - apiProxy = proxyFactory.createAPIProxy() - accountsProxy = proxyFactory.createAccountsProxy() - devicesProxy = proxyFactory.createDevicesProxy() + setUpProxies(containerURL: containerURL) let relayCache = RelayCache(cacheDirectory: containerURL) relayCacheTracker = RelayCacheTracker(relayCache: relayCache, application: application, apiProxy: apiProxy) @@ -93,6 +82,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD relayConstraintsObserver = TunnelBlockObserver(didUpdateTunnelSettings: { _, settings in constraintsUpdater.onNewConstraints?(settings.relayConstraints) }) + tunnelManager.addObserver(relayConstraintsObserver) storePaymentManager = StorePaymentManager( application: application, @@ -110,15 +100,41 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD shadowsocksCache: shadowsocksCache, constraintsUpdater: constraintsUpdater ) + setUpTransportMonitor(transportProvider: transportProvider) + setUpSimulatorHost(transportProvider: transportProvider) - tunnelManager.addObserver(relayConstraintsObserver) + registerBackgroundTasks() + setupPaymentHandler() + setupNotifications() + addApplicationNotifications(application: application) + + startInitialization(application: application) + + return true + } + + private func setUpProxies(containerURL: URL) { + proxyFactory = REST.ProxyFactory.makeProxyFactory( + transportProvider: REST.AnyTransportProvider { [weak self] in + return self?.transportMonitor.makeTransport() + }, + addressCache: addressCache + ) + + apiProxy = proxyFactory.createAPIProxy() + accountsProxy = proxyFactory.createAccountsProxy() + devicesProxy = proxyFactory.createDevicesProxy() + } + private func setUpTransportMonitor(transportProvider: TransportProvider) { transportMonitor = TransportMonitor( tunnelManager: tunnelManager, tunnelStore: tunnelStore, transportProvider: transportProvider ) + } + private func setUpSimulatorHost(transportProvider: TransportProvider) { #if targetEnvironment(simulator) // Configure mock tunnel provider on simulator simulatorTunnelProviderHost = SimulatorTunnelProviderHost( @@ -127,15 +143,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD ) SimulatorTunnelProvider.shared.delegate = simulatorTunnelProviderHost #endif - - registerBackgroundTasks() - setupPaymentHandler() - setupNotifications() - addApplicationNotifications(application: application) - - startInitialization(application: application) - - return true } // MARK: - UISceneSession lifecycle @@ -318,6 +325,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD loggerBuilder.addOSLogOutput(subsystem: ApplicationTarget.mainApp.bundleIdentifier) #endif loggerBuilder.install() + + logger = Logger(label: "AppDelegate") } private func addApplicationNotifications(application: UIApplication) { @@ -360,8 +369,26 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD private func startInitialization(application: UIApplication) { let wipeSettingsOperation = getWipeSettingsOperation() + let loadTunnelStoreOperation = getLoadTunnelStoreOperation() + let migrateSettingsOperation = getMigrateSettingsOperation(application: application) + let initTunnelManagerOperation = getInitTunnelManagerOperation() + + migrateSettingsOperation.addDependencies([wipeSettingsOperation, loadTunnelStoreOperation]) + initTunnelManagerOperation.addDependency(migrateSettingsOperation) + + operationQueue.addOperations( + [ + wipeSettingsOperation, + loadTunnelStoreOperation, + migrateSettingsOperation, + initTunnelManagerOperation, + ], + waitUntilFinished: false + ) + } - let loadTunnelStoreOperation = AsyncBlockOperation(dispatchQueue: .main) { [self] finish in + private func getLoadTunnelStoreOperation() -> AsyncBlockOperation { + AsyncBlockOperation(dispatchQueue: .main) { [self] finish in tunnelStore.loadPersistentTunnels { [self] error in if let error { logger.error( @@ -372,8 +399,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD finish(nil) } } + } - let migrateSettingsOperation = AsyncBlockOperation(dispatchQueue: .main) { [self] finish in + private func getMigrateSettingsOperation(application: UIApplication) -> AsyncBlockOperation { + AsyncBlockOperation(dispatchQueue: .main) { [self] finish in migrationManager .migrateSettings(store: SettingsManager.store, proxyFactory: proxyFactory) { [self] migrationResult in switch migrationResult { @@ -387,8 +416,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD finish(nil) case let .failure(error): - let migrationUIHandler = application.connectedScenes.first { $0 is SettingsMigrationUIHandler } - as? SettingsMigrationUIHandler + let migrationUIHandler = application.connectedScenes + .first { $0 is SettingsMigrationUIHandler } as? SettingsMigrationUIHandler if let migrationUIHandler { migrationUIHandler.showMigrationError(error) { @@ -400,10 +429,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD } } } + } - migrateSettingsOperation.addDependencies([wipeSettingsOperation, loadTunnelStoreOperation]) - - let initTunnelManagerOperation = AsyncBlockOperation(dispatchQueue: .main) { finish in + private func getInitTunnelManagerOperation() -> AsyncBlockOperation { + AsyncBlockOperation(dispatchQueue: .main) { finish in self.tunnelManager.loadConfiguration { error in if let error { fatalError(error.localizedDescription) @@ -417,17 +446,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD finish(nil) } } - initTunnelManagerOperation.addDependency(migrateSettingsOperation) - - operationQueue.addOperations( - [ - wipeSettingsOperation, - loadTunnelStoreOperation, - migrateSettingsOperation, - initTunnelManagerOperation, - ], - waitUntilFinished: false - ) } /// Returns an operation that acts on two conditions: |
