mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-15 00:34:08 +09:00
fix: remove battery level from the popup view if not longer available (#1083)
This commit is contained in:
@@ -70,6 +70,8 @@ internal class BLEView: NSStackView {
|
||||
return CGSize(width: self.bounds.width, height: self.bounds.height)
|
||||
}
|
||||
|
||||
private var levels: [NSTextField] = []
|
||||
|
||||
public init(width: CGFloat, address: String, name: String, batteryLevel: [KeyValue_t]) {
|
||||
self.address = address
|
||||
|
||||
@@ -103,8 +105,13 @@ internal class BLEView: NSStackView {
|
||||
}
|
||||
|
||||
public func update(_ batteryLevel: [KeyValue_t]) {
|
||||
self.levels.filter{ v in !batteryLevel.contains(where: { $0.key == v.identifier?.rawValue }) }.forEach { (v: NSView) in
|
||||
v.removeFromSuperview()
|
||||
}
|
||||
self.levels = self.levels.filter{ v in batteryLevel.contains(where: { $0.key == v.identifier?.rawValue }) }
|
||||
|
||||
batteryLevel.forEach { (pair: KeyValue_t) in
|
||||
if let view = self.subviews.first(where: { $0.identifier?.rawValue == pair.key }) as? NSTextField {
|
||||
if let view = self.levels.first(where: { $0.identifier?.rawValue == pair.key }) {
|
||||
view.stringValue = "\(pair.value)%"
|
||||
} else {
|
||||
self.addLevel(pair)
|
||||
@@ -119,5 +126,6 @@ internal class BLEView: NSStackView {
|
||||
valueView.stringValue = "\(pair.value)%"
|
||||
valueView.toolTip = pair.key
|
||||
self.addArrangedSubview(valueView)
|
||||
self.levels.append(valueView)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user