mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: added charging current and voltage (#1986)
This commit is contained in:
@@ -33,6 +33,8 @@ struct Battery_Usage: Codable {
|
||||
var temperature: Double = 0
|
||||
|
||||
var ACwatts: Int = 0
|
||||
var chargingCurrent: Int = 0
|
||||
var chargingVoltage: Int = 0
|
||||
|
||||
var timeToEmpty: Int = 0
|
||||
var timeToCharge: Int = 0
|
||||
|
||||
@@ -23,7 +23,7 @@ internal class Popup: PopupWrapper {
|
||||
return (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 adapterHeight: CGFloat = (22 * 4) + Constants.Popup.separatorHeight
|
||||
private let processHeight: CGFloat = (22 * 1)
|
||||
|
||||
private var dashboardView: NSView? = nil
|
||||
@@ -48,6 +48,8 @@ internal class Popup: PopupWrapper {
|
||||
|
||||
private var powerField: NSTextField? = nil
|
||||
private var chargingStateField: NSTextField? = nil
|
||||
private var chargingCurrentField: NSTextField? = nil
|
||||
private var chargingVoltageField: NSTextField? = nil
|
||||
|
||||
private var processes: ProcessesView? = nil
|
||||
private var processesInitialized: Bool = false
|
||||
@@ -185,8 +187,10 @@ internal class Popup: PopupWrapper {
|
||||
let separator = separatorView(localizedString("Power adapter"), origin: NSPoint(x: 0, y: self.adapterHeight-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.powerField = popupRow(container, n: 1, title: "\(localizedString("Power")):", value: "").1
|
||||
self.chargingStateField = popupRow(container, n: 0, title: "\(localizedString("Is charging")):", value: "").1
|
||||
self.powerField = popupRow(container, n: 3, title: "\(localizedString("Power")):", value: "").1
|
||||
self.chargingStateField = popupRow(container, n: 2, title: "\(localizedString("Is charging")):", value: "").1
|
||||
self.chargingCurrentField = popupRow(container, n: 1, title: "\(localizedString("Charging Current")):", value: "").1
|
||||
self.chargingVoltageField = popupRow(container, n: 0, title: "\(localizedString("Charging Voltage")):", value: "").1
|
||||
|
||||
self.adapterView = view
|
||||
|
||||
@@ -303,6 +307,8 @@ internal class Popup: PopupWrapper {
|
||||
|
||||
self.powerField?.stringValue = value.isBatteryPowered ? localizedString("Not connected") : "\(value.ACwatts) W"
|
||||
self.chargingStateField?.stringValue = value.isCharging ? localizedString("Yes") : localizedString("No")
|
||||
self.chargingCurrentField?.stringValue = value.isBatteryPowered ? localizedString("Not connected") : "\(value.chargingCurrent) mA"
|
||||
self.chargingVoltageField?.stringValue = value.isBatteryPowered ? localizedString("Not connected") : "\(value.chargingVoltage) mV"
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -103,6 +103,11 @@ internal class UsageReader: Reader<Battery_Usage> {
|
||||
}
|
||||
self.usage.ACwatts = ACwatts
|
||||
|
||||
if let chargerData = self.getChargerData() {
|
||||
self.usage.chargingCurrent = chargerData["ChargingCurrent"] as? Int ?? 0
|
||||
self.usage.chargingVoltage = chargerData["ChargingVoltage"] as? Int ?? 0
|
||||
}
|
||||
|
||||
self.callback(self.usage)
|
||||
}
|
||||
}
|
||||
@@ -142,6 +147,13 @@ internal class UsageReader: Reader<Battery_Usage> {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
private func getChargerData() -> [String: Any]? {
|
||||
if let chargerData = IORegistryEntryCreateCFProperty(service, "ChargerData" as CFString, kCFAllocatorDefault, 0) {
|
||||
return chargerData.takeRetainedValue() as? [String: Any]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
public class ProcessReader: Reader<[TopProcess]> {
|
||||
|
||||
Reference in New Issue
Block a user