Skip to content

feat: implement Linux support for connectivity detection (#5)#7

Open
gabref wants to merge 4 commits into
silvermine:masterfrom
gabref:gabref/linux-connectivity-status
Open

feat: implement Linux support for connectivity detection (#5)#7
gabref wants to merge 4 commits into
silvermine:masterfrom
gabref:gabref/linux-connectivity-status

Conversation

@gabref
Copy link
Copy Markdown

@gabref gabref commented May 1, 2026

Adds Linux support for connection_status() in tauri-plugin-connectivity.

  • implement the Linux backend using NetworkManager D-Bus state
  • map connectivity, metered, constrained, and transport status into the existing plugin types
  • use ModemManager roaming and NetworkManager device metering for constrained status
  • add passive fallback detection via /proc/net/route and sysfs when NetworkManager is unavailable
  • keep Linux D-Bus and ModemManager failures non-fatal
  • update docs to reflect Linux support
  • add example app backend logging for manual Linux testing

Closes #5

@gabref gabref force-pushed the gabref/linux-connectivity-status branch from 1be0251 to 9723253 Compare May 5, 2026 09:00
Comment thread src/platform/linux.rs
status
}

fn map_connectivity(connectivity: u32) -> ConnectedState {
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.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Agreed, updated this to report portal connectivity as connected but constrained.

Comment thread src/platform/linux.rs
path.as_str() == "/"
}

fn default_route_interface(route_table: &str) -> Option<String> {
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.

/proc/net/route lists every candidate route, including down ones. Should we filter on routes which are reported as being up?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Agreed. I updated the passive fallback to require the default route to have the RTF_UP flag before treating it as connected

Comment thread README.md
| `constrained` | `boolean` | Whether the connection is data-constrained or restricted |
| `connectionType` | `ConnectionType` | The physical transport: `wifi`, `ethernet`, `cellular`, `unknown` |

#### Platform mapping
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.

Can we also please document the platform mapping for Linux?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added the Linux mapping

Comment thread src/platform/linux.rs Outdated
NM_CONNECTIVITY_NONE | NM_CONNECTIVITY_PORTAL | NM_CONNECTIVITY_LIMITED => {
ConnectedState::Disconnected
}
NM_CONNECTIVITY_UNKNOWN => ConnectedState::Unknown,
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.

Nit: NM_CONNECTIVITY_UNKNOWN => Unknown and _ => Unknown are equivalent.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch. I simplified the match so unknown and unrecognized values both use the fallback arm.

@gabref gabref force-pushed the gabref/linux-connectivity-status branch 2 times, most recently from 10f4dcb to c376dad Compare May 11, 2026 23:46
@gabref gabref marked this pull request as ready for review May 11, 2026 23:47
@gabref gabref force-pushed the gabref/linux-connectivity-status branch from c376dad to 70b2703 Compare May 11, 2026 23:49
@gabref gabref force-pushed the gabref/linux-connectivity-status branch from 70b2703 to 0737cff Compare June 2, 2026 09:18
Comment thread src/platform/linux.rs
}

fn is_constrained(connectivity_state: ConnectedState, metered: bool, roaming: bool) -> bool {
connectivity_state == ConnectedState::Constrained || metered || roaming
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.

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?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

Comment thread src/platform/linux.rs Outdated
.build()
}

fn service_has_owner(connection: &Connection, service: &str) -> std::result::Result<bool, String> {
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.

This returns Result<bool, String>, while the rest of the module returns zbus::Result. Should this be updated?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Agreed. I updated service_has_owner() to return zbus::Result<bool> and propagate the zbus/name errors directly.

Comment thread src/platform/linux.rs Outdated
}

#[derive(Debug, Clone, PartialEq, Eq)]
struct PrimaryConnectionDetails {
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.

This is field-for-field identical to DeviceDetails. Can these be unified into a single type?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

gabu added 4 commits June 2, 2026 17:16
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.
@gabref gabref force-pushed the gabref/linux-connectivity-status branch from 0737cff to c245698 Compare June 2, 2026 15:16
@gabref gabref requested a review from velocitysystems June 2, 2026 15:17
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 Linux support for connectivity detection

2 participants