ui: split servers into lists; allow to enable only tested servers (#4445)

This commit is contained in:
spaced4ndy
2024-07-12 21:03:30 +04:00
committed by GitHub
parent b348979b32
commit 70204e071d
88 changed files with 320 additions and 258 deletions
+8 -14
View File
@@ -1122,20 +1122,20 @@ public struct ProtoServersConfig: Codable {
public struct UserProtoServers: Decodable {
public var serverProtocol: ServerProtocol
public var protoServers: [ServerCfg]
public var presetServers: [String]
public var presetServers: [ServerCfg]
}
public struct ServerCfg: Identifiable, Equatable, Codable {
public struct ServerCfg: Identifiable, Equatable, Codable, Hashable {
public var server: String
public var preset: Bool
public var tested: Bool?
public var enabled: ServerEnabled
public var enabled: Bool
var createdAt = Date()
// public var sendEnabled: Bool // can we potentially want to prevent sending on the servers we use to receive?
// Even if we don't see the use case, it's probably better to allow it in the model
// In any case, "trusted/known" servers are out of scope of this change
public init(server: String, preset: Bool, tested: Bool?, enabled: ServerEnabled) {
public init(server: String, preset: Bool, tested: Bool?, enabled: Bool) {
self.server = server
self.preset = preset
self.tested = tested
@@ -1148,7 +1148,7 @@ public struct ServerCfg: Identifiable, Equatable, Codable {
public var id: String { "\(server) \(createdAt)" }
public static var empty = ServerCfg(server: "", preset: false, tested: nil, enabled: .enabled)
public static var empty = ServerCfg(server: "", preset: false, tested: nil, enabled: false)
public var isEmpty: Bool {
server.trimmingCharacters(in: .whitespaces) == ""
@@ -1165,19 +1165,19 @@ public struct ServerCfg: Identifiable, Equatable, Codable {
server: "smp://abcd@smp8.simplex.im",
preset: true,
tested: true,
enabled: .enabled
enabled: true
),
custom: ServerCfg(
server: "smp://abcd@smp9.simplex.im",
preset: false,
tested: false,
enabled: .disabled
enabled: false
),
untested: ServerCfg(
server: "smp://abcd@smp10.simplex.im",
preset: false,
tested: nil,
enabled: .enabled
enabled: true
)
)
@@ -1189,12 +1189,6 @@ public struct ServerCfg: Identifiable, Equatable, Codable {
}
}
public enum ServerEnabled: String, Codable {
case disabled
case enabled
case known
}
public enum ProtocolTestStep: String, Decodable, Equatable {
case connect
case disconnect