fix(bluetooth): 排除内置电池电源项
This commit is contained in:
1 parent
f5ba9f88be
commit
fae841dae5
2 files changed
+4
-2
No files matched your search
@@ -117,10 +117,11 @@ public enum BluetoothBatteryReader {
|
||||
}
|
||||
|
||||
/// `pmset -g accps` 能补充部分 system_profiler / IORegistry 看不到的耳机和第三方 HID 电量。
|
||||
/// 无名称的电源项由 IORegistry 提供产品名,这里跳过以免显示成匿名设备。
|
||||
/// accps 也列出 Mac 内置电池;无名称的电源项由 IORegistry 提供产品名,这里都不作为附件展示。
|
||||
static func parsePMSet(_ output: String) -> [BluetoothDevice] {
|
||||
output.split(whereSeparator: \.isNewline).compactMap { rawLine in
|
||||
guard let source = parsePowerSourceLine(rawLine), !source.name.isEmpty else { return nil }
|
||||
guard let source = parsePowerSourceLine(rawLine), !source.name.isEmpty,
|
||||
source.name != "InternalBattery", !source.name.hasPrefix("InternalBattery-") else { return nil }
|
||||
return BluetoothDevice(name: source.name, address: "", kind: kind(forName: source.name, minorType: nil),
|
||||
batteries: [(tr("电量"), source.percent)], isCharging: source.isCharging)
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@ import Testing
|
||||
@Test func parsesNamedAccessoryPowerSources() {
|
||||
let output = """
|
||||
Now drawing from 'AC Power'
|
||||
-InternalBattery-0 (id=23134307)\t80%; AC attached; not charging present: true
|
||||
-Magic Keyboard (id=1234)\t98%; discharging present: true
|
||||
-大唐西域进贡上等白玉耳坠 (id=5678)\t76%; charging present: true
|
||||
- (id=9999)\t24%; discharging present: true
|
||||
|
||||
Reference in new issue
Block a user