Add support for starting and stopping the tunnel
This commit introduces the Tunnel view model object which has support for asking for permission, starting and stopping the tunnel. It automatically updates its state and publishes changes as an ObservableObject.
This commit is contained in:
parent
eeb0130156
commit
b3a540fc48
8 changed files with 277 additions and 28 deletions
37
Apple/App/TunnelView.swift
Normal file
37
Apple/App/TunnelView.swift
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import SwiftUI
|
||||
|
||||
struct TunnelView: View {
|
||||
|
||||
@ObservedObject
|
||||
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()
|
||||
}
|
||||
}
|
||||
.task { await tunnel.update() }
|
||||
.padding()
|
||||
}
|
||||
|
||||
private func start() {
|
||||
try? tunnel.start()
|
||||
}
|
||||
|
||||
private func stop() {
|
||||
tunnel.stop()
|
||||
}
|
||||
|
||||
private func configure() {
|
||||
Task { try await tunnel.configure() }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue