burrow/Apple/App/TunnelView.swift
Conrad Kramer 436a67b352 Update Tunnel on the main thread
Also updated it to use the new Swift Observable macro
2024-01-20 09:45:47 -08:00

34 lines
747 B
Swift

import SwiftUI
struct TunnelView: View {
var tunnel: Tunnel
var body: some View {
VStack {
Text(verbatim: tunnel.status.description)
switch tunnel.status {
case .connected:
Button("Disconnect", action: stop)
case .permissionRequired:
Button("Allow", action: configure)
case .disconnected:
Button("Start", action: start)
default:
EmptyView()
}
}
.padding()
}
private func start() {
try? tunnel.start()
}
private func stop() {
tunnel.stop()
}
private func configure() {
Task { try await tunnel.configure() }
}
}