This commit is contained in:
Christoph Hagen 2022-04-13 14:55:47 +02:00
parent 4723c98502
commit 0e0166f308
3 changed files with 36 additions and 23 deletions

View File

@ -96,7 +96,7 @@ enum ClientState {
}
}
var openButtonText: String {
var actionText: String {
switch self {
case .noKeyAvailable:
return "Create key"
@ -104,19 +104,38 @@ enum ClientState {
return "Unlock"
}
}
var openButtonColor: Color {
var requiresDescription: Bool {
switch self {
case .noKeyAvailable, .requestingStatus:
return .yellow
case .deviceNotAvailable, .messageRejected, .internalError:
return true
default:
return false
}
}
var color: Color {
switch self {
case .noKeyAvailable:
return .gray
case .requestingStatus:
return .yellow
case .deviceNotAvailable:
return Color(red: 1.0, green: 0.6, blue: 0.6)
case .messageRejected:
return .red
case .ready, .waitingForResponse, .openSesame:
case .internalError:
return Color(red: 0.7, green: 0, blue: 0)
case .ready:
return Color(red: 0.7, green: 1.0, blue: 0.5)
case .waitingForResponse:
return Color(red: 0.9, green: 1.0, blue: 0.5)
case .openSesame:
return .green
}
}
var openButtonIsEnabled: Bool {
var allowsAction: Bool {
switch self {
case .requestingStatus, .deviceNotAvailable, .waitingForResponse:
return false

View File

@ -26,7 +26,7 @@ struct ContentView: View {
}
var buttonBackground: Color {
state.openButtonIsEnabled ?
state.allowsAction ?
.white.opacity(0.2) :
.gray.opacity(0.2)
}
@ -34,34 +34,28 @@ struct ContentView: View {
let buttonBorderWidth: CGFloat = 3
var buttonColor: Color {
state.openButtonIsEnabled ? .white : .gray
state.allowsAction ? .white : .gray
}
private let buttonWidth: CGFloat = 200
private let topButtonHeight: CGFloat = 60
private let buttonWidth: CGFloat = 250
var body: some View {
GeometryReader { geo in
VStack(spacing: 20) {
Spacer()
HStack {
if isPerformingRequests {
ProgressView()
.progressViewStyle(CircularProgressViewStyle())
}
if state.requiresDescription {
Text(state.description)
.padding()
}
Button(state.openButtonText, action: mainButtonPressed)
Button(state.actionText, action: mainButtonPressed)
.frame(width: buttonWidth, height: buttonWidth, alignment: .center)
.background(buttonBackground)
.cornerRadius(buttonWidth / 2)
.overlay(RoundedRectangle(cornerRadius: buttonWidth / 2).stroke(lineWidth: buttonBorderWidth).foregroundColor(buttonColor))
.foregroundColor(buttonColor)
.font(.title)
.disabled(!state.openButtonIsEnabled)
.padding(20)
.disabled(!state.allowsAction)
.padding(.bottom, (geo.size.width-buttonWidth) / 2)
}
.onAppear {
if KeyManagement.hasKey {
@ -73,8 +67,8 @@ struct ContentView: View {
endRegularStatusUpdates()
}
.frame(width: geo.size.width, height: geo.size.height)
.background(state.openButtonColor)
.animation(.easeInOut, value: state.openButtonColor)
.background(state.color)
.animation(.easeInOut, value: state.color)
}
}

View File

@ -16,7 +16,7 @@ final class KeyManagement {
kSecClass as String: kSecClassInternetPassword,
kSecAttrAccount as String: "account",
kSecAttrServer as String: "christophhagen.de",
]//kSecAttrLabel as String: "sesame"]
kSecAttrLabel as String: "sesame"]
private static func loadKeys() -> Data? {
var query = query