feat: add UnlockView with biometric and password unlock
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WYqycDFsynHH9VnnK7LNSf
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
//
|
||||
// UnlockView.swift
|
||||
// MyPass
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import MyPassCore
|
||||
|
||||
struct UnlockView: View {
|
||||
@ObservedObject var vm: UnlockViewModel
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 24) {
|
||||
Spacer()
|
||||
Image(systemName: "lock.shield.fill")
|
||||
.font(.system(size: 64))
|
||||
.foregroundStyle(.tint)
|
||||
Text("MyPass")
|
||||
.font(.largeTitle.bold())
|
||||
|
||||
if vm.hasVault {
|
||||
vaultUnlockSection
|
||||
} else {
|
||||
openFileSection
|
||||
}
|
||||
|
||||
if let msg = vm.errorMessage {
|
||||
Text(msg)
|
||||
.foregroundStyle(.red)
|
||||
.font(.caption)
|
||||
.multilineTextAlignment(.center)
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
.padding(32)
|
||||
.fileImporter(
|
||||
isPresented: $vm.showFilePicker,
|
||||
allowedContentTypes: [.init(filenameExtension: "kdbx")!],
|
||||
onCompletion: { result in
|
||||
if let url = try? result.get() { vm.openFile(url: url) }
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var vaultUnlockSection: some View {
|
||||
VStack(spacing: 16) {
|
||||
if vm.canUseBiometrics {
|
||||
Button(action: vm.unlockWithBiometrics) {
|
||||
Label("Use Face ID / Touch ID", systemImage: "faceid")
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
.disabled(vm.isUnlocking)
|
||||
|
||||
Text("or enter password")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
SecureField("Master Password", text: $vm.password)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
.onSubmit(vm.unlockWithPassword)
|
||||
|
||||
Button("Unlock", action: vm.unlockWithPassword)
|
||||
.buttonStyle(.bordered)
|
||||
.disabled(vm.password.isEmpty || vm.isUnlocking)
|
||||
|
||||
Button("Choose different file…") { vm.showFilePicker = true }
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var openFileSection: some View {
|
||||
VStack(spacing: 16) {
|
||||
Text("No vault selected. Open a .kdbx file to get started.")
|
||||
.multilineTextAlignment(.center)
|
||||
.foregroundStyle(.secondary)
|
||||
Button(action: { vm.showFilePicker = true }) {
|
||||
Label("Open KDBX File…", systemImage: "doc.badge.plus")
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user