From 2c3f8a4b2f3855d8342648f4106fd4cac220c905 Mon Sep 17 00:00:00 2001 From: Kenta Kubo <601636+kkebo@users.noreply.github.com> Date: Tue, 2 Sep 2025 02:24:37 +0900 Subject: [PATCH] refactor: divide each `Form` into its own separate file --- DNSecure/Views/DNSSearchDomainMatchView.swift | 46 +++++++ .../Views/DNSServerAddressMatchView.swift | 46 +++++++ DNSecure/Views/InterfaceTypeMatchView.swift | 35 +++++ DNSecure/Views/ProbeURLView.swift | 36 ++++++ DNSecure/Views/RuleView.swift | 120 +----------------- DNSecure/Views/SSIDMatchView.swift | 48 +++++++ 6 files changed, 216 insertions(+), 115 deletions(-) create mode 100644 DNSecure/Views/DNSSearchDomainMatchView.swift create mode 100644 DNSecure/Views/DNSServerAddressMatchView.swift create mode 100644 DNSecure/Views/InterfaceTypeMatchView.swift create mode 100644 DNSecure/Views/ProbeURLView.swift create mode 100644 DNSecure/Views/SSIDMatchView.swift diff --git a/DNSecure/Views/DNSSearchDomainMatchView.swift b/DNSecure/Views/DNSSearchDomainMatchView.swift new file mode 100644 index 0000000..12318da --- /dev/null +++ b/DNSecure/Views/DNSSearchDomainMatchView.swift @@ -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.. { + .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) + } +} diff --git a/DNSecure/Views/RuleView.swift b/DNSecure/Views/RuleView.swift index b73827a..e994a21 100644 --- a/DNSecure/Views/RuleView.swift +++ b/DNSecure/Views/RuleView.swift @@ -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..