fix crash on start (the problem with self.window in popup)

- fix crash when missing wifi network name
This commit is contained in:
Serhiy Mytrovtsiy
2020-06-29 16:56:39 +02:00
parent e061a81723
commit 0f8e9ea739
6 changed files with 12 additions and 12 deletions

View File

@@ -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)) %"

View File

@@ -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()

View File

@@ -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"
}

View File

@@ -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
}
}