mirror of
https://github.com/kkebo/DNSecure.git
synced 2026-03-11 08:54:36 +00:00
Refactor
This commit is contained in:
parent
18edb76ead
commit
96b85071a9
4 changed files with 51 additions and 48 deletions
|
|
@ -214,11 +214,9 @@ extension ContentView: View {
|
|||
}
|
||||
}
|
||||
}
|
||||
.alert(isPresented: self.$alertIsPresented) {
|
||||
Alert(
|
||||
title: Text(self.alertTitle),
|
||||
message: Text(self.alertMessage)
|
||||
)
|
||||
.alert(self.alertTitle, isPresented: self.$alertIsPresented) {
|
||||
} message: {
|
||||
Text(self.alertMessage)
|
||||
}
|
||||
|
||||
if !self.isEnabled {
|
||||
|
|
|
|||
|
|
@ -7,9 +7,17 @@
|
|||
|
||||
import SwiftUI
|
||||
|
||||
private enum FocusedField {
|
||||
case dotAddress
|
||||
case dotServerName
|
||||
case dohAddress
|
||||
case dohServerURL
|
||||
}
|
||||
|
||||
struct DetailView {
|
||||
@Binding var server: Resolver
|
||||
@Binding var isOn: Bool
|
||||
@FocusState private var focusedField: FocusedField?
|
||||
|
||||
private func binding(for rule: OnDemandRule) -> Binding<OnDemandRule> {
|
||||
guard let index = self.server.onDemandRules.firstIndex(of: rule) else {
|
||||
|
|
@ -48,9 +56,10 @@ extension DetailView: View {
|
|||
}
|
||||
} header: {
|
||||
EditButton()
|
||||
.foregroundColor(.accentColor)
|
||||
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||
.overlay(Text("On Demand Rules"), alignment: .leading)
|
||||
.overlay(alignment: .leading) {
|
||||
Text("On Demand Rules")
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationTitle(self.server.name)
|
||||
|
|
@ -60,8 +69,18 @@ extension DetailView: View {
|
|||
switch self.server.configuration {
|
||||
case .dnsOverTLS(let configuration):
|
||||
self.dnsOverTLSSections(configuration)
|
||||
.onChange(of: self.focusedField) { newValue in
|
||||
if newValue == nil {
|
||||
self.server.configuration = .dnsOverTLS(configuration)
|
||||
}
|
||||
}
|
||||
case .dnsOverHTTPS(let configuration):
|
||||
self.dnsOverHTTPSSections(configuration)
|
||||
.onChange(of: self.focusedField) { newValue in
|
||||
if newValue == nil {
|
||||
self.server.configuration = .dnsOverHTTPS(configuration)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -80,13 +99,9 @@ extension DetailView: View {
|
|||
configuration.servers[i] = $0
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
}
|
||||
),
|
||||
onEditingChanged: { isEditing in
|
||||
if !isEditing {
|
||||
self.server.configuration = .dnsOverTLS(configuration)
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
.focused(self.$focusedField, equals: .dotAddress)
|
||||
.textContentType(.URL)
|
||||
.keyboardType(.numbersAndPunctuation)
|
||||
.autocapitalization(.none)
|
||||
|
|
@ -106,9 +121,10 @@ extension DetailView: View {
|
|||
}
|
||||
} header: {
|
||||
EditButton()
|
||||
.foregroundColor(.accentColor)
|
||||
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||
.overlay(Text("Servers"), alignment: .leading)
|
||||
.overlay(alignment: .leading) {
|
||||
Text("Servers")
|
||||
}
|
||||
} footer: {
|
||||
Text("The DNS server IP addresses.")
|
||||
}
|
||||
|
|
@ -126,13 +142,9 @@ extension DetailView: View {
|
|||
configuration.serverName = $0
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
}
|
||||
),
|
||||
onEditingChanged: { isEditing in
|
||||
if !isEditing {
|
||||
self.server.configuration = .dnsOverTLS(configuration)
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
.focused(self.$focusedField, equals: .dotServerName)
|
||||
.multilineTextAlignment(.trailing)
|
||||
.textContentType(.URL)
|
||||
.keyboardType(.URL)
|
||||
|
|
@ -161,13 +173,9 @@ extension DetailView: View {
|
|||
configuration.servers[i] = $0
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
}
|
||||
),
|
||||
onEditingChanged: { isEditing in
|
||||
if !isEditing {
|
||||
self.server.configuration = .dnsOverHTTPS(configuration)
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
.focused(self.$focusedField, equals: .dohAddress)
|
||||
.textContentType(.URL)
|
||||
.keyboardType(.numbersAndPunctuation)
|
||||
.autocapitalization(.none)
|
||||
|
|
@ -187,9 +195,10 @@ extension DetailView: View {
|
|||
}
|
||||
} header: {
|
||||
EditButton()
|
||||
.foregroundColor(.accentColor)
|
||||
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||
.overlay(Text("Servers"), alignment: .leading)
|
||||
.overlay(alignment: .leading) {
|
||||
Text("Servers")
|
||||
}
|
||||
} footer: {
|
||||
Text("The DNS server IP addresses.")
|
||||
}
|
||||
|
|
@ -208,13 +217,9 @@ extension DetailView: View {
|
|||
string: $0.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
)
|
||||
}
|
||||
),
|
||||
onEditingChanged: { isEditing in
|
||||
if !isEditing {
|
||||
self.server.configuration = .dnsOverHTTPS(configuration)
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
.focused(self.$focusedField, equals: .dohServerURL)
|
||||
.multilineTextAlignment(.trailing)
|
||||
.textContentType(.URL)
|
||||
.keyboardType(.URL)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
import SwiftUI
|
||||
|
||||
struct HowToActivateView {
|
||||
@Environment(\.presentationMode) private var presentationMode
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
let isSheet: Bool
|
||||
}
|
||||
|
||||
|
|
@ -112,14 +112,11 @@ extension HowToActivateView: View {
|
|||
if self.isSheet {
|
||||
Spacer()
|
||||
Button {
|
||||
self.presentationMode.wrappedValue.dismiss()
|
||||
self.dismiss()
|
||||
} label: {
|
||||
Text("Dismiss")
|
||||
.padding()
|
||||
.foregroundColor(.white)
|
||||
.background(Color.accentColor)
|
||||
.cornerRadius(10)
|
||||
Text("Dismiss").padding()
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
|
|
|
|||
|
|
@ -61,9 +61,10 @@ extension RuleView: View {
|
|||
}
|
||||
} header: {
|
||||
EditButton()
|
||||
.foregroundColor(.accentColor)
|
||||
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||
.overlay(Text("SSID Match"), alignment: .leading)
|
||||
.overlay(alignment: .leading) {
|
||||
Text("SSID Match")
|
||||
}
|
||||
} 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.")
|
||||
}
|
||||
|
|
@ -87,9 +88,10 @@ extension RuleView: View {
|
|||
}
|
||||
} header: {
|
||||
EditButton()
|
||||
.foregroundColor(.accentColor)
|
||||
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||
.overlay(Text("DNS Search Domain Match"), alignment: .leading)
|
||||
.overlay(alignment: .leading) {
|
||||
Text("DNS Search Domain Match")
|
||||
}
|
||||
} 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.")
|
||||
}
|
||||
|
|
@ -112,9 +114,10 @@ extension RuleView: View {
|
|||
}
|
||||
} header: {
|
||||
EditButton()
|
||||
.foregroundColor(.accentColor)
|
||||
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||
.overlay(Text("DNS Server Address Match"), alignment: .leading)
|
||||
.overlay(alignment: .leading) {
|
||||
Text("DNS Server Address Match")
|
||||
}
|
||||
} 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.")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue