diff --git a/Apple/App/BurrowApp.swift b/Apple/App/BurrowApp.swift index 6d798fb..e8aed86 100644 --- a/Apple/App/BurrowApp.swift +++ b/Apple/App/BurrowApp.swift @@ -15,7 +15,7 @@ struct BurrowApp: App { var body: some Scene { WindowGroup { - TunnelView() + TunnelView(tunnel: Self.tunnel) } } } diff --git a/Apple/App/TunnelView.swift b/Apple/App/TunnelView.swift index e3b9e28..0cbce70 100644 --- a/Apple/App/TunnelView.swift +++ b/Apple/App/TunnelView.swift @@ -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() } + } }