Skip to content

Commit

Permalink
**HOT FIX v2.11.12**
Browse files Browse the repository at this point in the history
fix: fixed non stopping fetching the wifi name that has a huge impact on network speed (#2146)
  • Loading branch information
exelban committed Sep 25, 2024
1 parent 7ec0c5c commit 109bc41
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 53 deletions.
108 changes: 60 additions & 48 deletions Modules/Net/readers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,12 @@ internal class UsageReader: Reader<Network_Usage> {
if self.active {
self.getPublicIP()
self.getDetails()
self.getWiFiDetails()
}
}
self.reachability.unreachable = {
if self.active {
self.getWiFiDetails()
self.usage.reset()
self.callback(self.usage)
}
Expand Down Expand Up @@ -326,58 +328,68 @@ internal class UsageReader: Reader<Network_Usage> {

guard self.usage.interface != nil else { return }

if self.usage.connectionType == .wifi {
if let interface = CWWiFiClient.shared().interface(withName: self.interfaceID) {
self.usage.wifiDetails.ssid = interface.ssid()
self.usage.wifiDetails.bssid = interface.bssid()
self.usage.wifiDetails.countryCode = interface.countryCode()

self.usage.wifiDetails.RSSI = interface.rssiValue()
self.usage.wifiDetails.noise = interface.noiseMeasurement()
self.usage.wifiDetails.transmitRate = interface.transmitRate()

self.usage.wifiDetails.standard = interface.activePHYMode().description
self.usage.wifiDetails.mode = interface.interfaceMode().description
self.usage.wifiDetails.security = interface.security().description

if let ch = interface.wlanChannel() {
self.usage.wifiDetails.channel = ch.description

self.usage.wifiDetails.channelBand = ch.channelBand.description
self.usage.wifiDetails.channelWidth = ch.channelWidth.description
self.usage.wifiDetails.channelNumber = ch.channelNumber.description
}
if self.usage.connectionType == .wifi && self.usage.wifiDetails.ssid == nil || self.usage.wifiDetails.ssid == "" {
self.getWiFiDetails()
}
}

private func getWiFiDetails() {
if let interface = CWWiFiClient.shared().interface(withName: self.interfaceID) {
if let ssid = interface.ssid() {
self.usage.wifiDetails.ssid = ssid
}
if let bssid = interface.bssid() {
self.usage.wifiDetails.bssid = bssid
}
if let cc = interface.countryCode() {
self.usage.wifiDetails.countryCode = cc
}

if self.usage.wifiDetails.ssid == nil || self.usage.wifiDetails.ssid == "" {
if #available(macOS 15, *) {
guard let res = process(path: "/usr/sbin/system_profiler", arguments: ["SPAirPortDataType", "-json"]) else {
return
}
do {
if let json = try JSONSerialization.jsonObject(with: Data(res.utf8), options: []) as? [String: Any] {
if let arr = json["SPAirPortDataType"] as? [[String: Any]],
let airport = arr.first(where: { $0["spairport_airport_interfaces"] != nil }),
let interfaces = airport["spairport_airport_interfaces"] as? [[String: Any]],
let interface = interfaces.first(where: { $0["_name"] as? String == self.interfaceID }),
let obj = interface["spairport_current_network_information"] as? [String: Any] {

self.usage.wifiDetails.ssid = obj["_name"] as? String
self.usage.wifiDetails.countryCode = obj["spairport_network_country_code"] as? String
self.usage.wifiDetails.standard = obj["spairport_network_phymode"] as? String
}
self.usage.wifiDetails.RSSI = interface.rssiValue()
self.usage.wifiDetails.noise = interface.noiseMeasurement()
self.usage.wifiDetails.transmitRate = interface.transmitRate()

self.usage.wifiDetails.standard = interface.activePHYMode().description
self.usage.wifiDetails.mode = interface.interfaceMode().description
self.usage.wifiDetails.security = interface.security().description

if let ch = interface.wlanChannel() {
self.usage.wifiDetails.channel = ch.description

self.usage.wifiDetails.channelBand = ch.channelBand.description
self.usage.wifiDetails.channelWidth = ch.channelWidth.description
self.usage.wifiDetails.channelNumber = ch.channelNumber.description
}
}

if self.usage.wifiDetails.ssid == nil || self.usage.wifiDetails.ssid == "" {
if #available(macOS 15, *) {
guard let res = process(path: "/usr/sbin/system_profiler", arguments: ["SPAirPortDataType", "-json"]) else {
return
}
do {
if let json = try JSONSerialization.jsonObject(with: Data(res.utf8), options: []) as? [String: Any] {
if let arr = json["SPAirPortDataType"] as? [[String: Any]],
let airport = arr.first(where: { $0["spairport_airport_interfaces"] != nil }),
let interfaces = airport["spairport_airport_interfaces"] as? [[String: Any]],
let interface = interfaces.first(where: { $0["_name"] as? String == self.interfaceID }),
let obj = interface["spairport_current_network_information"] as? [String: Any] {

self.usage.wifiDetails.ssid = obj["_name"] as? String
self.usage.wifiDetails.countryCode = obj["spairport_network_country_code"] as? String
self.usage.wifiDetails.standard = obj["spairport_network_phymode"] as? String
}
} catch let err as NSError {
error("error to parse system_profiler SPAirPortDataType: \(err.localizedDescription)")
return
}
} else {
let networksetupResponse = syncShell("networksetup -getairportnetwork \(self.interfaceID)")
if networksetupResponse.split(separator: "\n").count == 1 {
let arr = networksetupResponse.split(separator: ":")
if let ssid = arr.last {
self.usage.wifiDetails.ssid = ssid.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
}
} catch let err as NSError {
error("error to parse system_profiler SPAirPortDataType: \(err.localizedDescription)")
return
}
} else {
let networksetupResponse = syncShell("networksetup -getairportnetwork \(self.interfaceID)")
if networksetupResponse.split(separator: "\n").count == 1 {
let arr = networksetupResponse.split(separator: ":")
if let ssid = arr.last {
self.usage.wifiDetails.ssid = ssid.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Stats.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2841,7 +2841,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 2.11.11;
MARKETING_VERSION = 2.11.12;
OTHER_LDFLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = eu.exelban.Stats;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -2879,7 +2879,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 2.11.11;
MARKETING_VERSION = 2.11.12;
OTHER_LDFLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = eu.exelban.Stats;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
2 changes: 1 addition & 1 deletion Stats/Supporting Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>597</string>
<string>599</string>
<key>Description</key>
<string>Simple macOS system monitor in your menu bar</string>
<key>LSApplicationCategoryType</key>
Expand Down
4 changes: 2 additions & 2 deletions Widgets/Supporting Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleShortVersionString</key>
<string>2.11.11</string>
<string>2.11.12</string>
<key>CFBundleVersion</key>
<string>597</string>
<string>599</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
Expand Down

0 comments on commit 109bc41

Please sign in to comment.