Skip to content

Commit

Permalink
batteryの最適化
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyome22 committed Mar 17, 2024
1 parent bf821c3 commit cb90348
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
17 changes: 12 additions & 5 deletions Sources/SystemInfoKit/Entity/BatteryInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ public struct BatteryInfo: SystemInfo {
public let type: SystemInfoType = .battery
public internal(set) var value: Double = .zero
public let installed: Bool
private(set) var isCharging: Bool = false
private var powerSourceValue: String
public internal(set) var isCharging: Bool = false
private var adapterName: String?
private var healthValue: Double = .zero
private var maxCapacityValue: Double = .zero
private var cycleValue: Int = .zero
Expand Down Expand Up @@ -35,6 +35,14 @@ public struct BatteryInfo: SystemInfo {
}
}

private var powerSourceValue: String {
if isCharging {
return adapterName ?? String(localized: "batteryUnknown", bundle: .module)
} else {
return String(localized: "battery", bundle: .module)
}
}

private var healthOrMaxCapacity: String {
#if arch(x86_64) // Intel chip
return String(localized: "batteryHealth\(healthValue)", bundle: .module)
Expand All @@ -54,15 +62,14 @@ public struct BatteryInfo: SystemInfo {

init(installed: Bool = false) {
self.installed = installed
self.powerSourceValue = String(localized: "batteryUnknown", bundle: .module)
}

mutating func setIsCharging(_ value: Bool) {
self.isCharging = value
}

mutating func setPowerSource(_ value: String) {
self.powerSourceValue = value
mutating func setAdapterName(_ value: String) {
self.adapterName = value
}

mutating func setHealthValue(_ value: Double) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SystemInfoKit/Repository/BatteryRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ final class BatteryRepositoryImpl: BatteryRepository {
}
if let adapter = dict["AdapterDetails"] as? [String: AnyObject],
let name = adapter["Name"] as? String {
result.setPowerSource(name)
result.setAdapterName(name)
}
if let cycleCount = dict["CycleCount"] as? Int {
result.setCycleValue(cycleCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"memoryCompressed%lf" = "Compressed: %4.1f GB";

// Battery
"battery" = "Battery";
"battery%lf" = "Battery: %5.1f%%";
"batteryIsNotInstalled" = "Battery: not installed";
"batteryHealth%lf" = "Health: %5.1f%%";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"memoryCompressed%lf" = "圧縮: %4.1f GB";

// Battery
"battery" = "バッテリー";
"battery%lf" = "バッテリー: %5.1f%%";
"batteryIsNotInstalled" = "バッテリー: 非搭載";
"batteryHealth%lf" = "ヘルス: %5.1f%%";
Expand Down

0 comments on commit cb90348

Please sign in to comment.