2022-01-29 18:59:42 +01:00
|
|
|
import SwiftUI
|
2023-12-12 17:33:42 +01:00
|
|
|
import SwiftData
|
2022-01-29 18:59:42 +01:00
|
|
|
import CryptoKit
|
|
|
|
|
|
|
|
struct ContentView: View {
|
2023-04-11 18:18:31 +02:00
|
|
|
|
2023-12-12 17:33:42 +01:00
|
|
|
private let unlockButtonSize: CGFloat = 250
|
|
|
|
private let smallButtonSize: CGFloat = 50
|
|
|
|
private let buttonBackground: Color = .white.opacity(0.2)
|
|
|
|
private let buttonColor: Color = .white
|
2023-04-11 18:18:31 +02:00
|
|
|
|
2023-08-14 10:39:29 +02:00
|
|
|
@ObservedObject
|
2023-12-12 17:33:42 +01:00
|
|
|
var coordinator: RequestCoordinator
|
2023-04-11 18:18:31 +02:00
|
|
|
|
2023-12-12 17:33:42 +01:00
|
|
|
@State private var showSettingsSheet = false
|
|
|
|
@State private var showHistorySheet = false
|
|
|
|
@State private var didShowKeySheetOnce = false
|
2023-04-11 18:18:31 +02:00
|
|
|
|
2023-12-12 17:33:42 +01:00
|
|
|
init(modelContext: ModelContext) {
|
|
|
|
self.coordinator = .init(modelContext: modelContext)
|
2022-04-09 17:43:33 +02:00
|
|
|
}
|
2023-12-12 17:33:42 +01:00
|
|
|
|
2022-01-29 18:59:42 +01:00
|
|
|
var body: some View {
|
2023-12-12 17:33:42 +01:00
|
|
|
VStack(spacing: 20) {
|
|
|
|
HStack {
|
|
|
|
Spacer()
|
|
|
|
Text("Sesame")
|
|
|
|
.font(.title)
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
Text(coordinator.state.description)
|
|
|
|
Spacer()
|
|
|
|
HStack(alignment: .bottom, spacing: 0) {
|
|
|
|
Button(action: { showHistorySheet = true }) {
|
|
|
|
Image(systemSymbol: .clockArrowCirclepath)
|
2022-05-01 14:07:43 +02:00
|
|
|
.foregroundColor(.white)
|
2023-12-12 17:33:42 +01:00
|
|
|
.frame(width: smallButtonSize, height: smallButtonSize)
|
2022-05-01 14:07:43 +02:00
|
|
|
.background(.white.opacity(0.2))
|
2023-12-12 17:33:42 +01:00
|
|
|
.cornerRadius(smallButtonSize / 2)
|
2022-05-01 14:07:43 +02:00
|
|
|
.font(.title2)
|
2023-12-12 17:33:42 +01:00
|
|
|
|
2022-01-29 18:59:42 +01:00
|
|
|
}
|
2023-12-12 17:33:42 +01:00
|
|
|
Button("Unlock", action: coordinator.startUnlock)
|
|
|
|
.frame(width: unlockButtonSize, height: unlockButtonSize)
|
2022-04-09 17:43:33 +02:00
|
|
|
.background(buttonBackground)
|
2023-12-12 17:33:42 +01:00
|
|
|
.cornerRadius(unlockButtonSize / 2)
|
2022-04-09 17:43:33 +02:00
|
|
|
.foregroundColor(buttonColor)
|
|
|
|
.font(.title)
|
2023-12-12 17:33:42 +01:00
|
|
|
Button(action: { showSettingsSheet = true }) {
|
|
|
|
Image(systemSymbol: .gearshape)
|
|
|
|
.foregroundColor(.white)
|
|
|
|
.frame(width: smallButtonSize, height: smallButtonSize)
|
|
|
|
.background(.white.opacity(0.2))
|
|
|
|
.cornerRadius(smallButtonSize / 2)
|
|
|
|
.font(.title2)
|
2022-04-09 17:43:33 +02:00
|
|
|
}
|
|
|
|
}
|
2023-12-12 17:33:42 +01:00
|
|
|
|
|
|
|
Picker("Connection type", selection: $coordinator.connectionType) {
|
2023-12-20 19:00:38 +01:00
|
|
|
Text(ConnectionStrategy.local.description).tag(ConnectionStrategy.local)
|
|
|
|
Text(ConnectionStrategy.remote.description).tag(ConnectionStrategy.remote)
|
|
|
|
Text(ConnectionStrategy.remoteFirst.description).tag(ConnectionStrategy.remoteFirst)
|
|
|
|
// ForEach(ConnectionStrategy.allCases, id: \.rawValue) { connection in
|
|
|
|
// Text(connection.description).tag(connection)
|
|
|
|
// }
|
2022-05-01 18:30:30 +02:00
|
|
|
}
|
2023-12-12 17:33:42 +01:00
|
|
|
.pickerStyle(.segmented)
|
|
|
|
.padding(.horizontal, 30)
|
2022-04-09 17:43:33 +02:00
|
|
|
}
|
2023-12-12 17:33:42 +01:00
|
|
|
.background(coordinator.state.color)
|
|
|
|
.animation(.easeInOut, value: coordinator.state.color)
|
|
|
|
.sheet(isPresented: $showSettingsSheet) {
|
|
|
|
SettingsView(
|
|
|
|
keyManager: coordinator.keyManager,
|
|
|
|
serverAddress: $coordinator.serverPath,
|
|
|
|
localAddress: $coordinator.localAddress)
|
|
|
|
}
|
|
|
|
.sheet(isPresented: $showHistorySheet) { HistoryView() }
|
2022-05-01 18:30:30 +02:00
|
|
|
.preferredColorScheme(.dark)
|
2022-01-29 18:59:42 +01:00
|
|
|
}
|
|
|
|
|
2023-04-11 18:18:31 +02:00
|
|
|
|
2022-01-29 18:59:42 +01:00
|
|
|
|
|
|
|
}
|
2022-04-09 17:43:33 +02:00
|
|
|
|
2023-12-12 17:33:42 +01:00
|
|
|
#Preview {
|
|
|
|
do {
|
|
|
|
let config = ModelConfiguration(isStoredInMemoryOnly: true)
|
|
|
|
let container = try ModelContainer(for: HistoryItem.self, configurations: config)
|
|
|
|
|
|
|
|
let item = HistoryItem.mock
|
|
|
|
container.mainContext.insert(item)
|
|
|
|
try container.mainContext.save()
|
|
|
|
return ContentView(modelContext: container.mainContext)
|
|
|
|
.modelContainer(container)
|
|
|
|
} catch {
|
|
|
|
fatalError("Failed to create model container.")
|
2022-04-09 17:43:33 +02:00
|
|
|
}
|
|
|
|
}
|