mirror of
https://github.com/kkebo/DNSecure.git
synced 2026-03-11 08:54:36 +00:00
refactor: divide each Form into its own separate file
This commit is contained in:
parent
6faca0f72b
commit
2c3f8a4b2f
6 changed files with 216 additions and 115 deletions
46
DNSecure/Views/DNSSearchDomainMatchView.swift
Normal file
46
DNSecure/Views/DNSSearchDomainMatchView.swift
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import NetworkExtension
|
||||
import SwiftUI
|
||||
|
||||
struct DNSSearchDomainMatchView {
|
||||
@Binding var rule: OnDemandRule
|
||||
}
|
||||
|
||||
extension DNSSearchDomainMatchView: View {
|
||||
var body: some View {
|
||||
Form {
|
||||
Section {
|
||||
ForEach(0..<self.rule.dnsSearchDomainMatch.count, id: \.self) { i in
|
||||
LazyTextField(
|
||||
"Search Domain",
|
||||
// self.$rule.dnsSearchDomainMatch[i] causes crash on deletion
|
||||
text: .init(
|
||||
get: { self.rule.dnsSearchDomainMatch[i] },
|
||||
set: { self.rule.dnsSearchDomainMatch[i] = $0 }
|
||||
)
|
||||
)
|
||||
}
|
||||
.onDelete { self.rule.dnsSearchDomainMatch.remove(atOffsets: $0) }
|
||||
.onMove { self.rule.dnsSearchDomainMatch.move(fromOffsets: $0, toOffset: $1) }
|
||||
Button("Add DNS Search Domain") {
|
||||
self.rule.dnsSearchDomainMatch.append("")
|
||||
}
|
||||
} footer: {
|
||||
Text(
|
||||
"If the current default search domain is equal to one of the strings in this array and all of the other conditions in the rule match, then the rule matches."
|
||||
)
|
||||
}
|
||||
}
|
||||
.navigationTitle("DNS Search Domain Match")
|
||||
.toolbar {
|
||||
EditButton()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 17, *)
|
||||
#Preview {
|
||||
@Previewable @State var rule = OnDemandRule(name: "Preview Rule")
|
||||
NavigationStack {
|
||||
DNSSearchDomainMatchView(rule: $rule)
|
||||
}
|
||||
}
|
||||
46
DNSecure/Views/DNSServerAddressMatchView.swift
Normal file
46
DNSecure/Views/DNSServerAddressMatchView.swift
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import NetworkExtension
|
||||
import SwiftUI
|
||||
|
||||
struct DNSServerAddressMatchView {
|
||||
@Binding var rule: OnDemandRule
|
||||
}
|
||||
|
||||
extension DNSServerAddressMatchView: View {
|
||||
var body: some View {
|
||||
Form {
|
||||
Section {
|
||||
ForEach(0..<self.rule.dnsServerAddressMatch.count, id: \.self) { i in
|
||||
LazyTextField(
|
||||
"IP Address",
|
||||
// self.$rule.dnsServerAddressMatch[i] causes crash on deletion
|
||||
text: .init(
|
||||
get: { self.rule.dnsServerAddressMatch[i] },
|
||||
set: { self.rule.dnsServerAddressMatch[i] = $0 }
|
||||
)
|
||||
)
|
||||
}
|
||||
.onDelete { self.rule.dnsServerAddressMatch.remove(atOffsets: $0) }
|
||||
.onMove { self.rule.dnsServerAddressMatch.move(fromOffsets: $0, toOffset: $1) }
|
||||
Button("Add DNS Server Address") {
|
||||
self.rule.dnsServerAddressMatch.append("")
|
||||
}
|
||||
} footer: {
|
||||
Text(
|
||||
"If each of the current default DNS servers is equal to one of the strings in this array and all of the other conditions in the rule match, then the rule matches."
|
||||
)
|
||||
}
|
||||
}
|
||||
.navigationTitle("DNS Server Address Match")
|
||||
.toolbar {
|
||||
EditButton()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 17, *)
|
||||
#Preview {
|
||||
@Previewable @State var rule = OnDemandRule(name: "Preview Rule")
|
||||
NavigationStack {
|
||||
DNSServerAddressMatchView(rule: $rule)
|
||||
}
|
||||
}
|
||||
35
DNSecure/Views/InterfaceTypeMatchView.swift
Normal file
35
DNSecure/Views/InterfaceTypeMatchView.swift
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import NetworkExtension
|
||||
import SwiftUI
|
||||
|
||||
struct InterfaceTypeMatchView {
|
||||
@Binding var rule: OnDemandRule
|
||||
}
|
||||
|
||||
extension InterfaceTypeMatchView: View {
|
||||
var body: some View {
|
||||
Form {
|
||||
Section {
|
||||
Picker("Interface Type", selection: self.$rule.interfaceType) {
|
||||
ForEach(NEOnDemandRuleInterfaceType.allCases, id: \.self) {
|
||||
Text($0.description)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.inline)
|
||||
.labelsHidden()
|
||||
} footer: {
|
||||
Text(
|
||||
"If the current primary network interface is of this type and all of the other conditions in the rule match, then the rule matches."
|
||||
)
|
||||
}
|
||||
}
|
||||
.navigationTitle("Interface Type Match")
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 17, *)
|
||||
#Preview {
|
||||
@Previewable @State var rule = OnDemandRule(name: "Preview Rule")
|
||||
NavigationStack {
|
||||
InterfaceTypeMatchView(rule: $rule)
|
||||
}
|
||||
}
|
||||
36
DNSecure/Views/ProbeURLView.swift
Normal file
36
DNSecure/Views/ProbeURLView.swift
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import NetworkExtension
|
||||
import SwiftUI
|
||||
|
||||
struct ProbeURLView {
|
||||
@Binding var rule: OnDemandRule
|
||||
|
||||
private var probeURL: Binding<String> {
|
||||
.init(
|
||||
get: { self.rule.probeURL?.absoluteString ?? "" },
|
||||
set: { self.rule.probeURL = URL(string: $0) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
extension ProbeURLView: View {
|
||||
var body: some View {
|
||||
Form {
|
||||
Section {
|
||||
LazyTextField("Probe URL", text: self.probeURL)
|
||||
} footer: {
|
||||
Text(
|
||||
"If a request sent to this URL results in a HTTP 200 OK response and all of the other conditions in the rule match, then the rule matches. If you don't want to use this rule, leave it empty."
|
||||
)
|
||||
}
|
||||
}
|
||||
.navigationTitle("Probe URL")
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 17, *)
|
||||
#Preview {
|
||||
@Previewable @State var rule = OnDemandRule(name: "Preview Rule")
|
||||
NavigationStack {
|
||||
ProbeURLView(rule: $rule)
|
||||
}
|
||||
}
|
||||
|
|
@ -21,22 +21,7 @@ extension RuleView: View {
|
|||
|
||||
Section("Matching Conditions") {
|
||||
NavigationLink {
|
||||
Form {
|
||||
Section {
|
||||
Picker("Interface Type", selection: self.$rule.interfaceType) {
|
||||
ForEach(NEOnDemandRuleInterfaceType.allCases, id: \.self) {
|
||||
Text($0.description)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.inline)
|
||||
.labelsHidden()
|
||||
} footer: {
|
||||
Text(
|
||||
"If the current primary network interface is of this type and all of the other conditions in the rule match, then the rule matches."
|
||||
)
|
||||
}
|
||||
}
|
||||
.navigationTitle("Interface Type Match")
|
||||
InterfaceTypeMatchView(rule: self.$rule)
|
||||
} label: {
|
||||
HStack {
|
||||
Text("Interface Type Match")
|
||||
|
|
@ -48,35 +33,7 @@ extension RuleView: View {
|
|||
|
||||
if self.rule.interfaceType.isSSIDUsed {
|
||||
NavigationLink {
|
||||
Form {
|
||||
Section {
|
||||
ForEach(0..<self.rule.ssidMatch.count, id: \.self) { i in
|
||||
LazyTextField(
|
||||
"SSID",
|
||||
// self.$rule.ssidMatch[i] causes crash on deletion
|
||||
text: .init(
|
||||
get: { self.rule.ssidMatch[i] },
|
||||
set: { self.rule.ssidMatch[i] = $0 }
|
||||
)
|
||||
)
|
||||
}
|
||||
.onDelete { self.rule.ssidMatch.remove(atOffsets: $0) }
|
||||
.onMove { self.rule.ssidMatch.move(fromOffsets: $0, toOffset: $1) }
|
||||
Button("Add SSID") {
|
||||
NEHotspotNetwork.fetchCurrent { network in
|
||||
self.rule.ssidMatch.append(network?.ssid ?? "")
|
||||
}
|
||||
}
|
||||
} footer: {
|
||||
Text(
|
||||
"If the Service Set Identifier (SSID) of the current primary connected network matches one of the strings in this array and all of the other conditions in the rule match, then the rule matches."
|
||||
)
|
||||
}
|
||||
}
|
||||
.navigationTitle("SSID Match")
|
||||
.toolbar {
|
||||
EditButton()
|
||||
}
|
||||
SSIDMatchView(rule: self.$rule)
|
||||
} label: {
|
||||
HStack {
|
||||
Text("SSID Match")
|
||||
|
|
@ -94,33 +51,7 @@ extension RuleView: View {
|
|||
}
|
||||
|
||||
NavigationLink {
|
||||
Form {
|
||||
Section {
|
||||
ForEach(0..<self.rule.dnsSearchDomainMatch.count, id: \.self) { i in
|
||||
LazyTextField(
|
||||
"Search Domain",
|
||||
// self.$rule.dnsSearchDomainMatch[i] causes crash on deletion
|
||||
text: .init(
|
||||
get: { self.rule.dnsSearchDomainMatch[i] },
|
||||
set: { self.rule.dnsSearchDomainMatch[i] = $0 }
|
||||
)
|
||||
)
|
||||
}
|
||||
.onDelete { self.rule.dnsSearchDomainMatch.remove(atOffsets: $0) }
|
||||
.onMove { self.rule.dnsSearchDomainMatch.move(fromOffsets: $0, toOffset: $1) }
|
||||
Button("Add DNS Search Domain") {
|
||||
self.rule.dnsSearchDomainMatch.append("")
|
||||
}
|
||||
} footer: {
|
||||
Text(
|
||||
"If the current default search domain is equal to one of the strings in this array and all of the other conditions in the rule match, then the rule matches."
|
||||
)
|
||||
}
|
||||
}
|
||||
.navigationTitle("DNS Search Domain Match")
|
||||
.toolbar {
|
||||
EditButton()
|
||||
}
|
||||
DNSSearchDomainMatchView(rule: self.$rule)
|
||||
} label: {
|
||||
HStack {
|
||||
Text("DNS Search Domain Match")
|
||||
|
|
@ -137,33 +68,7 @@ extension RuleView: View {
|
|||
}
|
||||
|
||||
NavigationLink {
|
||||
Form {
|
||||
Section {
|
||||
ForEach(0..<self.rule.dnsServerAddressMatch.count, id: \.self) { i in
|
||||
LazyTextField(
|
||||
"IP Address",
|
||||
// self.$rule.dnsServerAddressMatch[i] causes crash on deletion
|
||||
text: .init(
|
||||
get: { self.rule.dnsServerAddressMatch[i] },
|
||||
set: { self.rule.dnsServerAddressMatch[i] = $0 }
|
||||
)
|
||||
)
|
||||
}
|
||||
.onDelete { self.rule.dnsServerAddressMatch.remove(atOffsets: $0) }
|
||||
.onMove { self.rule.dnsServerAddressMatch.move(fromOffsets: $0, toOffset: $1) }
|
||||
Button("Add DNS Server Address") {
|
||||
self.rule.dnsServerAddressMatch.append("")
|
||||
}
|
||||
} footer: {
|
||||
Text(
|
||||
"If each of the current default DNS servers is equal to one of the strings in this array and all of the other conditions in the rule match, then the rule matches."
|
||||
)
|
||||
}
|
||||
}
|
||||
.navigationTitle("DNS Server Address Match")
|
||||
.toolbar {
|
||||
EditButton()
|
||||
}
|
||||
DNSServerAddressMatchView(rule: self.$rule)
|
||||
} label: {
|
||||
HStack {
|
||||
Text("DNS Server Address Match")
|
||||
|
|
@ -180,22 +85,7 @@ extension RuleView: View {
|
|||
}
|
||||
|
||||
NavigationLink {
|
||||
Form {
|
||||
Section {
|
||||
LazyTextField(
|
||||
"Probe URL",
|
||||
text: .init(
|
||||
get: { self.rule.probeURL?.absoluteString ?? "" },
|
||||
set: { self.rule.probeURL = URL(string: $0) }
|
||||
)
|
||||
)
|
||||
} footer: {
|
||||
Text(
|
||||
"If a request sent to this URL results in a HTTP 200 OK response and all of the other conditions in the rule match, then the rule matches. If you don't want to use this rule, leave it empty."
|
||||
)
|
||||
}
|
||||
}
|
||||
.navigationTitle("Probe URL")
|
||||
ProbeURLView(rule: self.$rule)
|
||||
} label: {
|
||||
HStack {
|
||||
Text("Probe URL")
|
||||
|
|
|
|||
48
DNSecure/Views/SSIDMatchView.swift
Normal file
48
DNSecure/Views/SSIDMatchView.swift
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import NetworkExtension
|
||||
import SwiftUI
|
||||
|
||||
struct SSIDMatchView {
|
||||
@Binding var rule: OnDemandRule
|
||||
}
|
||||
|
||||
extension SSIDMatchView: View {
|
||||
var body: some View {
|
||||
Form {
|
||||
Section {
|
||||
ForEach(0..<self.rule.ssidMatch.count, id: \.self) { i in
|
||||
LazyTextField(
|
||||
"SSID",
|
||||
// self.$rule.ssidMatch[i] causes crash on deletion
|
||||
text: .init(
|
||||
get: { self.rule.ssidMatch[i] },
|
||||
set: { self.rule.ssidMatch[i] = $0 }
|
||||
)
|
||||
)
|
||||
}
|
||||
.onDelete { self.rule.ssidMatch.remove(atOffsets: $0) }
|
||||
.onMove { self.rule.ssidMatch.move(fromOffsets: $0, toOffset: $1) }
|
||||
Button("Add SSID") {
|
||||
NEHotspotNetwork.fetchCurrent { network in
|
||||
self.rule.ssidMatch.append(network?.ssid ?? "")
|
||||
}
|
||||
}
|
||||
} footer: {
|
||||
Text(
|
||||
"If the Service Set Identifier (SSID) of the current primary connected network matches one of the strings in this array and all of the other conditions in the rule match, then the rule matches."
|
||||
)
|
||||
}
|
||||
}
|
||||
.navigationTitle("SSID Match")
|
||||
.toolbar {
|
||||
EditButton()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 17, *)
|
||||
#Preview {
|
||||
@Previewable @State var rule = OnDemandRule(name: "Preview Rule")
|
||||
NavigationStack {
|
||||
SSIDMatchView(rule: $rule)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue