Skip to content

Commit

Permalink
feat: moved network country code from wifi adapter to IP address based (
Browse files Browse the repository at this point in the history
  • Loading branch information
exelban committed Feb 3, 2025
1 parent 04993c1 commit e3e149a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions Modules/Net/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public struct Network_interface: Codable {
public struct Network_addr: Codable {
var v4: String? = nil
var v6: String? = nil
var countryCode: String? = nil
}

public struct Network_wifi: Codable {
Expand Down
11 changes: 9 additions & 2 deletions Modules/Net/popup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,11 @@ internal class Popup: PopupWrapper {
}

if let interface = value.interface {
self.interfaceField?.stringValue = "\(interface.displayName) (\(interface.BSDName))"
self.interfaceField?.stringValue = "\(interface.displayName) (\(interface.BSDName)"
if let cc = value.wifiDetails.countryCode {
self.interfaceField?.stringValue += ", \(cc)"
}
self.interfaceField?.stringValue += ")"
self.macAddressField?.stringValue = interface.address
} else {
self.interfaceField?.stringValue = localizedString("Unknown")
Expand Down Expand Up @@ -462,7 +466,10 @@ internal class Popup: PopupWrapper {
self.recalculateHeight()
}
if self.publicIPv4Field?.stringValue != addr {
self.publicIPv4Field?.stringValue = (value.wifiDetails.countryCode != nil) ? "\(addr) (\(value.wifiDetails.countryCode!))" : addr
self.publicIPv4Field?.stringValue = addr
if let cc = value.raddr.countryCode {
self.publicIPv4Field?.stringValue += " (\(cc))"
}
}
} else if view.superview != nil {
view.removeFromSuperview()
Expand Down
7 changes: 7 additions & 0 deletions Modules/Net/readers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ internal class UsageReader: Reader<Network_Usage>, CWEventDelegate {
struct Addr_s: Decodable {
let ipv4: String?
let ipv6: String?
let country: String?
}

DispatchQueue.global(qos: .userInitiated).async {
Expand All @@ -425,6 +426,9 @@ internal class UsageReader: Reader<Network_Usage>, CWEventDelegate {
if let ip = addr.ipv4, self.isIPv4(ip) {
self.usage.raddr.v4 = ip
}
if let countryCode = addr.country {
self.usage.raddr.countryCode = countryCode
}
}
}
DispatchQueue.global(qos: .userInitiated).async {
Expand All @@ -434,6 +438,9 @@ internal class UsageReader: Reader<Network_Usage>, CWEventDelegate {
if let ip = addr.ipv6, !self.isIPv4(ip) {
self.usage.raddr.v6 = ip
}
if let countryCode = addr.country {
self.usage.raddr.countryCode = countryCode
}
}
}
}
Expand Down

0 comments on commit e3e149a

Please sign in to comment.