import SwiftUI import SwiftData import CryptoKit struct ContentView: View { private let unlockButtonSize: CGFloat = 250 private let smallButtonSize: CGFloat = 50 private let buttonBackground: Color = .white.opacity(0.2) private let buttonColor: Color = .white @ObservedObject var coordinator: RequestCoordinator @State private var showSettingsSheet = false @State private var showHistorySheet = false @State private var didShowKeySheetOnce = false init(modelContext: ModelContext) { self.coordinator = .init(modelContext: modelContext) } var body: some View { VStack(spacing: 20) { HStack { Spacer() Text("Sesame") .font(.title) Spacer() } if coordinator.state != .notChecked { Text(coordinator.state.description) } Spacer() HStack(alignment: .bottom, spacing: 0) { Button(action: { showHistorySheet = true }) { Image(systemSymbol: .clockArrowCirclepath) .foregroundColor(.white) .frame(width: smallButtonSize, height: smallButtonSize) .background(.white.opacity(0.2)) .cornerRadius(smallButtonSize / 2) .font(.title2) } Button("Unlock", action: unlock) .frame(width: unlockButtonSize, height: unlockButtonSize) .background(buttonBackground) .cornerRadius(unlockButtonSize / 2) .foregroundColor(buttonColor) .font(.title) Button(action: { showSettingsSheet = true }) { Image(systemSymbol: .gearshape) .foregroundColor(.white) .frame(width: smallButtonSize, height: smallButtonSize) .background(.white.opacity(0.2)) .cornerRadius(smallButtonSize / 2) .font(.title2) } } Picker("Connection type", selection: $coordinator.connectionType) { 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) // } } .pickerStyle(.segmented) .padding(.horizontal, 30) } .background(coordinator.state.color) .animation(.easeInOut, value: coordinator.state.color) .sheet(isPresented: $showSettingsSheet) { SettingsView( keyManager: coordinator.keyManager, coordinator: coordinator, serverAddress: $coordinator.serverPath, localAddress: $coordinator.localAddress, localPort: $coordinator.localPort) } .sheet(isPresented: $showHistorySheet) { HistoryView() } .preferredColorScheme(.dark) } private func unlock() { coordinator.startUnlock() } } #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.") } }