|
@@ -16,8 +16,62 @@
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
-@available(macOS 11, *)
|
|
|
+@available(macOS 12, *)
|
|
|
struct VMConfigNetworkPortForwardView: View {
|
|
|
+ @Binding var config: UTMQemuConfigurationNetwork
|
|
|
+ @State private var isEditingNewPort = false
|
|
|
+ @State private var isEditingExistingPort = false
|
|
|
+ @State private var selectedId: UUID?
|
|
|
+ @State private var editPortForward: UTMQemuConfigurationPortForward?
|
|
|
+
|
|
|
+ var body: some View {
|
|
|
+ VStack {
|
|
|
+ Table(config.portForward, selection: $selectedId) {
|
|
|
+ TableColumn("Protocol") { row in
|
|
|
+ Text(row.protocol.prettyValue)
|
|
|
+ }
|
|
|
+ TableColumn("Guest Address") { row in
|
|
|
+ Text(row.guestAddress ?? "")
|
|
|
+ }
|
|
|
+ TableColumn("Guest Port") { row in
|
|
|
+ Text(String(row.guestPort))
|
|
|
+ }
|
|
|
+ TableColumn("Host Address") { row in
|
|
|
+ Text(row.hostAddress ?? "")
|
|
|
+ }
|
|
|
+ TableColumn("Host Port") { row in
|
|
|
+ Text(String(row.hostPort))
|
|
|
+ }
|
|
|
+ }.onDoubleClick {
|
|
|
+ editPortForward = config.portForward.first(where: { $0.id == selectedId })
|
|
|
+ }
|
|
|
+ HStack {
|
|
|
+ Spacer()
|
|
|
+ if let selectedId = selectedId {
|
|
|
+ Button("Delete") {
|
|
|
+ config.portForward.removeAll(where: { $0.id == selectedId })
|
|
|
+ self.selectedId = nil
|
|
|
+ }
|
|
|
+ Button("Edit…") {
|
|
|
+ editPortForward = config.portForward.first(where: { $0.id == selectedId })
|
|
|
+ }.popover(item: $editPortForward, arrowEdge: .top) { item in
|
|
|
+ PortForwardEdit(config: $config, forward: item).padding()
|
|
|
+ .frame(width: 250)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Button("New…") {
|
|
|
+ isEditingNewPort.toggle()
|
|
|
+ }.popover(isPresented: $isEditingNewPort, arrowEdge: .top) {
|
|
|
+ PortForwardEdit(config: $config, forward: .init()).padding()
|
|
|
+ .frame(width: 250)
|
|
|
+ }
|
|
|
+ }.padding()
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+@available(macOS 11, *)
|
|
|
+struct VMConfigNetworkPortForwardLegacyView: View {
|
|
|
@Binding var config: UTMQemuConfigurationNetwork
|
|
|
@State private var editingNewPort = false
|
|
|
@State private var selectedPortForward: UTMQemuConfigurationPortForward?
|
|
@@ -27,7 +81,7 @@ struct VMConfigNetworkPortForwardView: View {
|
|
|
Text("Port Forward")
|
|
|
Spacer()
|
|
|
Button(action: { editingNewPort = true }, label: {
|
|
|
- Text("New")
|
|
|
+ Text("New…")
|
|
|
}).popover(isPresented: $editingNewPort, arrowEdge: .bottom) {
|
|
|
PortForwardEdit(config: $config, forward: .init()).padding()
|
|
|
.frame(width: 250)
|
|
@@ -106,7 +160,11 @@ struct VMConfigNetworkPortForwardView_Previews: PreviewProvider {
|
|
|
static var previews: some View {
|
|
|
Group {
|
|
|
Form {
|
|
|
- VMConfigNetworkPortForwardView(config: $config)
|
|
|
+ if #available(macOS 12, *) {
|
|
|
+ VMConfigNetworkPortForwardView(config: $config)
|
|
|
+ } else {
|
|
|
+ VMConfigNetworkPortForwardLegacyView(config: $config)
|
|
|
+ }
|
|
|
}.onAppear {
|
|
|
if config.portForward.count == 0 {
|
|
|
var newConfigPort = UTMQemuConfigurationPortForward()
|