- fix crash when some information missing about battery (#88)

- add MacPro5,1 to the list of devices
This commit is contained in:
Serhiy Mytrovtsiy
2020-09-20 21:30:23 +02:00
parent 9ed0002ec3
commit ebd901ec7b
5 changed files with 13 additions and 8 deletions

View File

@@ -59,13 +59,17 @@ internal class UsageReader: Reader<Battery_Usage> {
for ps in psList {
if let list = IOPSGetPowerSourceDescription(psInfo, ps).takeUnretainedValue() as? Dictionary<String, Any> {
self.usage.powerSource = list[kIOPSPowerSourceStateKey] as? String ?? "AC Power"
self.usage.state = list[kIOPSBatteryHealthKey] as! String
self.usage.state = list[kIOPSBatteryHealthKey] as? String ?? "0"
self.usage.isCharged = list[kIOPSIsChargedKey] as? Bool ?? false
self.usage.isCharging = self.getBoolValue("IsCharging" as CFString) ?? false
self.usage.level = Double(list[kIOPSCurrentCapacityKey] as! Int) / 100
self.usage.level = Double(list[kIOPSCurrentCapacityKey] as? Int ?? 0) / 100
self.usage.timeToEmpty = Int(list[kIOPSTimeToEmptyKey] as! Int)
self.usage.timeToCharge = Int(list[kIOPSTimeToFullChargeKey] as! Int)
if let time = list[kIOPSTimeToEmptyKey] as? Int {
self.usage.timeToEmpty = Int(time)
}
if let time = list[kIOPSTimeToFullChargeKey] as? Int {
self.usage.timeToCharge = Int(time)
}
self.usage.cycles = self.getIntValue("CycleCount" as CFString) ?? 0

View File

@@ -17,7 +17,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>47</string>
<string>49</string>
<key>Description</key>
<string>Simple macOS system monitor in your menu bar</string>
<key>LSApplicationCategoryType</key>

View File

@@ -322,7 +322,7 @@ class ApplicationSettings: NSView {
} else {
state = sender is NSButton ? (sender as! NSButton).state: nil
}
if state != nil {
store.set(key: "dockIcon", value: state! == NSControl.StateValue.on)
}

View File

@@ -327,6 +327,7 @@ let deviceDict: [String: model_s] = [
"Macmini8,1": model_s(name: "Mac mini (Late 2018)", year: 2012, type: .macMini),
// Mac Pro
"MacPro5,1": model_s(name: "Mac Pro (2012)", year: 2010, type: .macPro),
"MacPro6,1": model_s(name: "Mac Pro (Late 2013)", year: 2012, type: .macPro),
"MacPro7,1": model_s(name: "Mac Pro (2019)", year: 2012, type: .macPro),

View File

@@ -262,14 +262,14 @@ public extension Double {
}
}
func secondsToHoursMinutesSeconds () -> (Int?, Int?, Int?) {
func secondsToHoursMinutesSeconds() -> (Int?, Int?, Int?) {
let hrs = self / 3600
let mins = (self.truncatingRemainder(dividingBy: 3600)) / 60
let seconds = (self.truncatingRemainder(dividingBy:3600)).truncatingRemainder(dividingBy:60)
return (Int(hrs) > 0 ? Int(hrs) : nil , Int(mins) > 0 ? Int(mins) : nil, Int(seconds) > 0 ? Int(seconds) : nil)
}
func printSecondsToHoursMinutesSeconds () -> String {
func printSecondsToHoursMinutesSeconds() -> String {
let time = self.secondsToHoursMinutesSeconds()
switch time {