ios: ask permission to open profiles (#1910)

This commit is contained in:
Stanislav Dmitrenko
2023-02-08 13:39:41 +03:00
committed by GitHub
parent 9e4499de6d
commit c006b8150f
4 changed files with 24 additions and 10 deletions
@@ -15,6 +15,16 @@ enum LAResult {
case unavailable(authError: String?)
}
func authorize(_ text: String, _ authorized: Binding<Bool>) {
authenticate(reason: text) { laResult in
switch laResult {
case .success: authorized.wrappedValue = true
case .unavailable: authorized.wrappedValue = true
case .failed: authorized.wrappedValue = false
}
}
}
func authenticate(reason: String, completed: @escaping (LAResult) -> Void) {
let laContext = LAContext()
var authAvailabilityError: NSError?
+1 -9
View File
@@ -30,15 +30,7 @@ struct TerminalView: View {
}
}
private func runAuth() {
authenticate(reason: NSLocalizedString("Open chat console", comment: "authentication reason")) { laResult in
switch laResult {
case .success: authorized = true
case .unavailable: authorized = true
case .failed: authorized = false
}
}
}
private func runAuth() { authorize(NSLocalizedString("Open chat console", comment: "authentication reason"), $authorized) }
private func terminalView() -> some View {
VStack {
@@ -121,7 +121,6 @@ struct SettingsView: View {
NavigationLink {
UserProfilesView()
.navigationTitle("Your chat profiles")
} label: {
settingsRow("person.crop.rectangle.stack") { Text("Your chat profiles") }
}
@@ -12,6 +12,7 @@ struct UserProfilesView: View {
@State private var showDeleteConfirmation = false
@State private var userToDelete: Int?
@State private var alert: UserProfilesAlert?
@State var authorized = !UserDefaults.standard.bool(forKey: DEFAULT_PERFORM_LA)
private enum UserProfilesAlert: Identifiable {
case deleteUser(index: Int, delSMPQueues: Bool)
@@ -28,6 +29,17 @@ struct UserProfilesView: View {
}
var body: some View {
if authorized {
userProfilesView()
} else {
Button(action: runAuth) { Label("Unlock", systemImage: "lock") }
.onAppear(perform: runAuth)
}
}
private func runAuth() { authorize(NSLocalizedString("Open user profiles", comment: "authentication reason"), $authorized) }
private func userProfilesView() -> some View {
List {
Section {
ForEach(m.users) { u in
@@ -52,6 +64,7 @@ struct UserProfilesView: View {
}
}
.toolbar { EditButton() }
.navigationTitle("Your chat profiles")
.confirmationDialog("Delete chat profile?", isPresented: $showDeleteConfirmation, titleVisibility: .visible) {
deleteModeButton("Profile and server connections", true)
deleteModeButton("Local profile data only", false)