ios: fix purple warning on auth failure (#724)

* ios: fix purple warning on auth failure

* avoid showing chats

* avoid flicker

* fix exit

* bg task

* rename function

* remove bg task
This commit is contained in:
Evgeny Poberezkin
2022-06-03 12:24:50 +01:00
committed by GitHub
parent 3b708105a4
commit 72103949a7
2 changed files with 27 additions and 16 deletions
+21 -14
View File
@@ -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())
}
}
}
+6 -2
View File
@@ -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
}