Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion nmrs/src/api/network_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::core::connection_settings::{
};
use crate::core::device::{
is_connecting, list_bluetooth_devices, list_devices, set_wifi_enabled, wait_for_wifi_ready,
wifi_enabled,
wifi_enabled, wifi_hardware_enabled,
};
use crate::core::scan::{current_network, list_networks, scan_networks};
use crate::core::vpn::{connect_vpn, disconnect_vpn, get_vpn_info, list_vpn_connections};
Expand Down Expand Up @@ -424,6 +424,12 @@ impl NetworkManager {
set_wifi_enabled(&self.conn, value).await
}

/// Returns whether wireless hardware is currently enabled.
/// Reflects rfkill state which helps check if the radio is enabled or blocked.
pub async fn wifi_hardware_enabled(&self) -> Result<bool> {
wifi_hardware_enabled(&self.conn).await
}

/// Waits for a Wi-Fi device to become ready (disconnected or activated).
pub async fn wait_for_wifi_ready(&self) -> Result<()> {
wait_for_wifi_ready(&self.conn).await
Expand Down
6 changes: 6 additions & 0 deletions nmrs/src/core/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ pub(crate) async fn wifi_enabled(conn: &Connection) -> Result<bool> {
Ok(nm.wireless_enabled().await?)
}

/// Returns whether wireless hardware is enabled.
pub(crate) async fn wifi_hardware_enabled(conn: &Connection) -> Result<bool> {
let nm = NMProxy::new(conn).await?;
Ok(nm.wireless_hardware_enabled().await?)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
4 changes: 4 additions & 0 deletions nmrs/src/dbus/main_nm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ pub trait NM {
#[zbus(property)]
fn set_wireless_enabled(&self, value: bool) -> zbus::Result<()>;

/// Whether wireless hardware is enabled.
#[zbus(property)]
fn wireless_hardware_enabled(&self) -> zbus::Result<bool>;

/// Paths to all active connections.
#[zbus(property)]
fn active_connections(&self) -> zbus::Result<Vec<OwnedObjectPath>>;
Expand Down
17 changes: 17 additions & 0 deletions nmrs/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,23 @@ async fn test_wifi_enabled_get_set() {
);
}

#[tokio::test]
async fn test_wifi_hardware_enabled() {
require_networkmanager!();

let nm = NetworkManager::new()
.await
.expect("Failed to connect to NetworkManager");

require_wifi!(&nm);

// Read-only property — just verify the call succeeds
let _ = nm
.wifi_hardware_enabled()
.await
.expect("Failed to get WiFi hardware enabled state");
}

/// Test waiting for WiFi to be ready
#[tokio::test]
async fn test_wait_for_wifi_ready() {
Expand Down
Loading