Commit 1283aad4 authored by Jose Blaya's avatar Jose Blaya
Browse files

Regions view and Tiles

parent ad974441
......@@ -205,7 +205,7 @@ public class Server: Hashable {
/// :nodoc:
public static func ==(lhs: Server, rhs: Server) -> Bool {
return (lhs.identifier == rhs.identifier)
return (lhs.identifier == rhs.identifier && lhs.dipToken == rhs.dipToken)
}
/// :nodoc:
......
......@@ -44,6 +44,8 @@ class UserDefaultsStore: PlainStore, ConfigurationAccess {
static let preferredServer = "CurrentRegion" // legacy
static let preferredServerDIPToken = "CurrentRegionDIPToken"
static let pingByServerIdentifier = "PingByServerIdentifier"
static let vpnType = "VPNType"
......@@ -285,10 +287,12 @@ class UserDefaultsStore: PlainStore, ConfigurationAccess {
var preferredServer: Server? {
get {
let identifier = backend.string(forKey: Entries.preferredServer)
return cachedServers.first { $0.identifier == identifier }
let dipToken = preferredServerDIPToken
return cachedServers.first { $0.identifier == identifier && $0.dipToken == dipToken }
}
set {
backend.set(newValue?.identifier, forKey: Entries.preferredServer)
backend.set(newValue?.dipToken, forKey: Entries.preferredServerDIPToken)
var lastServers = historicalServers
if let server = newValue {
......@@ -305,6 +309,15 @@ class UserDefaultsStore: PlainStore, ConfigurationAccess {
}
}
var preferredServerDIPToken: String? {
get {
return backend.string(forKey: Entries.preferredServerDIPToken)
}
set {
backend.set(preferredServerDIPToken, forKey: Entries.preferredServerDIPToken)
}
}
var serverNetwork: ServersNetwork {
get {
let network = backend.string(forKey: Entries.serverNetwork)
......
......@@ -43,6 +43,9 @@ class DefaultServerProvider: ServerProvider, ConfigurationAccess, DatabaseAccess
var historicalServers: [Server] {
get {
if let dipTokens = dipTokens {
return accessedDatabase.plain.historicalServers.filter({$0.dipToken == nil || dipTokens.contains($0.dipToken ?? "")})
}
return accessedDatabase.plain.historicalServers
}
set {
......@@ -160,11 +163,18 @@ class DefaultServerProvider: ServerProvider, ConfigurationAccess, DatabaseAccess
self.currentServers = bundle.servers
if let tokens = self.accessedDatabase.secure.dipTokens() {
if let tokens = self.accessedDatabase.secure.dipTokens(), !tokens.isEmpty {
self.webServices.activateDIPToken(tokens: tokens) { (servers, error) in
if let servers = servers {
self.currentServers.append(contentsOf: servers)
for server in servers {
if !self.currentServers.contains(where: {$0.dipToken == server.dipToken}) {
self.currentServers.append(server)
}
}
}
NotificationCenter.default.post(name: .PIAThemeDidChange,
object: self,
userInfo: nil)
callback?(self.currentServers, error)
}
} else {
......
......@@ -47,8 +47,9 @@ public class EndpointManager {
private func availableMetaEndpoints(_ availableEndpoints: inout [PinningEndpoint]) {
var currentServers = Client.providers.serverProvider.currentServers.filter { $0.serverNetwork == .gen4 }
currentServers = currentServers.sorted(by: { $0.pingTime ?? 1000 < $1.pingTime ?? 1000 })
if let historicalServer = Client.providers.serverProvider.historicalServers.first {
currentServers = currentServers.filter({$0.meta != nil})
if let historicalServer = Client.providers.serverProvider.historicalServers.first(where: {$0.meta != nil}) {
availableEndpoints.append(PinningEndpoint(host: historicalServer.meta!.ip,
useCertificatePinning: true,
commonName: historicalServer.meta?.cn))
......
......@@ -39,6 +39,8 @@ class GlossServer: GlossParser {
return nil
}
let dipToken: String? = "dipToken" <~~ json ?? nil
let geo: Bool = "geo" <~~ json ?? false
var internalServerNetwork: ServersNetwork?
......@@ -132,6 +134,7 @@ class GlossServer: GlossParser {
serverNetwork: internalServerNetwork ?? .gen4,
geo: geo,
meta: meta,
dipToken: dipToken,
regionIdentifier: regionIdentifier
)
......@@ -223,7 +226,9 @@ extension Server: JSONEncodable {
"wg" ~~> wgUDPobj,
"ikev2" ~~> ikeV2UDPobj,
]),
"internal_server_network" ~~> serverNetwork?.rawValue
"internal_server_network" ~~> serverNetwork?.rawValue,
"dipToken" ~~> dipToken,
"id" ~~> regionIdentifier
])
......
......@@ -245,6 +245,24 @@ public extension TextStyle {
lineHeight: 18
)
static let ipTextStyle = TextStyle(
font: UIFont.regularFontWith(size: 12),
color: UIColor.piaGrey4,
foregroundColor: nil,
backgroundColor: nil,
tintColor: nil,
lineHeight: 16
)
static let ipTitleTextStyle = TextStyle(
font: UIFont.regularFontWith(size: 10),
color: UIColor.piaGrey4,
foregroundColor: nil,
backgroundColor: nil,
tintColor: nil,
lineHeight: 10
)
static let textStyle22 = TextStyle(
font: UIFont.mediumFontWith(size: 26),
color: UIColor.piaWhite,
......
......@@ -687,6 +687,15 @@ public class Theme {
}
}
/// :nodoc:
public func applyRegionIPCell(_ label: UILabel, appearance: Appearance) {
label.style(style: TextStyle.ipTextStyle)
}
public func applyRegionIPTitleCell(_ label: UILabel, appearance: Appearance) {
label.style(style: TextStyle.ipTitleTextStyle)
}
//MARK: Tile Usage
/// :nodoc:
public func applySubtitleTileUsage(_ label: UILabel, appearance: Appearance) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment