diff --git a/Apple/App/App-macOS.entitlements b/Apple/App/App-macOS.entitlements index 53fcbb7..e39ba66 100644 --- a/Apple/App/App-macOS.entitlements +++ b/Apple/App/App-macOS.entitlements @@ -13,7 +13,7 @@ com.apple.security.application-groups - $(APP_GROUP_IDENTIFIER) + group.com.hackclub.burrow diff --git a/Apple/App/BurrowView.swift b/Apple/App/BurrowView.swift index 8447592..ab9c558 100644 --- a/Apple/App/BurrowView.swift +++ b/Apple/App/BurrowView.swift @@ -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.self) + alert("Successs!", isPresented: $showAlert){ + Button("OK", role: .cancel) {} + } + + } catch { + + } } private func authenticateWithSlack() async throws { diff --git a/Apple/NetworkExtension/PacketTunnelProvider.swift b/Apple/NetworkExtension/PacketTunnelProvider.swift index 89e0de6..094af50 100644 --- a/Apple/NetworkExtension/PacketTunnelProvider.swift +++ b/Apple/NetworkExtension/PacketTunnelProvider.swift @@ -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.self) + _ = try await client.single_request("Stop", params:nil, type: BurrowResult.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.self) + let srvConfig = try await client.single_request("ServerConfig", params: nil, type: BurrowResult.self) guard let serverconfig = srvConfig.Ok else { throw BurrowError.resultIsError } diff --git a/Apple/Shared/Client.swift b/Apple/Shared/Client.swift index f643c6c..7d753a8 100644 --- a/Apple/Shared/Client.swift +++ b/Apple/Shared/Client.swift @@ -81,10 +81,11 @@ public final class Client { ) return try await send(req) } - public func single_request(_ request: String, type: U.Type = U.self) async throws -> U { + public func single_request(_ 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) }