diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2022-10-31 13:31:45 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2022-10-31 13:31:45 +0100 |
| commit | 87ef07178d9b164bec923d95e80d73d39ec3331b (patch) | |
| tree | bf9e8872facb260132f8c18e08f0c1ea3f4c4011 | |
| parent | 9ccaf980e233c4fcad450e29787a0c0b22aee1e6 (diff) | |
| parent | 1b8f774aa6c2cb4984bfe1d688403a7d1d241162 (diff) | |
| download | mullvadvpn-87ef07178d9b164bec923d95e80d73d39ec3331b.tar.xz mullvadvpn-87ef07178d9b164bec923d95e80d73d39ec3331b.zip | |
Merge branch 'move-app-wide-routine-appdelegate'
| -rw-r--r-- | ios/MullvadVPN/AppDelegate.swift | 45 | ||||
| -rw-r--r-- | ios/MullvadVPN/SceneDelegate.swift | 19 |
2 files changed, 46 insertions, 18 deletions
diff --git a/ios/MullvadVPN/AppDelegate.swift b/ios/MullvadVPN/AppDelegate.swift index f1958e9955..8776da06e9 100644 --- a/ios/MullvadVPN/AppDelegate.swift +++ b/ios/MullvadVPN/AppDelegate.swift @@ -53,6 +53,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { registerBackgroundTasks() setupPaymentHandler() setupNotificationHandler() + addApplicationNotifications(application: application) let setupTunnelManagerOperation = AsyncBlockOperation(dispatchQueue: .main) { operation in TunnelManager.shared.loadConfiguration { error in @@ -117,6 +118,25 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // the discarded scenes, as they will not return. } + // MARK: - Notifications + + @objc private func didBecomeActive(_ notification: Notification) { + TunnelManager.shared.refreshTunnelStatus() + TunnelManager.shared.startPeriodicPrivateKeyRotation() + RelayCacheTracker.shared.startPeriodicUpdates() + AddressCacheTracker.shared.startPeriodicUpdates() + } + + @objc private func willResignActive(_ notification: Notification) { + TunnelManager.shared.stopPeriodicPrivateKeyRotation() + RelayCacheTracker.shared.stopPeriodicUpdates() + AddressCacheTracker.shared.stopPeriodicUpdates() + } + + @objc private func didEnterBackground(_ notification: Notification) { + scheduleBackgroundTasks() + } + // MARK: - Background tasks private func registerBackgroundTasks() { @@ -194,7 +214,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { } } - func scheduleBackgroundTasks() { + private func scheduleBackgroundTasks() { scheduleAppRefreshTask() scheduleKeyRotationTask() scheduleAddressCacheUpdateTask() @@ -266,6 +286,29 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // MARK: - Private + private func addApplicationNotifications(application: UIApplication) { + let notificationCenter = NotificationCenter.default + + notificationCenter.addObserver( + self, + selector: #selector(didBecomeActive(_:)), + name: UIApplication.didBecomeActiveNotification, + object: application + ) + notificationCenter.addObserver( + self, + selector: #selector(willResignActive(_:)), + name: UIApplication.willResignActiveNotification, + object: application + ) + notificationCenter.addObserver( + self, + selector: #selector(didEnterBackground(_:)), + name: UIApplication.didEnterBackgroundNotification, + object: application + ) + } + private func setupPaymentHandler() { StorePaymentManager.shared.delegate = self StorePaymentManager.shared.addPaymentObserver(TunnelManager.shared) diff --git a/ios/MullvadVPN/SceneDelegate.swift b/ios/MullvadVPN/SceneDelegate.swift index 3cdb5d6b5c..1113eefb18 100644 --- a/ios/MullvadVPN/SceneDelegate.swift +++ b/ios/MullvadVPN/SceneDelegate.swift @@ -119,8 +119,6 @@ extension SceneDelegate: UIWindowSceneDelegate { } func sceneDidBecomeActive(_ scene: UIScene) { - TunnelManager.shared.refreshTunnelStatus() - if isSceneConfigured { accountDataThrottling.requestUpdate( condition: settingsNavController == nil @@ -129,31 +127,18 @@ extension SceneDelegate: UIWindowSceneDelegate { ) } - RelayCacheTracker.shared.startPeriodicUpdates() - TunnelManager.shared.startPeriodicPrivateKeyRotation() - AddressCacheTracker.shared.startPeriodicUpdates() ShortcutsManager.shared.updateVoiceShortcuts() setShowsPrivacyOverlay(false) } func sceneWillResignActive(_ scene: UIScene) { - RelayCacheTracker.shared.stopPeriodicUpdates() - TunnelManager.shared.stopPeriodicPrivateKeyRotation() - AddressCacheTracker.shared.stopPeriodicUpdates() - setShowsPrivacyOverlay(true) } - func sceneWillEnterForeground(_ scene: UIScene) { - // no-op - } - - func sceneDidEnterBackground(_ scene: UIScene) { - let appDelegate = UIApplication.shared.delegate as? AppDelegate + func sceneWillEnterForeground(_ scene: UIScene) {} - appDelegate?.scheduleBackgroundTasks() - } + func sceneDidEnterBackground(_ scene: UIScene) {} } // MARK: - SettingsButtonInteractionDelegate |
