Skip to content

Commit

Permalink
Merge pull request #160 from ivpn/bugfix/wrong-location-on-the-map
Browse files Browse the repository at this point in the history
App shows wrong location on the map if device is connected to IVPN gateway with VPN profile not managed by the IVPN app
  • Loading branch information
jurajhilje authored Sep 10, 2021
2 parents 2bdeea4 + 7b6377e commit 607b07c
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class ConnectionInfoPopupView: UIView {
didSet {
statusLabel.text = vpnStatusViewModel.popupStatusText
flagImage.image = UIImage.init(named: viewModel.imageNameForCountryCode)
locationLabel.text = "\(viewModel.city), \(viewModel.countryCode)"
locationLabel.text = viewModel.location
}
}

Expand Down
2 changes: 1 addition & 1 deletion IVPNClient/Scenes/MainScreen/Map/MapMarkerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class MapMarkerView: UIView {

var viewModel: ProofsViewModel? {
didSet {
if markerType == .local && !(viewModel?.isIvpnServer ?? false) {
if markerType == .local {
locationButton.setTitle(viewModel?.city, for: .normal)
connectionInfoPopup.viewModel = viewModel
}
Expand Down
2 changes: 1 addition & 1 deletion IVPNClient/Scenes/MainScreen/Map/MapScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class MapScrollView: UIScrollView {

markerLocalView.viewModel = viewModel

if !viewModel.isIvpnServer && Application.shared.connectionManager.status.isDisconnected() {
if Application.shared.connectionManager.status.isDisconnected() {
updateMapPosition(viewModel: viewModel, animated: oldValue != nil)
markerGatewayView.hide(animated: true)
markerLocalView.show(animated: oldValue != nil)
Expand Down
2 changes: 1 addition & 1 deletion IVPNClient/Scenes/MainScreen/View/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class MainView: UIView {
return
}

if !model.isIvpnServer {
if Application.shared.connectionManager.status.isDisconnected() {
localCoordinates = (model.latitude, model.longitude)
mapScrollView.localCoordinates = (model.latitude, model.longitude)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class NetworkProtectionRulesViewController: UITableViewController {

@IBAction func toggleUntrustedConnect(_ sender: UISwitch) {
defaults.set(sender.isOn, forKey: UserDefaults.Key.networkProtectionUntrustedConnect)
Application.shared.connectionManager.evaluateConnection() { [self] error in
Application.shared.connectionManager.evaluateConnection { [self] error in
if error != nil {
showWireGuardKeysMissingError()
}
Expand All @@ -40,7 +40,7 @@ class NetworkProtectionRulesViewController: UITableViewController {

@IBAction func toggleTrustedDisconnect(_ sender: UISwitch) {
defaults.set(sender.isOn, forKey: UserDefaults.Key.networkProtectionTrustedDisconnect)
Application.shared.connectionManager.evaluateConnection() { [self] error in
Application.shared.connectionManager.evaluateConnection { [self] error in
if error != nil {
showWireGuardKeysMissingError()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ extension NetworkProtectionViewController: NetworkProtectionHeaderTableViewCellD

if isOn {
NetworkManager.shared.startMonitoring {
Application.shared.connectionManager.evaluateConnection() { [self] error in
Application.shared.connectionManager.evaluateConnection { [self] error in
if error != nil {
showWireGuardKeysMissingError()
}
Expand Down
4 changes: 1 addition & 3 deletions IVPNClient/Utilities/DNSResolver/DNSResolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ final class DNSResolver {
/// - parameter timeout: The connection timeout.
/// - parameter completion: A completion block that will be called both on failure and success with a list
/// of IPs.
static func resolve(host: String, timeout: TimeInterval = 8.0,
completion: @escaping ([InternetAddress]) -> Void)
{
static func resolve(host: String, timeout: TimeInterval = 8.0, completion: @escaping ([InternetAddress]) -> Void) {
let callback: CFHostClientCallBack = { host, _, _, info in
guard let info = info else {
return
Expand Down
2 changes: 1 addition & 1 deletion IVPNClient/Utilities/Extensions/URL+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Foundation
extension URL {

func getTopLevelSubdomain() -> String {
if let hostName = host {
if let hostName = host {
let subStrings = hostName.components(separatedBy: ".")
var domainName = ""
let count = subStrings.count
Expand Down
4 changes: 4 additions & 0 deletions IVPNClient/ViewModels/ProofsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ struct ProofsViewModel {
return ""
}

guard !model.city.isEmpty else {
return model.country
}

return "\(model.city), \(model.countryCode)"
}

Expand Down
8 changes: 8 additions & 0 deletions UnitTests/ViewModels/ProofsViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,12 @@ class ProofsViewModelTests: XCTestCase {
XCTAssertEqual(viewModel.provider, "IVPN")
}

func test_location() {
viewModel.model = GeoLookup(ipAddress: "0.0.0.0", countryCode: "DE", country: "Germany", city: "Berlin", isIvpnServer: false, isp: "ISP Provider", latitude: 0, longitude: 0)
XCTAssertEqual(viewModel.location, "Berlin, DE")

viewModel.model = GeoLookup(ipAddress: "0.0.0.0", countryCode: "DE", country: "Germany", city: "", isIvpnServer: false, isp: "ISP Provider", latitude: 0, longitude: 0)
XCTAssertEqual(viewModel.location, "Germany")
}

}

0 comments on commit 607b07c

Please sign in to comment.