Sesame-iOS/Sesame/MainView.swift

105 lines
3.9 KiB
Swift
Raw Normal View History

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-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-08-14 10:39:29 +02:00
@ObservedObject
2023-12-12 17:33:42 +01:00
var coordinator: RequestCoordinator
2023-12-12 17:33:42 +01:00
@State private var showSettingsSheet = false
@State private var showHistorySheet = false
@State private var didShowKeySheetOnce = false
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()
}
2023-12-20 19:04:48 +01:00
if coordinator.state != .notChecked {
Text(coordinator.state.description)
}
2023-12-12 17:33:42 +01:00
Spacer()
HStack(alignment: .bottom, spacing: 0) {
Button(action: { showHistorySheet = true }) {
Image(systemSymbol: .clockArrowCirclepath)
.foregroundColor(.white)
2023-12-12 17:33:42 +01:00
.frame(width: smallButtonSize, height: smallButtonSize)
.background(.white.opacity(0.2))
2023-12-12 17:33:42 +01:00
.cornerRadius(smallButtonSize / 2)
.font(.title2)
2022-01-29 18:59:42 +01:00
}
Button("Unlock", action: unlock)
2023-12-12 17:33:42 +01:00
.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)
// }
}
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(
2023-12-27 21:57:32 +01:00
keyManager: coordinator.keyManager,
coordinator: coordinator,
2023-12-12 17:33:42 +01:00
serverAddress: $coordinator.serverPath,
2024-04-22 12:58:49 +02:00
localAddress: $coordinator.localAddress,
localPort: $coordinator.localPort)
2023-12-12 17:33:42 +01:00
}
.sheet(isPresented: $showHistorySheet) { HistoryView() }
.preferredColorScheme(.dark)
2022-01-29 18:59:42 +01:00
}
private func unlock() {
coordinator.startUnlock()
}
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
}
}