diff --git a/apps/ios/Shared/ContentView.swift b/apps/ios/Shared/ContentView.swift index 9206d44d10..6af2947781 100644 --- a/apps/ios/Shared/ContentView.swift +++ b/apps/ios/Shared/ContentView.swift @@ -12,7 +12,7 @@ struct ContentView: View { @ObservedObject var alertManager = AlertManager.shared @ObservedObject var callController = CallController.shared @Binding var doAuthenticate: Bool - @State private var userAuthorized: Bool? + @Binding var userAuthorized: Bool? @State private var showChatInfo: Bool = false // TODO comprehensively close modal views on authentication @AppStorage(DEFAULT_SHOW_LA_NOTICE) private var prefShowLANotice = false @AppStorage(DEFAULT_LA_NOTICE_SHOWN) private var prefLANoticeShown = false @@ -58,20 +58,27 @@ struct ContentView: View { private func runAuthenticate() { if !prefPerformLA { userAuthorized = true - } else { + } else if showChatInfo { showChatInfo = false - userAuthorized = false - authenticate(reason: NSLocalizedString("Unlock", comment: "authentication reason")) { laResult in - switch (laResult) { - case .success: - userAuthorized = true - case .failed: - AlertManager.shared.showAlert(laFailedAlert()) - case .unavailable: - userAuthorized = true - prefPerformLA = false - AlertManager.shared.showAlert(laUnavailableTurningOffAlert()) - } + DispatchQueue.main.async { + justAuthenticate() + } + } else { + justAuthenticate() + } + } + + private func justAuthenticate() { + authenticate(reason: NSLocalizedString("Unlock", comment: "authentication reason")) { laResult in + switch (laResult) { + case .success: + userAuthorized = true + case .failed: + AlertManager.shared.showAlert(laFailedAlert()) + case .unavailable: + userAuthorized = true + prefPerformLA = false + AlertManager.shared.showAlert(laUnavailableTurningOffAlert()) } } } diff --git a/apps/ios/Shared/SimpleXApp.swift b/apps/ios/Shared/SimpleXApp.swift index 0aad18a3e7..730e0cecc3 100644 --- a/apps/ios/Shared/SimpleXApp.swift +++ b/apps/ios/Shared/SimpleXApp.swift @@ -30,7 +30,7 @@ struct SimpleXApp: App { var body: some Scene { return WindowGroup { - ContentView(doAuthenticate: $doAuthenticate) + ContentView(doAuthenticate: $doAuthenticate, userAuthorized: $userAuthorized) .environmentObject(chatModel) .onOpenURL { url in logger.debug("ContentView.onOpenURL: \(url)") @@ -45,10 +45,14 @@ struct SimpleXApp: App { switch (phase) { case .background: BGManager.shared.schedule() + if userAuthorized == true { + enteredBackground = ProcessInfo.processInfo.systemUptime + } doAuthenticate = false - enteredBackground = ProcessInfo.processInfo.systemUptime + userAuthorized = false case .active: doAuthenticate = authenticationExpired() + if !doAuthenticate { userAuthorized = true } default: break }