Cross-platform network connectivity detection for Tauri 2.x apps.
This plugin provides a unified API for querying network connection status, including connection type (WiFi, Ethernet, Cellular), metered/constrained flags, and reachability. It is designed to help apps make network policy decisions.
- Detect connection type (WiFi, Ethernet, Cellular)
- Query platform-reported transport classes for policy settings
- Query metered and constrained status for network policy decisions
- Check internet reachability
- Cross-platform support (Windows, Linux, macOS, iOS, Android)
| Platform | Supported |
|---|---|
| Windows | Yes |
| Linux | Yes |
| macOS | Yes |
| Android | Yes |
| iOS | Yes |
-
Install NPM dependencies:
npm install
-
Build the TypeScript bindings:
npm run build
-
Build the Rust plugin:
cargo build
Run all tests (TypeScript and Rust):
npm testRun TypeScript tests only:
npm run test:tsRun Rust tests only:
cargo test --workspace --libSee Linux Connectivity Manual Testing for WSL2, VirtualBox, NetworkManager, ModemManager, metered, constrained, and transport-type test scenarios.
See macOS Connectivity Manual Testing for current-path transport inventory, disconnected, VPN, metered, and constrained scenarios.
This plugin requires a Rust version of at least 1.94.0
Add the plugin to your Cargo.toml:
src-tauri/Cargo.toml
[dependencies]
tauri-plugin-connectivity = { git = "https://github.com/silvermine/tauri-plugin-connectivity" }Install the JavaScript bindings:
npm install @silvermine/tauri-plugin-connectivityInitialize the plugin in your tauri::Builder:
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_connectivity::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}import { connectionStatus } from '@silvermine/tauri-plugin-connectivity';
async function checkConnection() {
const status = await connectionStatus();
console.debug(`Connected: ${status.connected}`);
console.debug(`Type: ${status.connectionType}`);
console.debug(`Metered: ${status.metered}`);
console.debug(`Constrained: ${status.constrained}`);
}Use the connection status to defer expensive operations on constrained or metered connections:
import { connectionStatus } from '@silvermine/tauri-plugin-connectivity';
async function shouldDownload(): Promise<boolean> {
const status = await connectionStatus();
if (!status.connected) {
console.debug('No internet connection');
return false;
}
if (status.metered || status.constrained) {
console.debug('Metered or constrained connection — deferring download');
return false;
}
return true;
}Use supportedConnectionTypes() when the app needs to show policy settings for
transport classes reported by the current platform backend. On Android,
transports declared as PackageManager system features are reported even when
inactive; other transports are reported only while currently active:
import { supportedConnectionTypes } from '@silvermine/tauri-plugin-connectivity';
async function showPolicyOptions() {
const supportedTypes = await supportedConnectionTypes();
console.debug(`Supported transports: ${supportedTypes.join(', ')}`);
}Access the connectivity API from any Tauri manager type via the extension trait:
use tauri_plugin_connectivity::ConnectivityExt;
fn check_connection<R: tauri::Runtime>(app: &tauri::AppHandle<R>) {
match app.connectivity().connection_status() {
Ok(status) => {
println!("Connected: {}", status.connected);
println!("Type: {:?}", status.connection_type);
}
Err(e) => eprintln!("Could not detect connection status: {e}"),
}
}The connectionStatus() function returns a ConnectionStatus object:
| Field | Type | Description |
|---|---|---|
connected |
boolean |
Whether the device has an active network path |
metered |
boolean |
Whether data usage is billed or limited |
constrained |
boolean |
Whether the connection is data-constrained or restricted |
connectionType |
ConnectionType |
The physical transport: wifi, ethernet, cellular, unknown |
The supportedConnectionTypes() function returns ConnectionType[]. The array
is deduplicated and excludes unknown. Its availability semantics are
platform-specific, as described below. An empty array means detection succeeded
but found no supported transports. Detection failures reject the promise when
no supported transport can be recovered; when at least one transport is
recovered, the array can be a best-effort partial inventory if another
interface cannot be inspected.
| Platform | Mapping |
|---|---|
| Windows | Present hardware-backed adapters from Win32 GetAdaptersAddresses() and GetIfEntry2() mapped by IANA interface type |
| Linux | NetworkManager realized Devices mapped by DeviceType; sysfs fallback when NetworkManager is unavailable |
| macOS | Interfaces of the current satisfied NWPath mapped by nw_interface_get_type() |
| iOS | Interfaces of the current satisfied NWPath.availableInterfaces mapped by NWInterface.InterfaceType |
| Android | PackageManager hardware features plus current ConnectivityManager networks |
Android does not expose a complete public SDK inventory of inactive removable
network adapters. Transports that are not declared as PackageManager system
features are reported only while Android exposes them as currently active
through ConnectivityManager.
On macOS and iOS, the array reflects the interfaces of the current network
path reported by NWPathMonitor, so inactive transports are not listed.
| Field | Windows | Linux | macOS | iOS | Android |
|---|---|---|---|---|---|
connected |
InternetAccess or ConstrainedInternetAccess |
NetworkManager FULL/PORTAL/LIMITED or up IPv4/IPv6 default route fallback |
nw_path_get_status == satisfied |
NWPath.status satisfied |
NET_CAPABILITY_INTERNET |
metered |
NetworkCostType Unknown/Fixed/Variable |
NetworkManager primary device Metered |
nw_path_is_expensive |
NWPath.isExpensive |
absence of NOT_METERED |
constrained |
ConstrainedInternetAccess, data-limit, roaming, or background data restrictions |
NetworkManager portal/limited/metered or cellular roaming; fallback defaults to false |
nw_path_is_constrained |
NWPath.isConstrained |
missing VALIDATED, or Data Saver / RESTRICT_BACKGROUND on a metered active network |
connectionType |
WWAN/WLAN/IANA interface type | NetworkManager device type or sysfs fallback | First nw_path_enumerate_interfaces entry |
NWPath.usesInterfaceType(_:) priority |
TRANSPORT_* capabilities |
This project follows the Silvermine standardization guidelines. Key standards include:
- EditorConfig: Consistent editor settings across the team
- Markdownlint: Markdown linting for documentation
- Commitlint: Conventional commit message format
- Code Style: 3-space indentation, LF line endings
npm run standardsMIT
Contributions are welcome! Please follow the established coding standards and commit message conventions.