diff --git a/IVPNClient/Managers/StorageManager.swift b/IVPNClient/Managers/StorageManager.swift index 3bcfe5e33..b13250070 100644 --- a/IVPNClient/Managers/StorageManager.swift +++ b/IVPNClient/Managers/StorageManager.swift @@ -313,21 +313,20 @@ extension StorageManager { extension StorageManager { - static func saveServer(gateway: String, group: String, isFastestEnabled: Bool) { + static func saveServer(gateway: String, isFastestEnabled: Bool) { if let server = fetchServer(gateway: gateway) { server.isFastestEnabled = isFastestEnabled } else { let newServer = Server(context: context) - newServer.gateway = gateway - newServer.group = group + newServer.gateway = gateway.replacingOccurrences(of: ".wg.", with: ".gw.") newServer.isFastestEnabled = isFastestEnabled } saveContext() } - static func fetchServers(gateway: String = "", group: String = "", isFastestEnabled: Bool = false) -> [Server]? { - let request: NSFetchRequest = Server.fetchRequest(gateway: gateway, group: group, isFastestEnabled: isFastestEnabled) + static func fetchServers(gateway: String = "", isFastestEnabled: Bool = false) -> [Server]? { + let request: NSFetchRequest = Server.fetchRequest(gateway: gateway, isFastestEnabled: isFastestEnabled) do { let result = try context.fetch(request) @@ -362,10 +361,8 @@ extension StorageManager { static func canUpdateServer(isOn: Bool) -> Bool { guard !isOn else { return true } - let group = Application.shared.settings.fastestServerConfiguredKey - - if UserDefaults.standard.bool(forKey: group) { - if let servers = fetchServers(group: group, isFastestEnabled: true) { + if UserDefaults.standard.bool(forKey: Application.shared.settings.fastestServerConfiguredKey) { + if let servers = fetchServers(isFastestEnabled: true) { if servers.count == 1 { return false } diff --git a/IVPNClient/Model.xcdatamodeld/Model.xcdatamodel/contents b/IVPNClient/Model.xcdatamodeld/Model.xcdatamodel/contents index 1c5bfb69d..e44f7e53d 100644 --- a/IVPNClient/Model.xcdatamodeld/Model.xcdatamodel/contents +++ b/IVPNClient/Model.xcdatamodeld/Model.xcdatamodel/contents @@ -1,18 +1,17 @@ - + - - - - + + + + - - - + + - + \ No newline at end of file diff --git a/IVPNClient/Models/CoreData/Server+CoreDataProperties.swift b/IVPNClient/Models/CoreData/Server+CoreDataProperties.swift index 055579e19..669092283 100644 --- a/IVPNClient/Models/CoreData/Server+CoreDataProperties.swift +++ b/IVPNClient/Models/CoreData/Server+CoreDataProperties.swift @@ -27,7 +27,6 @@ import CoreData extension Server { @NSManaged public var gateway: String? - @NSManaged public var group: String? @NSManaged public var isFastestEnabled: Bool convenience init(context: NSManagedObjectContext, needToSave: Bool) { @@ -35,16 +34,12 @@ extension Server { self.init(entity: entity!, insertInto: needToSave ? context : nil) } - @nonobjc public class func fetchRequest(gateway: String = "", group: String = "", isFastestEnabled: Bool = false) -> NSFetchRequest { + @nonobjc public class func fetchRequest(gateway: String = "", isFastestEnabled: Bool = false) -> NSFetchRequest { let fetchRequest = NSFetchRequest(entityName: "Server") var filters = [NSPredicate]() if !gateway.isEmpty { - filters.append(NSPredicate(format: "gateway == %@", gateway)) - } - - if !group.isEmpty { - filters.append(NSPredicate(format: "group == %@", group)) + filters.append(NSPredicate(format: "gateway == %@", gateway.replacingOccurrences(of: ".wg.", with: ".gw."))) } if isFastestEnabled { diff --git a/IVPNClient/Models/Settings.swift b/IVPNClient/Models/Settings.swift index e129de579..b8799c159 100644 --- a/IVPNClient/Models/Settings.swift +++ b/IVPNClient/Models/Settings.swift @@ -59,11 +59,7 @@ class Settings { } var fastestServerConfiguredKey: String { - if connectionProtocol.tunnelType() == .wireguard { - return "FastestServerConfiguredForWireGuard" - } else { - return "FastestServerConfiguredForOpenVPN" - } + return "FastestServerConfiguredForOpenVPN" } init(serverList: VPNServerList) { diff --git a/IVPNClient/Models/VPNServerList.swift b/IVPNClient/Models/VPNServerList.swift index 6748d9d15..e45b75efb 100644 --- a/IVPNClient/Models/VPNServerList.swift +++ b/IVPNClient/Models/VPNServerList.swift @@ -169,7 +169,9 @@ class VPNServerList { func getFastestServer() -> VPNServer? { let servers = filteredFastestServers let serversWithPing = servers.filter { $0.pingMs ?? -1 >= 0 } - if serversWithPing.isEmpty { return nil } + if serversWithPing.isEmpty { + return filteredFastestServers.first + } return servers.min { let leftPingMs = $0.pingMs ?? -1 @@ -210,10 +212,9 @@ class VPNServerList { } func saveAllServers(exceptionGateway: String) { - let group = Application.shared.settings.fastestServerConfiguredKey for server in servers { let isFastestEnabled = server.gateway != exceptionGateway - StorageManager.saveServer(gateway: server.gateway, group: group, isFastestEnabled: isFastestEnabled) + StorageManager.saveServer(gateway: server.gateway, isFastestEnabled: isFastestEnabled) } } diff --git a/IVPNClient/Scenes/MainScreen/ControlPanel/ControlPanelViewController.swift b/IVPNClient/Scenes/MainScreen/ControlPanel/ControlPanelViewController.swift index 7f266d5c8..a38592619 100644 --- a/IVPNClient/Scenes/MainScreen/ControlPanel/ControlPanelViewController.swift +++ b/IVPNClient/Scenes/MainScreen/ControlPanel/ControlPanelViewController.swift @@ -374,7 +374,6 @@ class ControlPanelViewController: UITableViewController { tableView.backgroundColor = UIColor.init(named: Theme.ivpnBackgroundPrimary) tableView.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 1)) isMultiHop = UserDefaults.shared.isMultiHop - Application.shared.connectionManager.needsUpdateSelectedServer() controlPanelView.updateServerNames() controlPanelView.updateServerLabels(viewModel: vpnStatusViewModel) controlPanelView.updateAntiTracker() diff --git a/IVPNClient/Scenes/ViewControllers/ServersConfigurationTableViewController.swift b/IVPNClient/Scenes/ViewControllers/ServersConfigurationTableViewController.swift index 793dfeb96..0354a8603 100644 --- a/IVPNClient/Scenes/ViewControllers/ServersConfigurationTableViewController.swift +++ b/IVPNClient/Scenes/ViewControllers/ServersConfigurationTableViewController.swift @@ -86,7 +86,7 @@ extension ServersConfigurationTableViewController: ServerConfigurationCellDelega let fastestServerConfiguredKey = Application.shared.settings.fastestServerConfiguredKey if UserDefaults.standard.bool(forKey: fastestServerConfiguredKey) { - StorageManager.saveServer(gateway: gateway, group: fastestServerConfiguredKey, isFastestEnabled: isOn) + StorageManager.saveServer(gateway: gateway, isFastestEnabled: isOn) } else { Application.shared.serverList.saveAllServers(exceptionGateway: gateway) UserDefaults.standard.set(true, forKey: fastestServerConfiguredKey)