diff --git a/cosmic-applet-bluetooth/src/bluetooth.rs b/cosmic-applet-bluetooth/src/bluetooth.rs index 9aef9880..7c7d4946 100644 --- a/cosmic-applet-bluetooth/src/bluetooth.rs +++ b/cosmic-applet-bluetooth/src/bluetooth.rs @@ -72,6 +72,14 @@ fn device_type_to_icon(device_type: &str) -> &'static str { } } +// In some distros, rfkill is only in sbin, which isn't normally in PATH +// TODO: Directly access `/dev/rfkill` +fn rfkill_path_var() -> std::ffi::OsString { + let mut path = std::env::var_os("PATH").unwrap_or_default(); + path.push(":/usr/sbin"); + path +} + #[inline] pub fn bluetooth_subscription( id: I, @@ -682,6 +690,7 @@ impl BluerSessionState { // rfkill will be persisted after reboot let name = adapter_clone.name(); if let Some(id) = tokio::process::Command::new("rfkill") + .env("PATH", rfkill_path_var()) .arg("list") .arg("-n") .arg("--output") @@ -698,6 +707,7 @@ impl BluerSessionState { }) { if let Err(err) = tokio::process::Command::new("rfkill") + .env("PATH", rfkill_path_var()) .arg(if *enabled { "unblock" } else { "block" }) .arg(id) .output() diff --git a/cosmic-applet-network/src/network_manager/mod.rs b/cosmic-applet-network/src/network_manager/mod.rs index e15b35a7..e3d18bd1 100644 --- a/cosmic-applet-network/src/network_manager/mod.rs +++ b/cosmic-applet-network/src/network_manager/mod.rs @@ -38,6 +38,14 @@ use self::{ current_networks::{active_connections, ActiveConnectionInfo}, }; +// In some distros, rfkill is only in sbin, which isn't normally in PATH +// TODO: Directly access `/dev/rfkill` +fn rfkill_path_var() -> std::ffi::OsString { + let mut path = std::env::var_os("PATH").unwrap_or_default(); + path.push(":/usr/sbin"); + path +} + #[derive(Debug)] pub enum State { Ready, @@ -154,6 +162,7 @@ async fn start_listening( // bluetooth success = success && Command::new("rfkill") + .env("PATH", rfkill_path_var()) .arg(if airplane_mode { "block" } else { "unblock" }) .arg("bluetooth") .output() @@ -402,6 +411,7 @@ impl NetworkManagerState { let mut self_ = Self::default(); // airplane mode let airplaine_mode = Command::new("rfkill") + .env("PATH", rfkill_path_var()) .arg("list") .arg("bluetooth") .output()