diff --git a/Modules/Battery/readers.swift b/Modules/Battery/readers.swift index 47a0ab44..7a547f0f 100644 --- a/Modules/Battery/readers.swift +++ b/Modules/Battery/readers.swift @@ -59,13 +59,17 @@ internal class UsageReader: Reader { for ps in psList { if let list = IOPSGetPowerSourceDescription(psInfo, ps).takeUnretainedValue() as? Dictionary { 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 diff --git a/Stats/Supporting Files/Info.plist b/Stats/Supporting Files/Info.plist index 8cf8fab7..59b93c45 100755 --- a/Stats/Supporting Files/Info.plist +++ b/Stats/Supporting Files/Info.plist @@ -17,7 +17,7 @@ CFBundleShortVersionString $(MARKETING_VERSION) CFBundleVersion - 47 + 49 Description Simple macOS system monitor in your menu bar LSApplicationCategoryType diff --git a/Stats/Views/AppSettings.swift b/Stats/Views/AppSettings.swift index 117249a1..961c62da 100644 --- a/Stats/Views/AppSettings.swift +++ b/Stats/Views/AppSettings.swift @@ -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) } diff --git a/StatsKit/SystemKit.swift b/StatsKit/SystemKit.swift index 47acb6a9..99c6f101 100644 --- a/StatsKit/SystemKit.swift +++ b/StatsKit/SystemKit.swift @@ -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), diff --git a/StatsKit/extensions.swift b/StatsKit/extensions.swift index df75e36b..5f6d7bfa 100644 --- a/StatsKit/extensions.swift +++ b/StatsKit/extensions.swift @@ -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 {