mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 16:24:30 +09:00
fix: fixed race condition in the Bluetooth module (#591)
This commit is contained in:
@@ -29,6 +29,8 @@ identifier_name:
|
||||
- NetworkReaders
|
||||
- SensorsList
|
||||
- Alignments
|
||||
- _devices
|
||||
- _uuidAddress
|
||||
|
||||
line_length: 200
|
||||
|
||||
|
||||
@@ -15,13 +15,35 @@ import CoreBluetooth
|
||||
import IOBluetooth
|
||||
|
||||
internal class DevicesReader: Reader<[BLEDevice]>, CBCentralManagerDelegate, CBPeripheralDelegate {
|
||||
private var devices: [BLEDevice] = []
|
||||
|
||||
private let queue = DispatchQueue(label: "eu.exelban.Stats.Bluetooth.reader", attributes: .concurrent)
|
||||
private var manager: CBCentralManager!
|
||||
private var uuidAddress: [UUID: String] = [:]
|
||||
|
||||
private var _devices: [BLEDevice] = []
|
||||
private var _uuidAddress: [UUID: String] = [:]
|
||||
private var peripherals: [CBPeripheral] = []
|
||||
private var characteristicsDict: [UUID: CBCharacteristic] = [:]
|
||||
|
||||
private var devices: [BLEDevice] {
|
||||
get {
|
||||
self.queue.sync { self._devices }
|
||||
}
|
||||
set {
|
||||
self.queue.async(flags: .barrier) {
|
||||
self._devices = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
private var uuidAddress: [UUID: String] {
|
||||
get {
|
||||
self.queue.sync { self._uuidAddress }
|
||||
}
|
||||
set {
|
||||
self.queue.async(flags: .barrier) {
|
||||
self._uuidAddress = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private let batteryServiceUUID = CBUUID(string: "0x180F")
|
||||
private let batteryCharacteristicsUUID = CBUUID(string: "0x2A19")
|
||||
|
||||
@@ -89,7 +111,7 @@ internal class DevicesReader: Reader<[BLEDevice]>, CBCentralManagerDelegate, CBP
|
||||
return
|
||||
}
|
||||
|
||||
if let uuid = UUID(uuidString: key) {
|
||||
if let uuid = UUID(uuidString: key), self.uuidAddress[uuid] == nil {
|
||||
self.uuidAddress[uuid] = value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,6 +89,13 @@
|
||||
isEnabled = "NO">
|
||||
</EnvironmentVariable>
|
||||
</EnvironmentVariables>
|
||||
<AdditionalOptions>
|
||||
<AdditionalOption
|
||||
key = "NSZombieEnabled"
|
||||
value = "YES"
|
||||
isEnabled = "YES">
|
||||
</AdditionalOption>
|
||||
</AdditionalOptions>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Debug"
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>$(MARKETING_VERSION)</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>298</string>
|
||||
<string>299</string>
|
||||
<key>Description</key>
|
||||
<string>Simple macOS system monitor in your menu bar</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
|
||||
Reference in New Issue
Block a user