Refactoring

This commit is contained in:
Leon Böttger committed 2025-07-27 12:21:40 +02:00
1 parent f4a21d3f0a
commit 9f2af19adb
1 file changed
+4 -9
+4 -9
View File
@@ -19,7 +19,7 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb
private var foundServices: [String: FoundServiceInfo] = [:] private var foundServices: [String: FoundServiceInfo] = [:]
private var shareExtensionDelegates: [ShareExtensionDelegate] = [] private var shareExtensionDelegates: [ShareExtensionDelegate] = []
private var outgoingTransfers: [String: OutgoingTransferInfo] = [:] private var outgoingTransfers: [String: OutgoingTransferInfo] = [:]
private var discoveryRefCount = 0 private var startedDeviceDiscovery = false
private var browsers: [NWBrowser] = [] private var browsers: [NWBrowser] = []
private let serviceTypes = ["_FC9F5ED42C8A._tcp."] private let serviceTypes = ["_FC9F5ED42C8A._tcp."]
@@ -129,9 +129,9 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb
public func startDeviceDiscovery() { public func startDeviceDiscovery() {
log("Device discovery requested.")
if discoveryRefCount == 0 { if !startedDeviceDiscovery {
startedDeviceDiscovery = true
foundServices.removeAll() foundServices.removeAll()
log("Starting device discovery") log("Starting device discovery")
@@ -158,16 +158,11 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb
} }
} }
} }
discoveryRefCount += 1
} }
public func stopDeviceDiscovery() { public func stopDeviceDiscovery() {
discoveryRefCount -= 1 if startedDeviceDiscovery {
assert(discoveryRefCount >= 0)
if discoveryRefCount == 0 {
for browser in browsers { for browser in browsers {
browser.cancel() browser.cancel()
} }