mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
- fix crash when some information missing about battery (#88)
- add MacPro5,1 to the list of devices
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user