From 7da881ae3e473b9b48657d4838e86da95072c34f Mon Sep 17 00:00:00 2001 From: Doug <6060466+pixlwave@users.noreply.github.com> Date: Tue, 5 Dec 2023 11:13:51 +0000 Subject: [PATCH] Add an extra call to obscure the app on willEnterForeground. (#2202) It shouldn't be necessary given the double call by the time the app is backgrounded, but we're still seeing occasional room list flashes. --- .../AppLockFlowCoordinator.swift | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/ElementX/Sources/FlowCoordinators/AppLockFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/AppLockFlowCoordinator.swift index 3567dae97..60f648266 100644 --- a/ElementX/Sources/FlowCoordinators/AppLockFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/AppLockFlowCoordinator.swift @@ -44,6 +44,8 @@ class AppLockFlowCoordinator: CoordinatorProtocol { case appObscured /// The app is in the background. case backgrounded + /// The app is returning to the foreground. + case launching /// The app is presenting biometric unlock to the user. case attemptingBiometricUnlock /// Biometric unlock has completed but the system UI is still the active input. @@ -63,6 +65,8 @@ class AppLockFlowCoordinator: CoordinatorProtocol { case willResignActive /// The app is now backgrounded and not visible to the user. case didEnterBackground + /// The app is in the background and has just been launched by the user. + case willEnterForeground /// The app is in the foreground and has been given focus. case didBecomeActive /// Biometric unlock has completed with the following result. @@ -116,6 +120,12 @@ class AppLockFlowCoordinator: CoordinatorProtocol { } .store(in: &cancellables) + notificationCenter.publisher(for: UIApplication.willEnterForegroundNotification) + .sink { [weak self] _ in + self?.stateMachine.tryEvent(.willEnterForeground) + } + .store(in: &cancellables) + notificationCenter.publisher(for: UIApplication.didBecomeActiveNotification) .sink { [weak self] _ in self?.stateMachine.tryEvent(.didBecomeActive) @@ -149,7 +159,9 @@ class AppLockFlowCoordinator: CoordinatorProtocol { return .unlocked case (_, .didEnterBackground): return .backgrounded - case (.backgrounded, .didBecomeActive): + case (_, .willEnterForeground): + return .launching + case (.launching, .didBecomeActive): guard appLockService.computeNeedsUnlock(didBecomeActiveAt: .now) else { return .unlocked } return isBiometricUnlockAvailable ? .attemptingBiometricUnlock : .attemptingPINUnlock case (.attemptingBiometricUnlock, .didFinishBiometricUnlock(let result)): @@ -188,8 +200,10 @@ class AppLockFlowCoordinator: CoordinatorProtocol { case (_, .backgrounded): appLockService.applicationDidEnterBackground() showPlaceholder() // Double call but just to be safe. Useful at app launch. + case (_, .launching): + showPlaceholder() // Triple call but necessary after being suspended. case (_, .attemptingBiometricUnlock): - showPlaceholder() // For the unlock background. Triple call but just to be safe. + showPlaceholder() // For the unlock background. Quadruple call but just to be safe. Task { await self.attemptBiometricUnlock() } case (.attemptingBiometricUnlock, .dismissingBiometricUnlock): break // Transitional state, no need to do anything.