Skip to content

Commit 19dba58

Browse files
committed
release 0.0.4
1 parent 5a63d65 commit 19dba58

4 files changed

Lines changed: 40 additions & 17 deletions

File tree

Package.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ let package = Package(
2424
// Targets are the basic building blocks of a package, defining a module or a test suite.
2525
// Targets can depend on other targets in this package and products from dependencies.
2626
.target(
27-
name: "NetworkPathMonitor"),
27+
name: "NetworkPathMonitor",
28+
linkerSettings: [
29+
.linkedFramework("Network"),
30+
]
31+
),
2832
.testTarget(
2933
name: "NetworkPathMonitorTests",
3034
dependencies: ["NetworkPathMonitor"]
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.9
1+
// swift-tools-version: 5.10
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
@@ -24,7 +24,11 @@ let package = Package(
2424
// Targets are the basic building blocks of a package, defining a module or a test suite.
2525
// Targets can depend on other targets in this package and products from dependencies.
2626
.target(
27-
name: "NetworkPathMonitor"),
27+
name: "NetworkPathMonitor",
28+
linkerSettings: [
29+
.linkedFramework("Network"),
30+
]
31+
),
2832
.testTarget(
2933
name: "NetworkPathMonitorTests",
3034
dependencies: ["NetworkPathMonitor"]

Sources/NetworkPathMonitor/Extensions.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ public extension Network.NWPath {
3333
@unknown default: return "unknown reason"
3434
}
3535
}
36+
37+
/// Network interfaces used by this path
38+
var usedInterfaces: [NWInterface] {
39+
availableInterfaces.filter { usesInterfaceType($0.type) }
40+
}
41+
42+
/// Physical network interfaces used by this path, excluding virtual interfaces
43+
var usedPhysicalInterfaces: [NWInterface] {
44+
usedInterfaces.filter {
45+
switch $0.type {
46+
case .wifi, .cellular, .wiredEthernet: return true
47+
default: return false
48+
}
49+
}
50+
}
3651
}
3752

3853
public extension Network.NWInterface.InterfaceType {

Sources/NetworkPathMonitor/NetworkPathMonitor.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
import Foundation
99

1010
// Enforce minimum Swift version for all platforms and build systems.
11-
#if swift(<5.9)
12-
#error("NetworkPathMonitor doesn't support Swift versions below 5.9")
11+
#if swift(<5.10)
12+
#error("NetworkPathMonitor doesn't support Swift versions below 5.10")
1313
#endif
1414

1515
import Network
1616

1717
public enum NetworkPathMonitorInfo: Sendable {
1818
/// Current NetworkPathMonitor version.
19-
public static let version = "0.0.3"
19+
public static let version = "0.0.4"
2020
}
2121

2222
/// A class that monitors network path changes using `NWPathMonitor`.
@@ -56,7 +56,7 @@ public actor NetworkPathMonitor {
5656
currentPath = networkMonitor.currentPath
5757
self.debounceInterval = debounceInterval
5858
networkMonitor.pathUpdateHandler = { [weak self] path in
59-
guard let self = self else { return }
59+
guard let self else { return }
6060
Task { await self.handlePathUpdate(path) }
6161
}
6262
}
@@ -92,16 +92,14 @@ public actor NetworkPathMonitor {
9292

9393
private func handlePathUpdate(_ path: NWPath) async {
9494
currentPath = path
95+
debounceTask?.cancel()
9596
guard debounceInterval > 0 else {
9697
// No debounce, yield immediately
97-
// Cancel any potentially lingering debounce task if debounceInterval was changed dynamically (though not the case here)
98-
debounceTask?.cancel()
9998
debounceTask = nil
10099
await yieldNetworkPath(path)
101100
return
102101
}
103102
// Debounce is active
104-
debounceTask?.cancel()
105103
debounceTask = Task {
106104
do {
107105
try await Task.sleep(nanoseconds: UInt64(self.debounceInterval * 1_000_000_000))
@@ -123,13 +121,15 @@ public actor NetworkPathMonitor {
123121
Task { await self.networkPathUpdater?(path) }
124122

125123
// Post network status change notification
126-
NotificationCenter.default.post(
127-
name: Self.networkStatusDidChangeNotification,
128-
object: self,
129-
userInfo: [
130-
"newPath": path,
131-
]
132-
)
124+
Task {
125+
NotificationCenter.default.post(
126+
name: Self.networkStatusDidChangeNotification,
127+
object: self,
128+
userInfo: [
129+
"newPath": path,
130+
]
131+
)
132+
}
133133
}
134134
}
135135

0 commit comments

Comments
 (0)