Skip to content

Commit

Permalink
Implemented battery time left display from gao-sun#174 (gao-sun#176)
Browse files Browse the repository at this point in the history
* Implemented battery time left display from gao-sun#174

* Fix project.pbxproj accidental removal

* Change battery timeRemaining name

* Apply suggestions from code review

Co-authored-by: gao-sun <[email protected]>
  • Loading branch information
jevonmao and gao-sun authored Feb 4, 2021
1 parent b0a38fb commit cf521a0
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Resource/ar.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// MARK: Battery
"battery" = "البطارية";
"battery.charge" = "شحن البطارية";
"battery.timeRemaining" = "Time Rem.";
"battery.power_source" = "Power Source";
"battery.power_source.battery" = "مصدر الطاقة";
"battery.power_source.acPower" = "تيار مستمر";
Expand Down Expand Up @@ -182,6 +183,7 @@
"text_component.loadAverage5Min" = "Load Average (5 min)";
"text_component.loadAverage15Min" = "Load Average (15 min)";
"text_component.average" = "Average";
"text_component.timeRemaining" = "Time Remaining";

// MARK: CPU Display Mode
"cpu_display_mode" = "CPU Display Mode";
Expand Down
2 changes: 2 additions & 0 deletions Resource/cs.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// MARK: Battery
"battery" = "Baterie";
"battery.charge" = "Nabito";
"battery.timeRemaining" = "Time Rem.";
"battery.power_source" = "Zdroj Energie";
"battery.power_source.battery" = "Baterie";
"battery.power_source.acPower" = "Nápájen ze Sítě";
Expand Down Expand Up @@ -179,6 +180,7 @@
"text_component.loadAverage5Min" = "Průměrné zatížení (5 min)";
"text_component.loadAverage15Min" = "Průměrné zatížení (15 min)";
"text_component.average" = "Průměr";
"text_component.timeRemaining" = "Time Remaining";

// MARK: CPU Display Mode
"cpu_display_mode" = "Režim zobrazení CPU ";
Expand Down
2 changes: 2 additions & 0 deletions Resource/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// MARK: Battery
"battery" = "Batterie";
"battery.charge" = "Laden";
"battery.timeRemaining" = "Time Rem.";
"battery.power_source" = "Stromquelle";
"battery.power_source.battery" = "Batterie";
"battery.power_source.acPower" = "Netzteil";
Expand Down Expand Up @@ -181,6 +182,7 @@
"text_component.loadAverage5Min" = "⌀-Auslastung (5 Min.)";
"text_component.loadAverage15Min" = "⌀-Auslastung (15 Min.)";
"text_component.average" = "Durchschnitt";
"text_component.timeRemaining" = "Time Remaining";

// MARK: CPU Display Mode
"cpu_display_mode" = "CPU Display Mode:";
Expand Down
2 changes: 2 additions & 0 deletions Resource/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// MARK: Battery
"battery" = "Battery";
"battery.charge" = "Charge";
"battery.timeRemaining" = "Time Rem.";
"battery.power_source" = "Power Source";
"battery.power_source.battery" = "Battery";
"battery.power_source.acPower" = "AC Power";
Expand Down Expand Up @@ -182,6 +183,7 @@
"text_component.loadAverage5Min" = "Load Average (5 min)";
"text_component.loadAverage15Min" = "Load Average (15 min)";
"text_component.average" = "Average";
"text_component.timeRemaining" = "Time Remaining";

// MARK: CPU Display Mode
"cpu_display_mode" = "CPU Display Mode";
Expand Down
2 changes: 2 additions & 0 deletions Resource/es.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// MARK: Battery
"battery" = "Batería";
"battery.charge" = "Carga";
"battery.timeRemaining" = "Time Rem.";
"battery.power_source" = "Alimentación";
"battery.power_source.battery" = "Batería";
"battery.power_source.acPower" = "Alimentación CA";
Expand Down Expand Up @@ -181,6 +182,7 @@
"text_component.loadAverage5Min" = "Load Average (5 min)";
"text_component.loadAverage15Min" = "Load Average (15 min)";
"text_component.average" = "Average";
"text_component.timeRemaining" = "Time Remaining";

// MARK: CPU Display Mode
"cpu_display_mode" = "CPU Display Mode";
Expand Down
2 changes: 2 additions & 0 deletions Resource/fr.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// MARK: Battery
"battery" = "Batterie";
"battery.charge" = "Charge";
"battery.timeRemaining" = "Time Rem.";
"battery.power_source" = "Source d'alimentation";
"battery.power_source.battery" = "Batterie";
"battery.power_source.acPower" = "Adaptateur secteur";
Expand Down Expand Up @@ -181,6 +182,7 @@
"text_component.loadAverage5Min" = "Charge moyenne (5 min)";
"text_component.loadAverage15Min" = "Charge moyenne (15 min)";
"text_component.average" = "Moyenne";
"text_component.timeRemaining" = "Time Remaining";

// MARK: CPU Display Mode
"cpu_display_mode" = "Mode d'affichage du CPU";
Expand Down
2 changes: 2 additions & 0 deletions Resource/ja.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// MARK: Battery
"battery" = "バッテリー";
"battery.charge" = "充電";
"battery.timeRemaining" = "Time Rem.";
"battery.power_source" = "電源";
"battery.power_source.battery" = "バッテリー";
"battery.power_source.acPower" = "電源アダプタ";
Expand Down Expand Up @@ -181,6 +182,7 @@
"text_component.loadAverage5Min" = "Load Average (5 min)";
"text_component.loadAverage15Min" = "Load Average (15 min)";
"text_component.average" = "Average";
"text_component.timeRemaining" = "Time Remaining";

// MARK: CPU Display Mode
"cpu_display_mode" = "CPU Display Mode";
Expand Down
2 changes: 2 additions & 0 deletions Resource/ko.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// MARK: Battery
"battery" = "배터리 사용중";
"battery.charge" = "충전중";
battery.timeRemaining = "Time Rem.";
"battery.power_source" = "전원 공급원";
"battery.power_source.battery" = "배터리";
"battery.power_source.acPower" = "전원 어댑터";
Expand Down Expand Up @@ -184,6 +185,7 @@
"text_component.loadAverage5Min" = "부하 평균 (5 분)";
"text_component.loadAverage15Min" = "부하 평균 (15 분)";
"text_component.average" = "평균";
"text_component.timeRemaining" = "Time Remaining";

// MARK: CPU Display Mode
"cpu_display_mode" = "CPU 보기 모드";
Expand Down
2 changes: 2 additions & 0 deletions Resource/mn.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// MARK: Battery
"battery" = "Батaрей";
"battery.charge" = "Цэнэг";
"battery.timeRemaining" = "Time Rem.";
"battery.power_source" = "Эх үүсвэр";
"battery.power_source.battery" = "Батарей";
"battery.power_source.acPower" = "Цэнэглэгч";
Expand Down Expand Up @@ -182,6 +183,7 @@
"text_component.loadAverage5Min" = "Load Average (5 min)";
"text_component.loadAverage15Min" = "Load Average (15 min)";
"text_component.average" = "Average";
"text_component.timeRemaining" = "Time Remaining";

// MARK: CPU Display Mode
"cpu_display_mode" = "CPU Display Mode";
Expand Down
2 changes: 2 additions & 0 deletions Resource/pt.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// MARK: Battery
"battery" = "Bateria";
"battery.charge" = "Carga";
"battery.timeRemaining" = "Time Rem.";
"battery.power_source" = "Fonte de Alimentação";
"battery.power_source.battery" = "Bateria";
"battery.power_source.acPower" = "Fonte AC";
Expand Down Expand Up @@ -181,6 +182,7 @@
"text_component.loadAverage5Min" = "Load Average (5 min)";
"text_component.loadAverage15Min" = "Load Average (15 min)";
"text_component.average" = "Average";
"text_component.timeRemaining" = "Time Remaining";

// MARK: CPU Display Mode
"cpu_display_mode" = "CPU Display Mode";
Expand Down
2 changes: 2 additions & 0 deletions Resource/ru.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// MARK: Battery
"battery" = "Батарея";
"battery.charge" = "Заряд";
"battery.timeRemaining" = "Time Rem.";
"battery.power_source" = "Источник питания";
"battery.power_source.battery" = "Батарея";
"battery.power_source.acPower" = "Сетевой Адаптер";
Expand Down Expand Up @@ -181,6 +182,7 @@
"text_component.loadAverage5Min" = "Load Average (5 min)";
"text_component.loadAverage15Min" = "Load Average (15 min)";
"text_component.average" = "Average";
"text_component.timeRemaining" = "Time Remaining";

// MARK: CPU Display Mode
"cpu_display_mode" = "CPU Display Mode";
Expand Down
2 changes: 2 additions & 0 deletions Resource/uk.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// MARK: Battery
"battery" = "Акумулятор";
"battery.charge" = "Заряд";
"battery.timeRemaining" = "Time Rem.";
"battery.power_source" = "Джерело живлення";
"battery.power_source.battery" = "Акумулятор";
"battery.power_source.acPower" = "Електромережа";
Expand Down Expand Up @@ -181,6 +182,7 @@
"text_component.loadAverage5Min" = "Середнє навантаження (5 хв)";
"text_component.loadAverage15Min" = "Середнє навантаження (15 хв)";
"text_component.average" = "Середнє";
"text_component.timeRemaining" = "Time Remaining";

// MARK: CPU Display Mode
"cpu_display_mode" = "Режим відображення ЦП";
Expand Down
3 changes: 3 additions & 0 deletions Resource/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// MARK: Battery
"battery" = "电池";
"battery.charge" = "电量";
"battery.timeRemaining" = "剩余时间";
"battery.power_source" = "电源";
"battery.power_source.battery" = "电池";
"battery.power_source.acPower" = "电源适配器";
Expand Down Expand Up @@ -181,6 +182,8 @@
"text_component.loadAverage5Min" = "平均负载 (5分钟)";
"text_component.loadAverage15Min" = "平均负载 (15分钟)";
"text_component.average" = "平均";
"text_component.timeRemaining" = "剩余时间";


// MARK: CPU Display Mode
"cpu_display_mode" = "CPU 显示";
Expand Down
1 change: 1 addition & 0 deletions eul/Schema/TextComponents/BatteryTextComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import SwiftyJSON
enum BatteryTextComponent: String, CaseIterable, JSONCodabble, LocalizedTextComponent {
case percentage
case mah
case timeRemaining

static var defaultComponents: [Self] {
[.percentage]
Expand Down
2 changes: 2 additions & 0 deletions eul/Store/BatteryStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class BatteryStore: ObservableObject, Refreshable {
@Published var maxCapacity = 0
@Published var designCapacity = 0
@Published var cycleCount = 0
@Published var timeRemaining = ""

var charge: Double {
io.currentCharge
Expand All @@ -51,6 +52,7 @@ class BatteryStore: ObservableObject, Refreshable {
maxCapacity = battery.maxCapactiy()
designCapacity = battery.designCapacity()
cycleCount = battery.cycleCount()
timeRemaining = battery.timeRemainingFormatted()
_ = battery.close()
writeToContainer()
}
Expand Down
2 changes: 2 additions & 0 deletions eul/Views/Menu/BatteryMenuBlockView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ struct BatteryMenuBlockView: View {
MiniSectionView(title: "battery.cycle_count".localized(), value: batteryStore.cycleCount.description)
Spacer()
MiniSectionView(title: "battery.condition".localized(), value: io.condition.description)
Spacer()
MiniSectionView(title: "battery.timeRemaining".localized(), value: batteryStore.timeRemaining)
}
}
.menuBlock()
Expand Down
2 changes: 2 additions & 0 deletions eul/Views/StatusBar/BatteryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ struct BatteryView: View {
return batteryStore.charge.percentageString
case .mah:
return "\(batteryStore.capacity) mAh"
case .timeRemaining:
return batteryStore.timeRemaining
}
}
}
Expand Down

0 comments on commit cf521a0

Please sign in to comment.