mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-15 00:34:08 +09:00
feat: add information when last time charger was connected in the battery popup (#450)
This commit is contained in:
@@ -31,6 +31,7 @@ struct Battery_Usage: value_t {
|
||||
|
||||
var timeToEmpty: Int = 0
|
||||
var timeToCharge: Int = 0
|
||||
var timeOnACPower: Date? = nil
|
||||
|
||||
public var widget_value: Double {
|
||||
get {
|
||||
|
||||
@@ -21,7 +21,7 @@ internal class Popup: NSView, Popup_p {
|
||||
private let dashboardHeight: CGFloat = 90
|
||||
|
||||
private let detailsHeight: CGFloat = (22 * 5) + Constants.Popup.separatorHeight
|
||||
private let batteryHeight: CGFloat = (22 * 4) + Constants.Popup.separatorHeight
|
||||
private let batteryHeight: CGFloat = (22 * 5) + Constants.Popup.separatorHeight
|
||||
private let adapterHeight: CGFloat = (22 * 2) + Constants.Popup.separatorHeight
|
||||
private let processHeight: CGFloat = (22 * 1)
|
||||
|
||||
@@ -37,6 +37,7 @@ internal class Popup: NSView, Popup_p {
|
||||
private var timeField: NSTextField? = nil
|
||||
private var healthField: NSTextField? = nil
|
||||
private var cyclesField: NSTextField? = nil
|
||||
private var lastChargeField: NSTextField? = nil
|
||||
|
||||
private var amperageField: NSTextField? = nil
|
||||
private var voltageField: NSTextField? = nil
|
||||
@@ -141,13 +142,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: 4, title: "\(LocalizedString("Level")):", value: "").1
|
||||
self.sourceField = PopupRow(container, n: 3, title: "\(LocalizedString("Source")):", value: "").1
|
||||
let t = self.labelValue(container, n: 2, title: "\(LocalizedString("Time")):", value: "")
|
||||
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.timeLabelField = t.0
|
||||
self.timeField = t.1
|
||||
self.healthField = PopupRow(container, n: 1, title: "\(LocalizedString("Health")):", value: "").1
|
||||
self.cyclesField = PopupRow(container, n: 0, title: "\(LocalizedString("Cycles")):", value: "").1
|
||||
self.healthField = PopupRow(container, n: 2, title: "\(LocalizedString("Health")):", value: "").1
|
||||
self.cyclesField = PopupRow(container, n: 1, title: "\(LocalizedString("Cycles")):", value: "").1
|
||||
self.lastChargeField = PopupRow(container, n: 0, title: "\(LocalizedString("Last charge")):", value: "").1
|
||||
|
||||
view.addSubview(separator)
|
||||
view.addSubview(container)
|
||||
@@ -251,6 +253,27 @@ internal class Popup: NSView, Popup_p {
|
||||
}
|
||||
self.cyclesField?.stringValue = "\(value.cycles)"
|
||||
|
||||
let form = DateComponentsFormatter()
|
||||
form.maximumUnitCount = 2
|
||||
form.unitsStyle = .full
|
||||
form.allowedUnits = [.day, .hour, .minute]
|
||||
if let timestamp = value.timeOnACPower {
|
||||
if let duration = form.string(from: timestamp, to: Date()) {
|
||||
let formatter = DateFormatter()
|
||||
formatter.timeStyle = .short
|
||||
formatter.dateStyle = .medium
|
||||
|
||||
self.lastChargeField?.stringValue = duration
|
||||
self.lastChargeField?.toolTip = formatter.string(from: timestamp)
|
||||
} else {
|
||||
self.lastChargeField?.stringValue = LocalizedString("Unknown")
|
||||
self.lastChargeField?.toolTip = LocalizedString("Unknown")
|
||||
}
|
||||
} else {
|
||||
self.lastChargeField?.stringValue = LocalizedString("Unknown")
|
||||
self.lastChargeField?.toolTip = LocalizedString("Unknown")
|
||||
}
|
||||
|
||||
self.amperageField?.stringValue = "\(abs(value.amperage)) mA"
|
||||
self.voltageField?.stringValue = "\(value.voltage.roundTo(decimalPlaces: 2)) V"
|
||||
let batteryPower = value.voltage * (Double(abs(value.amperage))/1000)
|
||||
|
||||
@@ -74,6 +74,10 @@ internal class UsageReader: Reader<Battery_Usage> {
|
||||
self.usage.timeToCharge = Int(time)
|
||||
}
|
||||
|
||||
if self.usage.powerSource == "AC Power" {
|
||||
self.usage.timeOnACPower = Date()
|
||||
}
|
||||
|
||||
self.usage.cycles = self.getIntValue("CycleCount" as CFString) ?? 0
|
||||
|
||||
let maxCapacity = self.getIntValue("MaxCapacity" as CFString) ?? 1
|
||||
|
||||
@@ -211,6 +211,7 @@
|
||||
"Time and percentage" = "Време и процент";
|
||||
"Time format" = "Формат на времето";
|
||||
"Hide additional information when full" = "Скриване на допълнителна информация при пълен заряд";
|
||||
"Last charge" = "Последно зареждане";
|
||||
|
||||
// Fans
|
||||
"Fans" = "Вентилатори";
|
||||
|
||||
@@ -211,6 +211,7 @@
|
||||
"Time and percentage" = "Čas a procenta";
|
||||
"Time format" = "Formát času";
|
||||
"Hide additional information when full" = "Skrýt další informace při plném nabití";
|
||||
"Last charge" = "Poslední poplatek";
|
||||
|
||||
// Fans
|
||||
"Fans" = "Ventilátory";
|
||||
|
||||
@@ -211,6 +211,7 @@
|
||||
"Time and percentage" = "Zeit und Prozentsatz";
|
||||
"Time format" = "Zeitformat";
|
||||
"Hide additional information when full" = "Zusätzliche Informationen bei vollständiger Ladung verbergen";
|
||||
"Last charge" = "Letzte Ladung";
|
||||
|
||||
// Fans
|
||||
"Fans" = "Lüfter";
|
||||
|
||||
@@ -211,6 +211,7 @@
|
||||
"Time and percentage" = "Time and percentage";
|
||||
"Time format" = "Time format";
|
||||
"Hide additional information when full" = "Hide additional information when full";
|
||||
"Last charge" = "Last charge";
|
||||
|
||||
// Fans
|
||||
"Fans" = "Fans";
|
||||
|
||||
@@ -211,6 +211,7 @@
|
||||
"Time and percentage" = "Tiempo y porcentaje";
|
||||
"Time format" = "Formato de tiempo";
|
||||
"Hide additional information when full" = "Ocultar información adicional cuando la batería está cargada";
|
||||
"Last charge" = "Última carga";
|
||||
|
||||
// Fans
|
||||
"Fans" = "Ventiladores";
|
||||
|
||||
@@ -211,6 +211,7 @@
|
||||
"Time and percentage" = "Temps et pourcentage";
|
||||
"Time format" = "Format de l'heure";
|
||||
"Hide additional information when full" = "Masquer les informations supplémentaires lorsque la batterie est pleine";
|
||||
"Last charge" = "Dernière charge";
|
||||
|
||||
// Fans
|
||||
"Fans" = "Fans";
|
||||
|
||||
@@ -211,6 +211,7 @@
|
||||
"Time and percentage" = "Időtartam és százalék";
|
||||
"Time format" = "Időformátum";
|
||||
"Hide additional information when full" = "További információk elrejtése, ha teljesen fel van töltve";
|
||||
"Last charge" = "Utolsó töltés";
|
||||
|
||||
// Fans
|
||||
"Fans" = "Ventillátorok";
|
||||
|
||||
@@ -211,6 +211,7 @@
|
||||
"Time and percentage" = "Tempo e percentuale";
|
||||
"Time format" = "Formato del tempo";
|
||||
"Hide additional information when full" = "Nascondi informazioni addizionali quando piena";
|
||||
"Last charge" = "Ultima carica";
|
||||
|
||||
// Fans
|
||||
"Fans" = "Fans";
|
||||
|
||||
@@ -211,6 +211,7 @@
|
||||
"Time and percentage" = "残り時間と残量(%)";
|
||||
"Time format" = "時間の表示形式";
|
||||
"Hide additional information when full" = "フル充電済みのときはアイコンのみ表示";
|
||||
"Last charge" = "ラストチャージ";
|
||||
|
||||
// Fans
|
||||
"Fans" = "ファン";
|
||||
|
||||
@@ -211,6 +211,7 @@
|
||||
"Time and percentage" = "시간과 비율";
|
||||
"Time format" = "시간 형식";
|
||||
"Hide additional information when full" = "배터리가 가득 차면 추가 정보 숨기기";
|
||||
"Last charge" = "마지막 청구";
|
||||
|
||||
// Fans
|
||||
"Fans" = "팬";
|
||||
|
||||
@@ -211,6 +211,7 @@
|
||||
"Time and percentage" = "Tid og prosent";
|
||||
"Time format" = "Tidsformat";
|
||||
"Hide additional information when full" = "Skjul ekstra information når fulladet";
|
||||
"Last charge" = "Siste lading";
|
||||
|
||||
// Fans
|
||||
"Fans" = "Vifter";
|
||||
|
||||
@@ -211,6 +211,7 @@
|
||||
"Time and percentage" = "Tijd and Percentage";
|
||||
"Time format" = "Tijdnotatie";
|
||||
"Hide additional information when full" = "Verberg aanvullende informatie wanneer deze vol is";
|
||||
"Last charge" = "Sidste opladning";
|
||||
|
||||
// Fans
|
||||
"Fans" = "Fans";
|
||||
|
||||
@@ -211,6 +211,7 @@
|
||||
"Time and percentage" = "Czas i procenty";
|
||||
"Time format" = "Format czasu";
|
||||
"Hide additional information when full" = "Ukryj dodatkowe informacje, gdy bateria jest naładowana";
|
||||
"Last charge" = "Ostatnie ładowanie";
|
||||
|
||||
// Fans
|
||||
"Fans" = "Wentylatory";
|
||||
|
||||
@@ -211,6 +211,7 @@
|
||||
"Time and percentage" = "Tempo e porcentagem";
|
||||
"Time format" = "Formato de hora";
|
||||
"Hide additional information when full" = "Ocultar informações adicionais quando estiver cheia";
|
||||
"Last charge" = "Última carga";
|
||||
|
||||
// Fans
|
||||
"Fans" = "Ventoinhas";
|
||||
|
||||
@@ -211,6 +211,7 @@
|
||||
"Time and percentage" = "Tempo e porcentagem";
|
||||
"Time format" = "Formato de hora";
|
||||
"Hide additional information when full" = "Ocultar informações adicionais quando estiver cheia";
|
||||
"Last charge" = "Última carga";
|
||||
|
||||
// Fans
|
||||
"Fans" = "Ventoinhas";
|
||||
|
||||
@@ -211,6 +211,7 @@
|
||||
"Time and percentage" = "Timp si procentaj";
|
||||
"Time format" = "Formatul timpului";
|
||||
"Hide additional information when full" = "Ascunde restul informației cand e plină";
|
||||
"Last charge" = "Ultima încărcare";
|
||||
|
||||
// Fans
|
||||
"Fans" = "Ventilatoare";
|
||||
|
||||
@@ -211,6 +211,7 @@
|
||||
"Time and percentage" = "Время и Проценты";
|
||||
"Time format" = "Формат времени";
|
||||
"Hide additional information when full" = "Скрыть дополнительную информацию при полном заряде";
|
||||
"Last charge" = "Последняя зарядка";
|
||||
|
||||
// Fans
|
||||
"Fans" = "Fans";
|
||||
|
||||
@@ -211,6 +211,7 @@
|
||||
"Time and percentage" = "Zaman ve yüzde";
|
||||
"Time format" = "Zaman formatı";
|
||||
"Hide additional information when full" = "Pil dolduğunda ek bilgileri gizle";
|
||||
"Last charge" = "Son ödeme";
|
||||
|
||||
// Fans
|
||||
"Fans" = "Fanlar";
|
||||
|
||||
@@ -211,6 +211,7 @@
|
||||
"Time and percentage" = "Час і проценти";
|
||||
"Time format" = "Формат часу";
|
||||
"Hide additional information when full" = "Приховати додаткову інформацію, якщо акумулятор заряджений";
|
||||
"Last charge" = "Остання зарядка";
|
||||
|
||||
// Fans
|
||||
"Fans" = "Fans";
|
||||
|
||||
@@ -211,6 +211,7 @@
|
||||
"Time and percentage" = "Thời gian và tỷ lệ phần trăm";
|
||||
"Time format" = "Định dạng thời gian";
|
||||
"Hide additional information when full" = "Ẩn thông tin bổ sung khi pin đầy";
|
||||
"Last charge" = "Lần sạc cuối cùng";
|
||||
|
||||
// Fans
|
||||
"Fans" = "Quạt";
|
||||
|
||||
@@ -211,6 +211,7 @@
|
||||
"Time and percentage" = "时间和百分比";
|
||||
"Time format" = "时间格式";
|
||||
"Hide additional information when full" = "电池充满后隐藏其他信息";
|
||||
"Last charge" = "最后一次收费";
|
||||
|
||||
// Fans
|
||||
"Fans" = "风扇";
|
||||
|
||||
@@ -211,6 +211,7 @@
|
||||
"Time and percentage" = "時間和百分比";
|
||||
"Time format" = "時間格式";
|
||||
"Hide additional information when full" = "電池充飽後隱藏其他資訊";
|
||||
"Last charge" = "最後一次收費";
|
||||
|
||||
// Fans
|
||||
"Fans" = "風扇";
|
||||
|
||||
Reference in New Issue
Block a user