Skip to content

Commit

Permalink
fix crash on start (the problem with self.window in popup)
Browse files Browse the repository at this point in the history
- fix crash when missing wifi network name
  • Loading branch information
exelban committed Jun 29, 2020
1 parent e061a81 commit 0f8e9ea
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion ModuleKit/Widgets/popup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ internal class Popup: NSView {
values.forEach { (s: Sensor_t) in
if self.list[s.key] != nil {
DispatchQueue.main.async(execute: {
if self.window!.isVisible {
if (self.window?.isVisible ?? false) {
self.list[s.key]?.stringValue = s.formattedValue
}
})
Expand Down
4 changes: 2 additions & 2 deletions Modules/CPU/popup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ 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)
temperature = formatter.string(from: measurement)
}

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)) %"
Expand Down
2 changes: 1 addition & 1 deletion Modules/Memory/popup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions Modules/Net/popup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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"
}
Expand Down
8 changes: 4 additions & 4 deletions Modules/Net/readers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -203,11 +203,11 @@ internal class UsageReader: Reader<Network_Usage> {
}
IOObjectRelease(controllerService)
}

IOObjectRelease(intfService)
intfService = IOIteratorNext(intfIterator)
}

return macAddress
}
}
4 changes: 2 additions & 2 deletions Stats.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1680,7 +1680,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 2.1.1;
MARKETING_VERSION = 2.1.2;
PRODUCT_BUNDLE_IDENTIFIER = eu.exelban.Stats;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -1712,7 +1712,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 2.1.1;
MARKETING_VERSION = 2.1.2;
PRODUCT_BUNDLE_IDENTIFIER = eu.exelban.Stats;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down

0 comments on commit 0f8e9ea

Please sign in to comment.