Created simple burrow UI for iOS

Edited the existing view so that if running on an iOS device it would
provide a basic UI with a toggle switch that will allow the user to
connect/disconnect from the VPN.
This commit is contained in:
Conrad Kramer 2023-09-09 11:18:21 -07:00
parent 6368ca7f74
commit 2152fc3081
2 changed files with 48 additions and 28 deletions

View file

@ -15,7 +15,7 @@ struct BurrowApp: App {
var body: some Scene {
WindowGroup {
TunnelView()
TunnelView(tunnel: Self.tunnel)
}
}
}

View file

@ -1,36 +1,56 @@
import SwiftUI
struct TunnelView: View {
// @ObservedObject var tunnel: Tunnel
@ObservedObject var tunnel: Tunnel
@State var useBurrow = false
var body: some View {
#if os(iOS)
Text("Burrow")
.font(.largeTitle)
.fontWeight(.heavy)
VStack {
switch tunnel.status {
case .connecting, .disconnecting:
ProgressView().controlSize(.large).padding()
case .permissionRequired:
var useBurrow = false
Button("Configure VPN", action: configure).buttonStyle(.borderedProminent).tint(.red).padding()
default:
// for someone else to do: clean up my code and make the toggle VERY large that it's juicy. - R. Ruiz (allthesquares)
Toggle("", isOn: $useBurrow)
.disabled(tunnel.status == .unknown || tunnel.status == .configurationReadWriteFailed || tunnel.status == .invalid)
.labelsHidden()
.controlSize(.large)
.padding()
.toggleStyle(SwitchToggleStyle(tint: .red))
.onChange(of: useBurrow) { value in
if value == true {
start()
} else {
stop()
}
}
}
Text(verbatim: tunnel.status.description)
}
.task { await tunnel.update() }
#else
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()
#endif
}
// 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() }
}
}