mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
fix crash on start (the problem with self.window in popup)
- fix crash when missing wifi network name
This commit is contained in:
@@ -99,7 +99,7 @@ internal class Popup: NSView {
|
||||
var temperature: String = "Unknown"
|
||||
|
||||
DispatchQueue.main.async(execute: {
|
||||
if self.window!.isVisible || !self.ready {
|
||||
if (self.window?.isVisible ?? false) || !self.ready {
|
||||
if tempValue != nil {
|
||||
let formatter = MeasurementFormatter()
|
||||
let measurement = Measurement(value: tempValue!.rounded(toPlaces: 0), unit: UnitTemperature.celsius)
|
||||
@@ -107,7 +107,7 @@ internal class Popup: NSView {
|
||||
}
|
||||
|
||||
self.temperatureField?.stringValue = temperature
|
||||
|
||||
|
||||
self.systemField?.stringValue = "\(Int(value.systemLoad.rounded(toPlaces: 2) * 100)) %"
|
||||
self.userField?.stringValue = "\(Int(value.userLoad.rounded(toPlaces: 2) * 100)) %"
|
||||
self.idleField?.stringValue = "\(Int(value.idleLoad.rounded(toPlaces: 2) * 100)) %"
|
||||
|
||||
@@ -101,7 +101,7 @@ internal class Popup: NSView {
|
||||
|
||||
public func loadCallback(_ value: RAM_Usage) {
|
||||
DispatchQueue.main.async(execute: {
|
||||
if self.window!.isVisible || !self.initialized {
|
||||
if (self.window?.isVisible ?? false) || !self.initialized {
|
||||
self.activeField?.stringValue = Units(bytes: Int64(value.active!)).getReadableMemory()
|
||||
self.inactiveField?.stringValue = Units(bytes: Int64(value.inactive!)).getReadableMemory()
|
||||
self.wiredField?.stringValue = Units(bytes: Int64(value.wired!)).getReadableMemory()
|
||||
|
||||
@@ -147,7 +147,7 @@ internal class Popup: NSView {
|
||||
|
||||
public func usageCallback(_ value: Network_Usage) {
|
||||
DispatchQueue.main.async(execute: {
|
||||
if !self.window!.isVisible && self.initialized && value.active {
|
||||
if !(self.window?.isVisible ?? false) && self.initialized && value.active {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ internal class Popup: NSView {
|
||||
if value.connectionType != nil {
|
||||
var networkType = ""
|
||||
if value.connectionType == .wifi {
|
||||
networkType = "\(value.networkName!) (WiFi)"
|
||||
networkType = "\(value.networkName ?? "unknown") (WiFi)"
|
||||
} else if value.connectionType == .ethernet {
|
||||
networkType = "Ethernet"
|
||||
}
|
||||
|
||||
@@ -179,12 +179,12 @@ internal class UsageReader: Reader<Network_Usage> {
|
||||
|
||||
let matchingDict = matchingDictUM! as NSMutableDictionary
|
||||
matchingDict["IOPropertyMatch"] = [ "IOPrimaryInterface" : true]
|
||||
|
||||
|
||||
var matchingServices : io_iterator_t = 0
|
||||
if IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDict, &matchingServices) != KERN_SUCCESS {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
return matchingServices
|
||||
}
|
||||
|
||||
@@ -203,11 +203,11 @@ internal class UsageReader: Reader<Network_Usage> {
|
||||
}
|
||||
IOObjectRelease(controllerService)
|
||||
}
|
||||
|
||||
|
||||
IOObjectRelease(intfService)
|
||||
intfService = IOIteratorNext(intfIterator)
|
||||
}
|
||||
|
||||
|
||||
return macAddress
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user