diff --git a/Modules/Battery/main.swift b/Modules/Battery/main.swift index 9fe01c14..4b84d027 100644 --- a/Modules/Battery/main.swift +++ b/Modules/Battery/main.swift @@ -22,6 +22,9 @@ struct Battery_Usage: value_t { var cycles: Int = 0 var health: Int = 0 + var designedCapacity: Int = 0 + var maxCapacity: Int = 0 + var amperage: Int = 0 var voltage: Double = 0 var temperature: Double = 0 diff --git a/Modules/Battery/popup.swift b/Modules/Battery/popup.swift index 0c2e53bc..1650352a 100644 --- a/Modules/Battery/popup.swift +++ b/Modules/Battery/popup.swift @@ -19,7 +19,7 @@ internal class Popup: NSView, Popup_p { private let dashboardHeight: CGFloat = 90 - private let detailsHeight: CGFloat = (22 * 6) + Constants.Popup.separatorHeight + private let detailsHeight: CGFloat = (22 * 7) + Constants.Popup.separatorHeight private let batteryHeight: CGFloat = (22 * 4) + Constants.Popup.separatorHeight private let adapterHeight: CGFloat = (22 * 2) + Constants.Popup.separatorHeight private let processHeight: CGFloat = (22 * 1) @@ -35,6 +35,7 @@ internal class Popup: NSView, Popup_p { private var timeLabelField: NSTextField? = nil private var timeField: NSTextField? = nil private var healthField: NSTextField? = nil + private var capacityField: NSTextField? = nil private var cyclesField: NSTextField? = nil private var lastChargeField: NSTextField? = nil @@ -146,12 +147,14 @@ internal class Popup: NSView, Popup_p { let separator = separatorView(localizedString("Details"), origin: NSPoint(x: 0, y: self.detailsHeight-Constants.Popup.separatorHeight), width: self.frame.width) let container: NSView = NSView(frame: NSRect(x: 0, y: 0, width: self.frame.width, height: separator.frame.origin.y)) - self.levelField = popupRow(container, n: 5, title: "\(localizedString("Level")):", value: "").1 - self.sourceField = popupRow(container, n: 4, title: "\(localizedString("Source")):", value: "").1 - let t = self.labelValue(container, n: 3, title: "\(localizedString("Time")):", value: "") + self.levelField = popupRow(container, n: 6, title: "\(localizedString("Level")):", value: "").1 + self.sourceField = popupRow(container, n: 5, title: "\(localizedString("Source")):", value: "").1 + let t = self.labelValue(container, n: 4, title: "\(localizedString("Time")):", value: "") self.timeLabelField = t.0 self.timeField = t.1 - self.healthField = popupRow(container, n: 2, title: "\(localizedString("Health")):", value: "").1 + self.healthField = popupRow(container, n: 3, title: "\(localizedString("Health")):", value: "").1 + self.capacityField = popupRow(container, n: 2, title: "\(localizedString("Capacity")):", value: "").1 + self.capacityField?.toolTip = localizedString("maximum / designed") self.cyclesField = popupRow(container, n: 1, title: "\(localizedString("Cycles")):", value: "").1 self.lastChargeField = popupRow(container, n: 0, title: "\(localizedString("Last charge")):", value: "").1 @@ -258,6 +261,8 @@ internal class Popup: NSView, Popup_p { } self.healthField?.stringValue = "\(value.health)%" + self.capacityField?.stringValue = "\(value.maxCapacity) / \(value.designedCapacity) mAh" + if let state = value.state { self.healthField?.stringValue += " (\(state))" } diff --git a/Modules/Battery/readers.swift b/Modules/Battery/readers.swift index cf9d44b1..57c58659 100644 --- a/Modules/Battery/readers.swift +++ b/Modules/Battery/readers.swift @@ -78,15 +78,12 @@ internal class UsageReader: Reader { self.usage.cycles = self.getIntValue("CycleCount" as CFString) ?? 0 - var maxCapacity: Int = 1 - let designCapacity: Int = self.getIntValue("DesignCapacity" as CFString) ?? 1 - #if arch(x86_64) - maxCapacity = self.getIntValue("MaxCapacity" as CFString) ?? 1 - #else - maxCapacity = self.getIntValue("AppleRawMaxCapacity" as CFString) ?? 1 - #endif - self.usage.state = list[kIOPSBatteryHealthKey] as? String - self.usage.health = (100 * maxCapacity) / designCapacity + self.usage.designedCapacity = self.getIntValue("DesignCapacity" as CFString) ?? 1 + self.usage.maxCapacity = self.getIntValue((isARM ? "AppleRawMaxCapacity" : "MaxCapacity") as CFString) ?? 1 + if !isARM { + self.usage.state = list[kIOPSBatteryHealthKey] as? String + } + self.usage.health = Int((Double(100 * self.usage.maxCapacity) / Double(self.usage.designedCapacity)).rounded(.toNearestOrEven)) self.usage.amperage = self.getIntValue("Amperage" as CFString) ?? 0 self.usage.voltage = self.getVoltage() ?? 0