Update Tunnel on the main thread

Also updated it to use the new Swift Observable macro
This commit is contained in:
Conrad Kramer 2024-01-20 09:39:30 -08:00
parent b008762a5b
commit 436a67b352
10 changed files with 167 additions and 69 deletions

View file

@ -1,36 +1,34 @@
import SwiftUI
struct TunnelView: View {
// @ObservedObject var tunnel: Tunnel
var tunnel: Tunnel
var body: some View {
EmptyView()
// 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()
// }
// }
// .task { await tunnel.update() }
// .padding()
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() }
// }
private func start() {
try? tunnel.start()
}
private func stop() {
tunnel.stop()
}
private func configure() {
Task { try await tunnel.configure() }
}
}