diff --git a/src/manager.rs b/src/manager.rs index 88f60da..d989e5e 100644 --- a/src/manager.rs +++ b/src/manager.rs @@ -21,8 +21,8 @@ use crate::power::{ use crate::process::{run_script, script_output}; use crate::systemd::SystemdUnit; use crate::wifi::{ - get_wifi_backend_from_conf, get_wifi_backend_from_script, set_wifi_backend, - set_wifi_debug_mode, WifiBackend, WifiDebugMode, WifiPowerManagement, + get_wifi_backend, set_wifi_backend, set_wifi_debug_mode, WifiBackend, WifiDebugMode, + WifiPowerManagement, }; use crate::{anyhow_to_zbus, anyhow_to_zbus_fdo}; @@ -62,7 +62,6 @@ impl fmt::Display for FanControl { pub struct SteamOSManager { connection: Connection, - wifi_backend: WifiBackend, wifi_debug_mode: WifiDebugMode, // Whether we should use trace-cmd or not. // True on galileo devices, false otherwise @@ -73,7 +72,6 @@ impl SteamOSManager { pub async fn new(connection: Connection) -> Result { Ok(SteamOSManager { connection, - wifi_backend: get_wifi_backend_from_conf().await?, wifi_debug_mode: WifiDebugMode::Off, should_trace: variant().await? == HardwareVariant::Galileo, }) @@ -309,7 +307,7 @@ impl SteamOSManager { // Set the wifi debug mode to mode, using an int for flexibility going forward but only // doing things on 0 or 1 for now // Return false on error - match get_wifi_backend_from_script().await { + match get_wifi_backend().await { Ok(WifiBackend::IWD) => (), Ok(backend) => { return Err(zbus::fdo::Error::Failed(format!( @@ -344,8 +342,11 @@ impl SteamOSManager { /// WifiBackend property. #[zbus(property)] - async fn wifi_backend(&self) -> u32 { - self.wifi_backend as u32 + async fn wifi_backend(&self) -> zbus::fdo::Result { + match get_wifi_backend().await { + Ok(backend) => Ok(backend as u32), + Err(e) => Err(anyhow_to_zbus_fdo(e)), + } } #[zbus(property)] @@ -359,16 +360,7 @@ impl SteamOSManager { Ok(backend) => backend, Err(e) => return Err(zbus::fdo::Error::InvalidArgs(e.to_string())), }; - match set_wifi_backend(backend).await { - Ok(()) => { - self.wifi_backend = backend; - Ok(()) - } - Err(e) => { - error!("Setting wifi backend failed: {e}"); - Err(anyhow_to_zbus_fdo(e)) - } - } + set_wifi_backend(backend).await.map_err(anyhow_to_zbus_fdo) } /// A version property. diff --git a/src/wifi.rs b/src/wifi.rs index 65035c6..801e0ec 100644 --- a/src/wifi.rs +++ b/src/wifi.rs @@ -13,7 +13,7 @@ use tracing::error; use zbus::Connection; use crate::path; -use crate::process::{run_script, script_output}; +use crate::process::run_script; use crate::systemd::{daemon_reload, SystemdUnit}; const OVERRIDE_CONTENTS: &str = "[Service] @@ -224,7 +224,7 @@ pub async fn set_wifi_debug_mode( Ok(()) } -pub async fn get_wifi_backend_from_conf() -> Result { +pub async fn get_wifi_backend() -> Result { let wifi_backend_contents = fs::read_to_string(path(WIFI_BACKEND_PATH)) .await? .trim() @@ -239,11 +239,6 @@ pub async fn get_wifi_backend_from_conf() -> Result { bail!("WiFi backend not found in config"); } -pub async fn get_wifi_backend_from_script() -> Result { - let result = script_output("/usr/bin/steamos-wifi-set-backend", &["--check"]).await?; - WifiBackend::from_str(result.trim()) -} - pub async fn set_wifi_backend(backend: WifiBackend) -> Result<()> { run_script( "set wifi backend",