Switch to gRPC client in Swift app
This commit is contained in:
parent
25a0f7c421
commit
083ec73613
93 changed files with 1666 additions and 1327 deletions
27
Apple/UI/Networks/HackClub.swift
Normal file
27
Apple/UI/Networks/HackClub.swift
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import BurrowCore
|
||||
import SwiftUI
|
||||
|
||||
struct HackClub: Network {
|
||||
typealias NetworkType = Burrow_WireGuardNetwork
|
||||
static let type: Burrow_NetworkType = .hackClub
|
||||
|
||||
var id: Int32
|
||||
var backgroundColor: Color { .init("HackClub") }
|
||||
|
||||
@MainActor var label: some View {
|
||||
GeometryReader { reader in
|
||||
VStack(alignment: .leading) {
|
||||
Image("HackClub")
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(height: reader.size.height / 4)
|
||||
Spacer()
|
||||
Text("@conradev")
|
||||
.foregroundStyle(.white)
|
||||
.font(.body.monospaced())
|
||||
}
|
||||
.padding()
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
}
|
||||
}
|
||||
36
Apple/UI/Networks/Network.swift
Normal file
36
Apple/UI/Networks/Network.swift
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import Atomics
|
||||
import BurrowCore
|
||||
import SwiftProtobuf
|
||||
import SwiftUI
|
||||
|
||||
protocol Network {
|
||||
associatedtype NetworkType: Message
|
||||
associatedtype Label: View
|
||||
|
||||
static var type: Burrow_NetworkType { get }
|
||||
|
||||
var id: Int32 { get }
|
||||
var backgroundColor: Color { get }
|
||||
|
||||
@MainActor var label: Label { get }
|
||||
}
|
||||
|
||||
@Observable
|
||||
@MainActor
|
||||
final class NetworkViewModel: Sendable {
|
||||
private(set) var networks: [Burrow_Network] = []
|
||||
|
||||
private var task: Task<Void, Error>!
|
||||
|
||||
init(socketURL: URL) {
|
||||
task = Task { [weak self] in
|
||||
let client = NetworksClient.unix(socketURL: socketURL)
|
||||
for try await networks in client.networkList(.init()) {
|
||||
guard let viewModel = self else { continue }
|
||||
Task { @MainActor in
|
||||
viewModel.networks = networks.network
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Apple/UI/Networks/WireGuard.swift
Normal file
34
Apple/UI/Networks/WireGuard.swift
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import BurrowCore
|
||||
import SwiftUI
|
||||
|
||||
struct WireGuard: Network {
|
||||
typealias NetworkType = Burrow_WireGuardNetwork
|
||||
static let type: BurrowCore.Burrow_NetworkType = .wireGuard
|
||||
|
||||
var id: Int32
|
||||
var backgroundColor: Color { .init("WireGuard") }
|
||||
|
||||
@MainActor var label: some View {
|
||||
GeometryReader { reader in
|
||||
VStack(alignment: .leading) {
|
||||
HStack {
|
||||
Image("WireGuard")
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
Image("WireGuardTitle")
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: reader.size.width / 2)
|
||||
Spacer()
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: reader.size.height / 4)
|
||||
Spacer()
|
||||
Text("@conradev")
|
||||
.foregroundStyle(.white)
|
||||
.font(.body.monospaced())
|
||||
}
|
||||
.padding()
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue