feat: implement Linux support for connectivity detection (#5)#7
Conversation
1be0251 to
9723253
Compare
| status | ||
| } | ||
|
|
||
| fn map_connectivity(connectivity: u32) -> ConnectedState { |
There was a problem hiding this comment.
Should NM_CONNECTIVITY_PORTAL map to Connected with constrained: true, rather than Disconnected? I think this is similar to the question @jhafer raised in the other PR.
There was a problem hiding this comment.
Agreed, updated this to report portal connectivity as connected but constrained.
| path.as_str() == "/" | ||
| } | ||
|
|
||
| fn default_route_interface(route_table: &str) -> Option<String> { |
There was a problem hiding this comment.
/proc/net/route lists every candidate route, including down ones. Should we filter on routes which are reported as being up?
There was a problem hiding this comment.
Agreed. I updated the passive fallback to require the default route to have the RTF_UP flag before treating it as connected
| | `constrained` | `boolean` | Whether the connection is data-constrained or restricted | | ||
| | `connectionType` | `ConnectionType` | The physical transport: `wifi`, `ethernet`, `cellular`, `unknown` | | ||
|
|
||
| #### Platform mapping |
There was a problem hiding this comment.
Can we also please document the platform mapping for Linux?
| NM_CONNECTIVITY_NONE | NM_CONNECTIVITY_PORTAL | NM_CONNECTIVITY_LIMITED => { | ||
| ConnectedState::Disconnected | ||
| } | ||
| NM_CONNECTIVITY_UNKNOWN => ConnectedState::Unknown, |
There was a problem hiding this comment.
Nit: NM_CONNECTIVITY_UNKNOWN => Unknown and _ => Unknown are equivalent.
There was a problem hiding this comment.
Good catch. I simplified the match so unknown and unrecognized values both use the fallback arm.
10f4dcb to
c376dad
Compare
c376dad to
70b2703
Compare
70b2703 to
0737cff
Compare
| } | ||
|
|
||
| fn is_constrained(connectivity_state: ConnectedState, metered: bool, roaming: bool) -> bool { | ||
| connectivity_state == ConnectedState::Constrained || metered || roaming |
There was a problem hiding this comment.
On Linux, metered: true always forces constrained: true, whereas the Windows backend derives the two from separate signals. Could you confirm that's the desired behavior?
There was a problem hiding this comment.
Yes, this is intentional for Linux. NetworkManager does not expose a separate background-data policy signal, so we treat an explicitly or guessed metered primary device as constrained. I added a code comment to make that mapping explicit.
| .build() | ||
| } | ||
|
|
||
| fn service_has_owner(connection: &Connection, service: &str) -> std::result::Result<bool, String> { |
There was a problem hiding this comment.
This returns Result<bool, String>, while the rest of the module returns zbus::Result. Should this be updated?
There was a problem hiding this comment.
Agreed. I updated service_has_owner() to return zbus::Result<bool> and propagate the zbus/name errors directly.
| } | ||
|
|
||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| struct PrimaryConnectionDetails { |
There was a problem hiding this comment.
This is field-for-field identical to DeviceDetails. Can these be unified into a single type?
There was a problem hiding this comment.
I originally kept them separate because they represented different semantic levels: per-device details vs aggregated primary-connection details. Since the fields and behavior are identical, unifying them is cleaner. Updated to use a single ConnectionDetails type.
Linux needs a passive backend that works with NetworkManager when available. Smaller systems without NetworkManager should still get a predictable answer. Use cached NetworkManager properties for connectivity, metering, and transport. Fall back to the kernel route table and sysfs instead of active probes.
Update the Linux support matrix and API docs to describe how the backend maps NetworkManager connectivity, portal state, metering, transport, and constrained fallback behavior.
Manual Linux testing is easier when the example app emits plugin debug logs. Install a debug-friendly tracing subscriber in the example app. Refresh its lockfile for logging and the Linux backend dependency graph.
Document tested Linux scenarios, expected responses, and setup commands. Note that ModemManager cellular and roaming scenarios remain untested.
0737cff to
c245698
Compare
Adds Linux support for
connection_status()intauri-plugin-connectivity./proc/net/routeand sysfs when NetworkManager is unavailableCloses #5