feat: implement macOS connectivity detection#11
Conversation
|
Creating and destroying an NWPathMonitor on every call feels fragile, especially with a fixed timeout. Apple’s API delivers path updates through callbacks scheduled on a dispatch queue, so treating the first frontend request as a synchronous one-shot query felt like the wrong model. NWPathMonitor is better treated as a long-lived monitor than as a synchronous status getter. So i changed the implementation to create the monitor once, caches the latest status, and returns that cached value from plugin calls. I also start the monitor during plugin setup so the system has a chance to receive the first path update before the frontend makes its first real request, instead of making that request responsible for initializing the monitor. |
velocitysystems
left a comment
There was a problem hiding this comment.
@polw1 Changes look good. On further evaluation, since the monitor is stored in a static OneLock<T> the drop trait will never actually execute. It's probably best we remove the drop trait and add an inline comment noting the singleton is never cancelled.
4ee2869 to
312e8e6
Compare
|
Hi @polw1. This PR can now be rebased again |
312e8e6 to
f5aed24
Compare
velocitysystems
left a comment
There was a problem hiding this comment.
Thanks @polw1. Did a final review but just found one thing we may want to fix.
|
|
||
| /// Other interface types (loopback, `nw_interface_type_other`) intentionally | ||
| /// map to `Unknown`: the plugin only distinguishes transports callers can act on. | ||
| fn resolve_connection_type(wifi: bool, wired: bool, cellular: bool) -> ConnectionType { |
There was a problem hiding this comment.
The wifi > wired > cellular priority here is the plugin's own heuristic over independent nw_path_uses_interface_type probes, each of which only reports whether the path uses that interface at all.
But types.rs documents connection_type as "the preferred/primary transport as determined by the OS," and the Windows backend honors that by classifying the single preferred ConnectionProfile. On a docked laptop with both Wi-Fi and Ethernet active, both probes return true and this reports Wifi, even though macOS service-order typically routes over Ethernet — so the two platforms disagree on the same contract.
There was a problem hiding this comment.
Good catch. I missed that we have nw_path_enumerate_interfaces, whose docs say the interfaces are enumerated in order of preference.
I’ll use that instead.
Summary
Adds macOS support for
connection_status()using Apple’s Network framework.NWPathMonitornw_path_status_satisfiedasconnected: trueCloses #8
Test plan
cargo checkcargo test --workspace --libnpm run standards