Skip to content

Commit

Permalink
feat: update ConnectionInfoViewModel
Browse files Browse the repository at this point in the history
  • Loading branch information
jurajhilje committed Oct 23, 2023
1 parent 862555e commit 84627e2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
2 changes: 2 additions & 0 deletions IVPNWidget/Scene/ConnectionInfo/ConnectionInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ struct ConnectionInfo {
var multiHop: Bool
var selectedProtocol: String
var geoLookup: GeoLookup
var isV2ray: Bool
var v2rayProtocol: String
}
23 changes: 17 additions & 6 deletions IVPNWidget/Scene/ConnectionInfo/ConnectionInfoViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,18 @@ extension ConnectionInfoView {
var port = 0
let components = model.selectedProtocol.components(separatedBy: "-")

if let protocolType = components[safeIndex: 1] {
proto = protocolType.uppercased()
}

if let protocolPort = components[safeIndex: 2] {
port = Int(protocolPort) ?? 0
}

if let protocolName = components[safeIndex: 0] {
if protocolName == "wireguard" {
name = "WireGuard"
proto = wireguardProtocol()
}
if protocolName == "openvpn" {
name = "OpenVPN"
Expand All @@ -75,12 +84,6 @@ extension ConnectionInfoView {
return "IKEv2"
}
}
if let protocolType = components[safeIndex: 1] {
proto = protocolType.uppercased()
}
if let protocolPort = components[safeIndex: 2] {
port = Int(protocolPort) ?? 0
}

if model.multiHop {
return "\(name), \(proto)"
Expand All @@ -93,5 +96,13 @@ extension ConnectionInfoView {
return model.antiTracker ? "ON" : "OFF"
}

func wireguardProtocol() -> String {
if model.isV2ray && model.v2rayProtocol == "tcp" {
return "TCP"
}

return "UDP"
}

}
}
17 changes: 16 additions & 1 deletion IVPNWidget/Service/DataService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ class WidgetDataService: DataService {
}

func getConnectionInfo() -> ConnectionInfo {
return ConnectionInfo(antiTracker: getAntiTracker(), multiHop: getMultiHop(), selectedProtocol: getProtocol(), geoLookup: getLocation())
return ConnectionInfo(
antiTracker: getAntiTracker(),
multiHop: getMultiHop(),
selectedProtocol: getProtocol(),
geoLookup: getLocation(),
isV2ray: getIsV2ray(),
v2rayProtocol: getV2rayProtocol()
)
}

func getAntiTracker() -> Bool {
Expand All @@ -64,4 +71,12 @@ class WidgetDataService: DataService {
return UserDefaults.shared.selectedProtocol
}

func getIsV2ray() -> Bool {
return UserDefaults.shared.isV2ray
}

func getV2rayProtocol() -> String {
return UserDefaults.shared.v2rayProtocol
}

}

0 comments on commit 84627e2

Please sign in to comment.