Skip to content

feat: implement macOS connectivity detection#11

Merged
jjhafer merged 6 commits into
silvermine:masterfrom
polw1:feat/macos-connectivity
Jun 22, 2026
Merged

feat: implement macOS connectivity detection#11
jjhafer merged 6 commits into
silvermine:masterfrom
polw1:feat/macos-connectivity

Conversation

@polw1

@polw1 polw1 commented May 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds macOS support for connection_status() using Apple’s Network framework.

  • implement the macOS backend with NWPathMonitor
  • map connectivity, metered, constrained, and transport status into the existing plugin types
  • treat only nw_path_status_satisfied as connected: true
  • document the macOS path-status semantics in code comments and README
  • add test coverage for macOS path-status handling and connection-type priority

Closes #8

Test plan

  • cargo check
  • cargo test --workspace --lib
  • npm run standards

@polw1

polw1 commented May 16, 2026

Copy link
Copy Markdown
Contributor Author

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.

Comment thread Cargo.toml Outdated
Comment thread src/platform/macos.rs
Comment thread src/platform/macos.rs
@polw1 polw1 requested a review from velocitysystems June 2, 2026 20:07

@velocitysystems velocitysystems left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

@polw1 polw1 requested a review from velocitysystems June 8, 2026 21:04
Comment thread src/lib.rs
Comment thread src/platform/macos.rs
Comment thread src/platform/macos.rs
Comment thread src/platform/macos.rs Outdated
Comment thread src/platform/macos.rs
@polw1 polw1 force-pushed the feat/macos-connectivity branch from 4ee2869 to 312e8e6 Compare June 12, 2026 09:32
@polw1 polw1 requested a review from jjhafer June 12, 2026 10:39
@velocitysystems

Copy link
Copy Markdown
Contributor

Hi @polw1. This PR can now be rebased again master.

@polw1 polw1 force-pushed the feat/macos-connectivity branch from 312e8e6 to f5aed24 Compare June 18, 2026 09:27
@polw1 polw1 requested a review from velocitysystems June 18, 2026 09:29

@velocitysystems velocitysystems left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @polw1. Did a final review but just found one thing we may want to fix.

Comment thread src/platform/macos.rs Outdated

/// 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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@polw1 polw1 requested a review from velocitysystems June 22, 2026 11:29
@jjhafer jjhafer merged commit 304abfc into silvermine:master Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement macOS support for connectivity detection

3 participants