mirror of
https://github.com/kkebo/DNSecure.git
synced 2026-03-11 08:54:36 +00:00
style: swift-format
This commit is contained in:
parent
3e97eec20b
commit
5faedd45d9
10 changed files with 50 additions and 37 deletions
|
|
@ -5,8 +5,8 @@
|
||||||
// Created by Kenta Kubo on 7/1/20.
|
// Created by Kenta Kubo on 7/1/20.
|
||||||
//
|
//
|
||||||
|
|
||||||
import os.log
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import os.log
|
||||||
|
|
||||||
let logger = Logger()
|
let logger = Logger()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,14 +13,14 @@ extension NEOnDemandRuleInterfaceType: @retroactive CustomStringConvertible {
|
||||||
case .any:
|
case .any:
|
||||||
return "Any"
|
return "Any"
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
case .ethernet:
|
case .ethernet:
|
||||||
return "Ethernet"
|
return "Ethernet"
|
||||||
#endif
|
#endif
|
||||||
case .wiFi:
|
case .wiFi:
|
||||||
return "Wi-Fi"
|
return "Wi-Fi"
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
case .cellular:
|
case .cellular:
|
||||||
return "Cellular"
|
return "Cellular"
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
return "Unknown"
|
return "Unknown"
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ enum Presets {
|
||||||
configuration: .dnsOverTLS(
|
configuration: .dnsOverTLS(
|
||||||
DoTConfiguration(
|
DoTConfiguration(
|
||||||
servers: [
|
servers: [
|
||||||
"116.202.176.26",
|
"116.202.176.26"
|
||||||
],
|
],
|
||||||
serverName: "dot.libredns.gr"
|
serverName: "dot.libredns.gr"
|
||||||
)
|
)
|
||||||
|
|
@ -137,7 +137,7 @@ enum Presets {
|
||||||
configuration: .dnsOverHTTPS(
|
configuration: .dnsOverHTTPS(
|
||||||
DoHConfiguration(
|
DoHConfiguration(
|
||||||
servers: [
|
servers: [
|
||||||
"116.202.176.26",
|
"116.202.176.26"
|
||||||
],
|
],
|
||||||
serverURL: URL(string: "https://doh.libredns.gr/dns-query")
|
serverURL: URL(string: "https://doh.libredns.gr/dns-query")
|
||||||
)
|
)
|
||||||
|
|
@ -148,7 +148,7 @@ enum Presets {
|
||||||
configuration: .dnsOverHTTPS(
|
configuration: .dnsOverHTTPS(
|
||||||
DoHConfiguration(
|
DoHConfiguration(
|
||||||
servers: [
|
servers: [
|
||||||
"116.202.176.26",
|
"116.202.176.26"
|
||||||
],
|
],
|
||||||
serverURL: URL(string: "https://doh.libredns.gr/ads")
|
serverURL: URL(string: "https://doh.libredns.gr/ads")
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -48,9 +48,9 @@ enum Configuration {
|
||||||
|
|
||||||
func toDNSSettings() -> NEDNSSettings {
|
func toDNSSettings() -> NEDNSSettings {
|
||||||
switch self {
|
switch self {
|
||||||
case let .dnsOverTLS(configuration):
|
case .dnsOverTLS(let configuration):
|
||||||
return configuration.toDNSSettings()
|
return configuration.toDNSSettings()
|
||||||
case let .dnsOverHTTPS(configuration):
|
case .dnsOverHTTPS(let configuration):
|
||||||
return configuration.toDNSSettings()
|
return configuration.toDNSSettings()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -87,10 +87,10 @@ extension Configuration: Codable {
|
||||||
var container = encoder.container(keyedBy: Self.CodingKeys.self)
|
var container = encoder.container(keyedBy: Self.CodingKeys.self)
|
||||||
|
|
||||||
switch self {
|
switch self {
|
||||||
case let .dnsOverTLS(configuration):
|
case .dnsOverTLS(let configuration):
|
||||||
try container.encode(Self.Base.dnsOverTLS, forKey: .base)
|
try container.encode(Self.Base.dnsOverTLS, forKey: .base)
|
||||||
try container.encode(configuration, forKey: .dotConfiguration)
|
try container.encode(configuration, forKey: .dotConfiguration)
|
||||||
case let .dnsOverHTTPS(configuration):
|
case .dnsOverHTTPS(let configuration):
|
||||||
try container.encode(Self.Base.dnsOverHTTPS, forKey: .base)
|
try container.encode(Self.Base.dnsOverHTTPS, forKey: .base)
|
||||||
try container.encode(configuration, forKey: .dohConfiguration)
|
try container.encode(configuration, forKey: .dohConfiguration)
|
||||||
}
|
}
|
||||||
|
|
@ -200,10 +200,11 @@ extension Resolver: Codable {
|
||||||
self.id = try container.decode(UUID.self, forKey: .id)
|
self.id = try container.decode(UUID.self, forKey: .id)
|
||||||
self.name = try container.decode(String.self, forKey: .name)
|
self.name = try container.decode(String.self, forKey: .name)
|
||||||
self.configuration = try container.decode(Configuration.self, forKey: .configuration)
|
self.configuration = try container.decode(Configuration.self, forKey: .configuration)
|
||||||
self.onDemandRules = try container.decodeIfPresent(
|
self.onDemandRules =
|
||||||
[OnDemandRule].self,
|
try container.decodeIfPresent(
|
||||||
forKey: .onDemandRules
|
[OnDemandRule].self,
|
||||||
) ?? []
|
forKey: .onDemandRules
|
||||||
|
) ?? []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -218,7 +219,7 @@ extension Resolvers {
|
||||||
extension Resolvers: @retroactive RawRepresentable {
|
extension Resolvers: @retroactive RawRepresentable {
|
||||||
public init?(rawValue: String) {
|
public init?(rawValue: String) {
|
||||||
guard let data = rawValue.data(using: .utf8),
|
guard let data = rawValue.data(using: .utf8),
|
||||||
let result = try? JSONDecoder().decode(Self.self, from: data)
|
let result = try? JSONDecoder().decode(Self.self, from: data)
|
||||||
else {
|
else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -227,7 +228,7 @@ extension Resolvers: @retroactive RawRepresentable {
|
||||||
|
|
||||||
public var rawValue: String {
|
public var rawValue: String {
|
||||||
guard let data = try? JSONEncoder().encode(self),
|
guard let data = try? JSONEncoder().encode(self),
|
||||||
let result = String(data: data, encoding: .utf8)
|
let result = String(data: data, encoding: .utf8)
|
||||||
else {
|
else {
|
||||||
return "[]"
|
return "[]"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -90,8 +90,10 @@ struct ContentView {
|
||||||
manager.onDemandRules = server.onDemandRules.toNEOnDemandRules()
|
manager.onDemandRules = server.onDemandRules.toNEOnDemandRules()
|
||||||
manager.saveToPreferences { saveError in
|
manager.saveToPreferences { saveError in
|
||||||
if let saveError = saveError as NSError? {
|
if let saveError = saveError as NSError? {
|
||||||
guard saveError.domain != "NEConfigurationErrorDomain"
|
guard
|
||||||
|| saveError.code != 9 else {
|
saveError.domain != "NEConfigurationErrorDomain"
|
||||||
|
|| saveError.code != 9
|
||||||
|
else {
|
||||||
// Nothing was changed
|
// Nothing was changed
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -187,8 +189,9 @@ extension ContentView: View {
|
||||||
// FIXME: This is a workaround for self.$severs[i].
|
// FIXME: This is a workaround for self.$severs[i].
|
||||||
// That cannot save settings as soon as it is modified.
|
// That cannot save settings as soon as it is modified.
|
||||||
guard let id = self.usedID,
|
guard let id = self.usedID,
|
||||||
let uuid = UUID(uuidString: id),
|
let uuid = UUID(uuidString: id),
|
||||||
let server = self.servers.find(by: uuid) else {
|
let server = self.servers.find(by: uuid)
|
||||||
|
else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.saveSettings(of: server)
|
self.saveSettings(of: server)
|
||||||
|
|
@ -263,8 +266,9 @@ extension ContentView: View {
|
||||||
// FIXME: This is a workaround for self.$severs[i].
|
// FIXME: This is a workaround for self.$severs[i].
|
||||||
// That cannot save settings as soon as it is modified.
|
// That cannot save settings as soon as it is modified.
|
||||||
guard let id = self.usedID,
|
guard let id = self.usedID,
|
||||||
let uuid = UUID(uuidString: id),
|
let uuid = UUID(uuidString: id),
|
||||||
let server = self.servers.find(by: uuid) else {
|
let server = self.servers.find(by: uuid)
|
||||||
|
else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.saveSettings(of: server)
|
self.saveSettings(of: server)
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ struct RestorationView {
|
||||||
@Environment(\.dismiss) private var dismiss
|
@Environment(\.dismiss) private var dismiss
|
||||||
@State private var selection = Set<Resolver>()
|
@State private var selection = Set<Resolver>()
|
||||||
@State private var keyword = ""
|
@State private var keyword = ""
|
||||||
let onAdd: (Set<Resolver>) -> ()
|
let onAdd: (Set<Resolver>) -> Void
|
||||||
|
|
||||||
private var servers: Resolvers {
|
private var servers: Resolvers {
|
||||||
guard !self.keyword.isEmpty else { return Presets.servers }
|
guard !self.keyword.isEmpty else { return Presets.servers }
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,9 @@ extension RuleView: View {
|
||||||
} header: {
|
} header: {
|
||||||
Text("Interface Type Match")
|
Text("Interface Type Match")
|
||||||
} footer: {
|
} 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.")
|
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."
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.rule.interfaceType.ssidIsUsed {
|
if self.rule.interfaceType.ssidIsUsed {
|
||||||
|
|
@ -65,7 +67,9 @@ extension RuleView: View {
|
||||||
Text("SSID Match")
|
Text("SSID Match")
|
||||||
}
|
}
|
||||||
} footer: {
|
} 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.")
|
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."
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,7 +96,9 @@ extension RuleView: View {
|
||||||
Text("DNS Search Domain Match")
|
Text("DNS Search Domain Match")
|
||||||
}
|
}
|
||||||
} footer: {
|
} 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.")
|
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."
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Section {
|
Section {
|
||||||
|
|
@ -118,7 +124,9 @@ extension RuleView: View {
|
||||||
Text("DNS Server Address Match")
|
Text("DNS Server Address Match")
|
||||||
}
|
}
|
||||||
} footer: {
|
} 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.")
|
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."
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Section {
|
Section {
|
||||||
|
|
@ -132,7 +140,9 @@ extension RuleView: View {
|
||||||
} header: {
|
} header: {
|
||||||
Text("Probe URL Match")
|
Text("Probe URL Match")
|
||||||
} footer: {
|
} 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.")
|
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(self.rule.name)
|
.navigationTitle(self.rule.name)
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,10 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
@testable import DNSecure
|
@testable import DNSecure
|
||||||
|
|
||||||
class DNSecureTests: XCTestCase {
|
class DNSecureTests: XCTestCase {
|
||||||
|
|
||||||
override func setUpWithError() throws {
|
override func setUpWithError() throws {
|
||||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||||
}
|
}
|
||||||
|
|
@ -29,5 +29,4 @@ class DNSecureTests: XCTestCase {
|
||||||
// Put the code you want to measure the time of here.
|
// Put the code you want to measure the time of here.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@
|
||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
class DNSecureUITests: XCTestCase {
|
class DNSecureUITests: XCTestCase {
|
||||||
|
|
||||||
override func setUpWithError() throws {
|
override func setUpWithError() throws {
|
||||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@
|
||||||
// This file is automatically generated.
|
// This file is automatically generated.
|
||||||
// Do not edit it by hand because the contents will be replaced.
|
// Do not edit it by hand because the contents will be replaced.
|
||||||
|
|
||||||
import PackageDescription
|
|
||||||
import AppleProductTypes
|
import AppleProductTypes
|
||||||
|
import PackageDescription
|
||||||
|
|
||||||
let package = Package(
|
let package = Package(
|
||||||
name: "DNSecure",
|
name: "DNSecure",
|
||||||
|
|
@ -24,13 +24,13 @@ let package = Package(
|
||||||
accentColor: .asset("AccentColor"),
|
accentColor: .asset("AccentColor"),
|
||||||
supportedDeviceFamilies: [
|
supportedDeviceFamilies: [
|
||||||
.pad,
|
.pad,
|
||||||
.phone
|
.phone,
|
||||||
],
|
],
|
||||||
supportedInterfaceOrientations: [
|
supportedInterfaceOrientations: [
|
||||||
.portrait,
|
.portrait,
|
||||||
.landscapeRight,
|
.landscapeRight,
|
||||||
.landscapeLeft,
|
.landscapeLeft,
|
||||||
.portraitUpsideDown(.when(deviceFamilies: [.pad]))
|
.portraitUpsideDown(.when(deviceFamilies: [.pad])),
|
||||||
],
|
],
|
||||||
appCategory: .utilities
|
appCategory: .utilities
|
||||||
)
|
)
|
||||||
|
|
@ -46,6 +46,6 @@ let package = Package(
|
||||||
"DNSecure"
|
"DNSecure"
|
||||||
],
|
],
|
||||||
path: "DNSecureTests"
|
path: "DNSecureTests"
|
||||||
)
|
),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue