diff --git a/src/manager.rs b/src/manager.rs index fd1566a..d0ae714 100644 --- a/src/manager.rs +++ b/src/manager.rs @@ -24,7 +24,7 @@ */ use std::ffi::OsStr; -use subprocess::{ExitStatus::Exited, Popen, PopenConfig, PopenError}; +use subprocess::{ExitStatus::Exited, Popen, PopenConfig, PopenError, Redirection}; use zbus_macros::dbus_interface; pub struct SMManager { } @@ -45,6 +45,20 @@ fn run_script(name: &str, argv: &[impl AsRef]) -> bool { } } +fn script_output(argv: &[impl AsRef]) -> Result { + // Run given command and return the output given + let mut process = Popen::create(argv, PopenConfig { + stdout: Redirection::Pipe, + ..Default::default() + })?; + let (output, _err) = process.communicate(None)?; + let _exit_status = process.wait()?; + match output { + Some(output_strings) => Ok(output_strings), + None => Err(PopenError::LogicError("Error getting output")) + } +} + #[dbus_interface(name = "com.steampowered.SteamOSManager1")] impl SMManager { const API_VERSION: u32 = 1; @@ -79,6 +93,18 @@ impl SMManager { run_script("check hardware support", &["jupiter-check-support"]) } + async fn read_als_calibration(&self) -> f32 { + // Run script to get calibration value + let result = script_output(&["/usr/bin/steamos-polkit-helpers/jupiter-get-als-gain"]); + let mut value: f32 = -1.0; + match result { + Ok(as_string) => value = as_string.trim().parse().unwrap(), + Err(message) => println!("Unable to run als calibration script : {}", message), + } + + value + } + /// A version property. #[dbus_interface(property)] async fn version(&self) -> u32 {