mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-21 22:05:59 +00:00
Fix: Mac showed no connection when connected using Ethernet
This commit is contained in:
1 parent
6126d9428d
commit
b135229d30
1 file changed
+18
-13
@@ -45,11 +45,11 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb
|
|||||||
|
|
||||||
@Published var attachments: AttachmentDetails? = nil
|
@Published var attachments: AttachmentDetails? = nil
|
||||||
@Published var hasLocalNetworkAccess = true
|
@Published var hasLocalNetworkAccess = true
|
||||||
@Published var isConnectedViaWiFi = true
|
@Published var isConnectedToLocalNetwork = true
|
||||||
|
|
||||||
public var connectionUpdateCallback: (Bool) -> Void = { _ in } {
|
public var connectionUpdateCallback: (Bool) -> Void = { _ in } {
|
||||||
didSet {
|
didSet {
|
||||||
connectionUpdateCallback(isConnectedViaWiFi)
|
connectionUpdateCallback(isConnectedToLocalNetwork)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,18 +69,23 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb
|
|||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
hasConnectionMonitor.pathUpdateHandler = { path in
|
hasConnectionMonitor.pathUpdateHandler = { path in
|
||||||
if path.usesInterfaceType(.wifi) {
|
|
||||||
log("[NearbyConnectionManager] Connected via WiFi.")
|
#if os(macOS)
|
||||||
DispatchQueue.main.async {
|
// On Mac, the local network is available as long as the path is satisfied, since Macs do not have cellular modems
|
||||||
self.isConnectedViaWiFi = true
|
let isConnected = path.status == .satisfied
|
||||||
self.connectionUpdateCallback(true)
|
#else
|
||||||
}
|
// On iPhone and iPad, the local network is only available using Wi-Fi or Ethernet
|
||||||
} else {
|
let isConnected = path.usesInterfaceType(.wifi) || path.usesInterfaceType(.wiredEthernet)
|
||||||
log("[NearbyConnectionManager] WiFi connection lost.")
|
#endif
|
||||||
DispatchQueue.main.async {
|
|
||||||
self.isConnectedViaWiFi = false
|
DispatchQueue.main.async {
|
||||||
self.connectionUpdateCallback(false)
|
if isConnected {
|
||||||
|
log("[NearbyConnectionManager] Connected to local network.")
|
||||||
|
} else {
|
||||||
|
log("[NearbyConnectionManager] Local network lost.")
|
||||||
}
|
}
|
||||||
|
self.isConnectedToLocalNetwork = isConnected
|
||||||
|
self.connectionUpdateCallback(isConnected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user