diff --git a/apps/ios/Shared/ContentView.swift b/apps/ios/Shared/ContentView.swift index bb5ab76aaa..6a4f6ddcc7 100644 --- a/apps/ios/Shared/ContentView.swift +++ b/apps/ios/Shared/ContentView.swift @@ -12,16 +12,16 @@ struct ContentView: View { @ObservedObject var alertManager = AlertManager.shared @ObservedObject var callController = CallController.shared @Binding var doAuthenticate: Bool - @Binding var enteredBackground: Double? @State private var userAuthorized: Bool? - @State private var laFailed: Bool = false @AppStorage(DEFAULT_SHOW_LA_NOTICE) private var prefShowLANotice = false @AppStorage(DEFAULT_LA_NOTICE_SHOWN) private var prefLANoticeShown = false @AppStorage(DEFAULT_PERFORM_LA) private var prefPerformLA = false var body: some View { ZStack { - if userAuthorized == true { + if prefPerformLA && userAuthorized != true { + Button(action: runAuthenticate) { Label("Unlock", systemImage: "lock") } + } else { if let step = chatModel.onboardingStage { if case .onboardingComplete = step, let user = chatModel.currentUser { @@ -47,25 +47,13 @@ struct ContentView: View { OnboardingView(onboarding: step) } } - } else if prefPerformLA && laFailed { - retryAuthView() - } - } - .onChange(of: doAuthenticate) { doAuth in - if doAuth, authenticationExpired() { - runAuthenticate() } } + .onAppear { if doAuthenticate { runAuthenticate() } } + .onChange(of: doAuthenticate) { _ in if doAuthenticate { runAuthenticate() } } .alert(isPresented: $alertManager.presentAlert) { alertManager.alertView! } } - private func retryAuthView() -> some View { - Button { - laFailed = false - runAuthenticate() - } label: { Label("Retry", systemImage: "arrow.counterclockwise") } - } - private func runAuthenticate() { if !prefPerformLA { userAuthorized = true @@ -78,7 +66,6 @@ struct ContentView: View { case .success: userAuthorized = true case .failed: - laFailed = true AlertManager.shared.showAlert(laFailedAlert()) case .unavailable: userAuthorized = true @@ -90,14 +77,6 @@ struct ContentView: View { } } - private func authenticationExpired() -> Bool { - if let enteredBackground = enteredBackground { - return ProcessInfo.processInfo.systemUptime - enteredBackground >= 30 - } else { - return true - } - } - func laNoticeAlert() -> Alert { Alert( title: Text("SimpleX Lock"), diff --git a/apps/ios/Shared/SimpleXApp.swift b/apps/ios/Shared/SimpleXApp.swift index e1a54748b3..0aad18a3e7 100644 --- a/apps/ios/Shared/SimpleXApp.swift +++ b/apps/ios/Shared/SimpleXApp.swift @@ -17,8 +17,8 @@ struct SimpleXApp: App { @ObservedObject var alertManager = AlertManager.shared @Environment(\.scenePhase) var scenePhase @AppStorage(DEFAULT_PERFORM_LA) private var prefPerformLA = false - @State private var userAuthorized: Bool? = nil - @State private var doAuthenticate: Bool = false + @State private var userAuthorized: Bool? + @State private var doAuthenticate = false @State private var enteredBackground: Double? = nil init() { @@ -30,7 +30,7 @@ struct SimpleXApp: App { var body: some Scene { return WindowGroup { - ContentView(doAuthenticate: $doAuthenticate, enteredBackground: $enteredBackground) + ContentView(doAuthenticate: $doAuthenticate) .environmentObject(chatModel) .onOpenURL { url in logger.debug("ContentView.onOpenURL: \(url)") @@ -48,11 +48,19 @@ struct SimpleXApp: App { doAuthenticate = false enteredBackground = ProcessInfo.processInfo.systemUptime case .active: - doAuthenticate = true + doAuthenticate = authenticationExpired() default: break } } } } + + private func authenticationExpired() -> Bool { + if let enteredBackground = enteredBackground { + return ProcessInfo.processInfo.systemUptime - enteredBackground >= 30 + } else { + return true + } + } }