WIP: UI for adding config
This commit is contained in:
parent
dd3f5d0d92
commit
f6241e90d5
4 changed files with 36 additions and 7 deletions
|
|
@ -13,7 +13,7 @@
|
|||
</array>
|
||||
<key>com.apple.security.application-groups</key>
|
||||
<array>
|
||||
<string>$(APP_GROUP_IDENTIFIER)</string>
|
||||
<string>group.com.hackclub.burrow</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
import AuthenticationServices
|
||||
import SwiftUI
|
||||
import BurrowShared
|
||||
|
||||
#if !os(macOS)
|
||||
struct BurrowView: View {
|
||||
@Environment(\.webAuthenticationSession)
|
||||
private var webAuthenticationSession
|
||||
@State private var rpcClient: Client? = nil
|
||||
@State private var showAlert = false
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
|
|
@ -17,6 +20,7 @@ struct BurrowView: View {
|
|||
Menu {
|
||||
Button("Hack Club", action: addHackClubNetwork)
|
||||
Button("WireGuard", action: addWireGuardNetwork)
|
||||
Button("Custom", action: sncAddCustomnetwork)
|
||||
} label: {
|
||||
Image(systemName: "plus.circle.fill")
|
||||
.font(.title)
|
||||
|
|
@ -34,7 +38,7 @@ struct BurrowView: View {
|
|||
.handleOAuth2Callback()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func addHackClubNetwork() {
|
||||
Task {
|
||||
try await authenticateWithSlack()
|
||||
|
|
@ -42,7 +46,31 @@ struct BurrowView: View {
|
|||
}
|
||||
|
||||
private func addWireGuardNetwork() {
|
||||
|
||||
}
|
||||
private func getClient() throws -> Client {
|
||||
if self.rpcClient == nil {
|
||||
let client = try Client()
|
||||
self.rpcClient = client
|
||||
}
|
||||
return self.rpcClient!
|
||||
}
|
||||
private func sncAddCustomnetwork() {
|
||||
Task {
|
||||
try await addCustomnetwork()
|
||||
}
|
||||
}
|
||||
private func addCustomnetwork() async {
|
||||
do {
|
||||
let networkToml = ""
|
||||
let client = try getClient()
|
||||
try await client.single_request("AddConfigToml", params: networkToml, type: BurrowResult<AnyResponseData>.self)
|
||||
alert("Successs!", isPresented: $showAlert){
|
||||
Button("OK", role: .cancel) {}
|
||||
}
|
||||
|
||||
} catch {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private func authenticateWithSlack() async throws {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
|||
override func stopTunnel(with reason: NEProviderStopReason) async {
|
||||
do {
|
||||
let client = try Client()
|
||||
_ = try await client.single_request("Stop", type: BurrowResult<AnyResponseData>.self)
|
||||
_ = try await client.single_request("Stop", params:nil, type: BurrowResult<AnyResponseData>.self)
|
||||
self.logger.log("Stopped client.")
|
||||
} catch {
|
||||
self.logger.error("Failed to stop tunnel: \(error)")
|
||||
|
|
@ -51,7 +51,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
|||
guard let client = self.client else {
|
||||
throw BurrowError.noClient
|
||||
}
|
||||
let srvConfig = try await client.single_request("ServerConfig", type: BurrowResult<ServerConfig>.self)
|
||||
let srvConfig = try await client.single_request("ServerConfig", params: nil, type: BurrowResult<ServerConfig>.self)
|
||||
guard let serverconfig = srvConfig.Ok else {
|
||||
throw BurrowError.resultIsError
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,10 +81,11 @@ public final class Client {
|
|||
)
|
||||
return try await send(req)
|
||||
}
|
||||
public func single_request<U: Decodable>(_ request: String, type: U.Type = U.self) async throws -> U {
|
||||
public func single_request<U: Decodable>(_ request: String, params: String? = nil, type: U.Type = U.self) async throws -> U {
|
||||
let req = BurrowSimpleRequest(
|
||||
id: generator.next(upperBound: UInt.max),
|
||||
command: request
|
||||
command: request,
|
||||
params:params
|
||||
)
|
||||
return try await send(req)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue