This commit is contained in:
Neil Alexander 2023-06-27 00:02:17 +01:00
parent c70dd740f9
commit 0553f929f6
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
5 changed files with 38 additions and 21 deletions

View file

@ -64,7 +64,7 @@ class ConfigurationProxy: PlatformItemSource {
self.set("Listen", to: [] as [String]) self.set("Listen", to: [] as [String])
self.set("AdminListen", to: "none") self.set("AdminListen", to: "none")
self.set("IfName", to: "dummy") self.set("IfName", to: "dummy")
// self.set("Peers", to: ["tcp://172.22.97.1.5190", "tls://172.22.97.1:5191"]) self.set("Peers", to: ["tcp://172.22.97.1.5190", "tls://172.22.97.1:5191"])
if self.get("AutoStart") == nil { if self.get("AutoStart") == nil {
self.set("AutoStart", to: ["Any": false, "WiFi": false, "Mobile": false, "Ethernet": false] as [String: Bool]) self.set("AutoStart", to: ["Any": false, "WiFi": false, "Mobile": false, "Ethernet": false] as [String: Bool])

View file

@ -65,6 +65,7 @@ class CrossPlatformAppDelegate: PlatformAppDelegate, ObservableObject {
} }
} }
@Published var yggdrasilSupported: Bool = true
@Published var yggdrasilConnected: Bool = false @Published var yggdrasilConnected: Bool = false
@Published var yggdrasilPublicKey: String = "N/A" @Published var yggdrasilPublicKey: String = "N/A"
@ -122,11 +123,13 @@ class CrossPlatformAppDelegate: PlatformAppDelegate, ObservableObject {
NETunnelProviderManager.loadAllFromPreferences { (savedManagers: [NETunnelProviderManager]?, error: Error?) in NETunnelProviderManager.loadAllFromPreferences { (savedManagers: [NETunnelProviderManager]?, error: Error?) in
guard error == nil else { guard error == nil else {
print("Failed to load VPN managers: \(error?.localizedDescription ?? "(no error)")") print("Failed to load VPN managers: \(error?.localizedDescription ?? "(no error)")")
self.yggdrasilSupported = false
return return
} }
guard let savedManagers else { guard let savedManagers else {
print("Expected to find saved managers but didn't") print("Expected to find saved managers but didn't")
self.yggdrasilSupported = false
return return
} }

View file

@ -546,7 +546,7 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = YggdrasilNetworkExtension.entitlements; CODE_SIGN_ENTITLEMENTS = "Yggdrasil Network Extension/YggdrasilNetworkExtension.entitlements";
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 32; CURRENT_PROJECT_VERSION = 32;
@ -578,7 +578,7 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = YggdrasilNetworkExtension.entitlements; CODE_SIGN_ENTITLEMENTS = "Yggdrasil Network Extension/YggdrasilNetworkExtension.entitlements";
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 32; CURRENT_PROJECT_VERSION = 32;

View file

@ -11,8 +11,6 @@ struct PeersView: View {
// @Binding public var yggdrasilConfiguration: ConfigurationProxy // @Binding public var yggdrasilConfiguration: ConfigurationProxy
@ObservedObject private var appDelegate = Application.appDelegate @ObservedObject private var appDelegate = Application.appDelegate
@State private var peers = ["Paul", "Taylor", "Adele"]
var body: some View { var body: some View {
Form { Form {
Section(content: { Section(content: {
@ -24,7 +22,8 @@ struct PeersView: View {
#if os(macOS) #if os(macOS)
Spacer() Spacer()
Button(role: .destructive) { Button(role: .destructive) {
print("Deleting") // appDelegate.yggdrasilConfig.peers.remove { $0 == peerURI }
// self.delete(at: appDelegate.yggdrasilConfig.peers.firstIndex { $0 == peerURI })
} label: { } label: {
Image(systemName: "xmark.circle.fill") Image(systemName: "xmark.circle.fill")
} }
@ -32,7 +31,20 @@ struct PeersView: View {
#endif #endif
} }
} }
.onDelete(perform: delete) .onMove { indexSet, offset in
appDelegate.yggdrasilConfig.peers.move(fromOffsets: indexSet, toOffset: offset)
}
.onDelete { indexSet in
appDelegate.yggdrasilConfig.peers.remove(atOffsets: indexSet)
}
Button {
appDelegate.yggdrasilConfig.peers.append("foo")
} label: {
Label("Add peer", systemImage: "plus")
}
.buttonStyle(.plain)
.foregroundColor(.accentColor)
Text("Yggdrasil will automatically attempt to connect to configured peers when started. If you configure more than one peer, your device may carry traffic on behalf of other network nodes. Avoid this by configuring only a single peer. Data charges may apply when using mobile data.") Text("Yggdrasil will automatically attempt to connect to configured peers when started. If you configure more than one peer, your device may carry traffic on behalf of other network nodes. Avoid this by configuring only a single peer. Data charges may apply when using mobile data.")
.font(.system(size: 11)) .font(.system(size: 11))
@ -64,12 +76,7 @@ struct PeersView: View {
} }
#if os(iOS) #if os(iOS)
.toolbar { .toolbar {
Button(role: nil, action: { // EditButton()
}, label: {
Image(systemName: "plus")
})
EditButton()
} }
#endif #endif
.formStyle(.grouped) .formStyle(.grouped)
@ -78,10 +85,6 @@ struct PeersView: View {
.navigationBarTitleDisplayMode(.large) .navigationBarTitleDisplayMode(.large)
#endif #endif
} }
func delete(at offsets: IndexSet) {
peers.remove(atOffsets: offsets)
}
} }
struct PeersView_Previews: PreviewProvider { struct PeersView_Previews: PreviewProvider {

View file

@ -20,7 +20,9 @@ struct StatusView: View {
@State private var statusBadgeText: String = "Not enabled" @State private var statusBadgeText: String = "Not enabled"
private func getStatusBadgeColor() -> SwiftUI.Color { private func getStatusBadgeColor() -> SwiftUI.Color {
if !appDelegate.yggdrasilEnabled { if !appDelegate.yggdrasilSupported {
return .gray
} else if !appDelegate.yggdrasilEnabled {
return .gray return .gray
} else if !appDelegate.yggdrasilConnected { } else if !appDelegate.yggdrasilConnected {
return .yellow return .yellow
@ -30,7 +32,9 @@ struct StatusView: View {
} }
private func getStatusBadgeText() -> String { private func getStatusBadgeText() -> String {
if !appDelegate.yggdrasilEnabled { if !appDelegate.yggdrasilSupported {
return "Not supported on this device"
} else if !appDelegate.yggdrasilEnabled {
return "Not enabled" return "Not enabled"
} else if !appDelegate.yggdrasilConnected { } else if !appDelegate.yggdrasilConnected {
return "No peers connected" return "No peers connected"
@ -44,12 +48,16 @@ struct StatusView: View {
Section(content: { Section(content: {
VStack(alignment: .leading) { VStack(alignment: .leading) {
Toggle("Enable Yggdrasil", isOn: $appDelegate.yggdrasilEnabled) Toggle("Enable Yggdrasil", isOn: $appDelegate.yggdrasilEnabled)
.disabled(!appDelegate.yggdrasilSupported)
HStack { HStack {
Image(systemName: "circlebadge.fill") Image(systemName: "circlebadge.fill")
.foregroundColor(statusBadgeColor) .foregroundColor(statusBadgeColor)
.onAppear(perform: { .onAppear(perform: {
statusBadgeColor = getStatusBadgeColor() statusBadgeColor = getStatusBadgeColor()
}) })
.onChange(of: appDelegate.yggdrasilSupported) { newValue in
statusBadgeColor = getStatusBadgeColor()
}
.onChange(of: appDelegate.yggdrasilEnabled) { newValue in .onChange(of: appDelegate.yggdrasilEnabled) { newValue in
statusBadgeColor = getStatusBadgeColor() statusBadgeColor = getStatusBadgeColor()
} }
@ -65,6 +73,9 @@ struct StatusView: View {
.onAppear(perform: { .onAppear(perform: {
statusBadgeText = getStatusBadgeText() statusBadgeText = getStatusBadgeText()
}) })
.onChange(of: appDelegate.yggdrasilSupported) { newValue in
statusBadgeText = getStatusBadgeText()
}
.onChange(of: appDelegate.yggdrasilEnabled) { newValue in .onChange(of: appDelegate.yggdrasilEnabled) { newValue in
statusBadgeText = getStatusBadgeText() statusBadgeText = getStatusBadgeText()
} }