Run cargo fmt

This commit is contained in:
Vicki Pfau 2024-03-19 16:04:07 -07:00
parent 5afe7222ca
commit 7217b0c2b1

View file

@ -23,7 +23,7 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
use std::{ fs, ffi::OsStr, fmt }; use std::{ffi::OsStr, fmt, fs};
use tokio::{fs::File, io::AsyncWriteExt, process::Command}; use tokio::{fs::File, io::AsyncWriteExt, process::Command};
use zbus::{interface, zvariant::Fd}; use zbus::{interface, zvariant::Fd};
@ -36,16 +36,13 @@ enum WifiDebugMode {
impl TryFrom<u32> for WifiDebugMode { impl TryFrom<u32> for WifiDebugMode {
type Error = &'static str; type Error = &'static str;
fn try_from(v: u32) -> Result<Self, Self::Error> fn try_from(v: u32) -> Result<Self, Self::Error> {
{
match v { match v {
x if x == WifiDebugMode::Off as u32 => Ok(WifiDebugMode::Off), x if x == WifiDebugMode::Off as u32 => Ok(WifiDebugMode::Off),
x if x == WifiDebugMode::On as u32 => Ok(WifiDebugMode::On), x if x == WifiDebugMode::On as u32 => Ok(WifiDebugMode::On),
_ => { Err("No enum match for value {v}") }, _ => Err("No enum match for value {v}"),
} }
} }
} }
impl fmt::Display for WifiDebugMode { impl fmt::Display for WifiDebugMode {
@ -64,10 +61,8 @@ pub struct SMManager {
should_trace: bool, should_trace: bool,
} }
impl SMManager impl SMManager {
{ pub fn new() -> Self {
pub fn new() -> Self
{
SMManager { SMManager {
wifi_debug_mode: WifiDebugMode::Off, wifi_debug_mode: WifiDebugMode::Off,
should_trace: is_galileo().unwrap(), should_trace: is_galileo().unwrap(),
@ -75,17 +70,13 @@ impl SMManager
} }
} }
impl Default for SMManager impl Default for SMManager {
{ fn default() -> Self {
fn default() -> Self
{
SMManager::new() SMManager::new()
} }
} }
const OVERRIDE_CONTENTS: &str = const OVERRIDE_CONTENTS: &str = "[Service]
"[Service]
ExecStart= ExecStart=
ExecStart=/usr/lib/iwd/iwd -d ExecStart=/usr/lib/iwd/iwd -d
"; ";
@ -99,8 +90,7 @@ const MIN_BUFFER_SIZE: u32 = 100;
const BOARD_NAME_PATH: &str = "/sys/class/dmi/id/board_name"; const BOARD_NAME_PATH: &str = "/sys/class/dmi/id/board_name";
const GALILEO_NAME: &str = "Galileo"; const GALILEO_NAME: &str = "Galileo";
fn is_galileo() -> std::io::Result<bool> fn is_galileo() -> std::io::Result<bool> {
{
let mut board_name = fs::read_to_string(BOARD_NAME_PATH)?; let mut board_name = fs::read_to_string(BOARD_NAME_PATH)?;
board_name = board_name.trim().to_string(); board_name = board_name.trim().to_string();
@ -108,19 +98,18 @@ fn is_galileo() -> std::io::Result<bool>
Ok(matches) Ok(matches)
} }
async fn script_exit_code( async fn script_exit_code(executable: &str, args: &[impl AsRef<OsStr>]) -> std::io::Result<bool> {
executable: &str,
args: &[impl AsRef<OsStr>],
) -> std::io::Result<bool> {
// Run given script and return true on success // Run given script and return true on success
let mut child = Command::new(executable) let mut child = Command::new(executable).args(args).spawn()?;
.args(args)
.spawn()?;
let status = child.wait().await?; let status = child.wait().await?;
Ok(status.success()) Ok(status.success())
} }
async fn run_script(name: &str, executable: &str, args: &[impl AsRef<OsStr>]) -> std::io::Result<bool> { async fn run_script(
name: &str,
executable: &str,
args: &[impl AsRef<OsStr>],
) -> std::io::Result<bool> {
// Run given script to get exit code and return true on success. // Run given script to get exit code and return true on success.
// Return false on failure, but also print an error if needed // Return false on failure, but also print an error if needed
match script_exit_code(executable, args).await { match script_exit_code(executable, args).await {
@ -148,8 +137,7 @@ async fn script_output(
Ok(s.to_string()) Ok(s.to_string())
} }
async fn setup_iwd_config(want_override: bool) -> Result<(), std::io::Error> async fn setup_iwd_config(want_override: bool) -> Result<(), std::io::Error> {
{
// Copy override.conf file into place or out of place depending // Copy override.conf file into place or out of place depending
// on install value // on install value
@ -165,8 +153,7 @@ async fn setup_iwd_config(want_override: bool) -> Result<(), std::io::Error>
} }
} }
async fn restart_iwd() -> std::io::Result<bool> async fn restart_iwd() -> std::io::Result<bool> {
{
// First reload systemd since we modified the config most likely // First reload systemd since we modified the config most likely
// othorwise we wouldn't be restarting iwd. // othorwise we wouldn't be restarting iwd.
match run_script("reload systemd", "systemctl", &["daemon-reload"]).await { match run_script("reload systemd", "systemctl", &["daemon-reload"]).await {
@ -179,7 +166,7 @@ async fn restart_iwd() -> std::io::Result<bool>
println!("restart_iwd: reload systemd failed somehow"); println!("restart_iwd: reload systemd failed somehow");
Ok(false) Ok(false)
} }
}, }
Err(message) => { Err(message) => {
println!("restart_iwd: reload systemd got an error {message}"); println!("restart_iwd: reload systemd got an error {message}");
Err(message) Err(message)
@ -187,8 +174,7 @@ async fn restart_iwd() -> std::io::Result<bool>
} }
} }
async fn stop_tracing(should_trace: bool) -> std::io::Result<bool> async fn stop_tracing(should_trace: bool) -> std::io::Result<bool> {
{
if !should_trace { if !should_trace {
return Ok(true); return Ok(true);
} }
@ -196,18 +182,27 @@ async fn stop_tracing(should_trace: bool) -> std::io::Result<bool>
// Stop tracing and extract ring buffer to disk for capture // Stop tracing and extract ring buffer to disk for capture
run_script("stop tracing", "trace-cmd", &["stop"]).await?; run_script("stop tracing", "trace-cmd", &["stop"]).await?;
// stop tracing worked // stop tracing worked
run_script("extract traces", "trace-cmd", &["extract", "-o", OUTPUT_FILE]).await run_script(
"extract traces",
"trace-cmd",
&["extract", "-o", OUTPUT_FILE],
)
.await
} }
async fn start_tracing(buffer_size:u32, should_trace: bool) -> std::io::Result<bool> async fn start_tracing(buffer_size: u32, should_trace: bool) -> std::io::Result<bool> {
{
if !should_trace { if !should_trace {
return Ok(true); return Ok(true);
} }
// Start tracing // Start tracing
let size_str = format!("{}", buffer_size); let size_str = format!("{}", buffer_size);
run_script("start tracing", "trace-cmd", &["start", "-e", "ath11k_wmi_diag", "-b", &size_str]).await run_script(
"start tracing",
"trace-cmd",
&["start", "-e", "ath11k_wmi_diag", "-b", &size_str],
)
.await
} }
#[interface(name = "com.steampowered.SteamOSManager1")] #[interface(name = "com.steampowered.SteamOSManager1")]
@ -221,8 +216,8 @@ impl SMManager {
async fn factory_reset(&self) -> bool { async fn factory_reset(&self) -> bool {
// Run steamos factory reset script and return true on success // Run steamos factory reset script and return true on success
match run_script("factory reset", "steamos-factory-reset-config", &[""]).await { match run_script("factory reset", "steamos-factory-reset-config", &[""]).await {
Ok(value) => { value }, Ok(value) => value,
Err(_) => { false } Err(_) => false,
} }
} }
@ -233,9 +228,10 @@ impl SMManager {
"/usr/bin/steamos-polkit-helpers/steamos-disable-wireless-power-management", "/usr/bin/steamos-polkit-helpers/steamos-disable-wireless-power-management",
&[""], &[""],
) )
.await { .await
Ok(value) => { value }, {
Err(_) => { false } Ok(value) => value,
Err(_) => false,
} }
} }
@ -247,9 +243,10 @@ impl SMManager {
"systemcltl", "systemcltl",
&["start", "jupiter-fan-control-service"], &["start", "jupiter-fan-control-service"],
) )
.await { .await
Ok(value) => { value }, {
Err(_) => { false } Ok(value) => value,
Err(_) => false,
} }
} else { } else {
match run_script( match run_script(
@ -257,9 +254,10 @@ impl SMManager {
"systemctl", "systemctl",
&["stop", "jupiter-fan-control.service"], &["stop", "jupiter-fan-control.service"],
) )
.await { .await
Ok(value) => { value }, {
Err(_) => { false } Ok(value) => value,
Err(_) => false,
} }
} }
} }
@ -268,8 +266,8 @@ impl SMManager {
// Run jupiter-check-support note this script does exit 1 for "Support: No" case // Run jupiter-check-support note this script does exit 1 for "Support: No" case
// so no need to parse output, etc. // so no need to parse output, etc.
match run_script("check hardware support", "jupiter-check-support", &[""]).await { match run_script("check hardware support", "jupiter-check-support", &[""]).await {
Ok(value) => { value }, Ok(value) => value,
Err(_) => { false } Err(_) => false,
} }
} }
@ -297,9 +295,10 @@ impl SMManager {
"/usr/bin/steamos-potlkit-helpers/jupiter-biosupdate", "/usr/bin/steamos-potlkit-helpers/jupiter-biosupdate",
&["--auto"], &["--auto"],
) )
.await { .await
Ok(value) => { value }, {
Err(_) => { false } Ok(value) => value,
Err(_) => false,
} }
} }
@ -311,9 +310,10 @@ impl SMManager {
"/usr/bin/steamos-polkit-helpers/jupiter-dock-updater", "/usr/bin/steamos-polkit-helpers/jupiter-dock-updater",
&[""], &[""],
) )
.await { .await
Ok(value) => { value }, {
Err(_) => { false } Ok(value) => value,
Err(_) => false,
} }
} }
@ -325,9 +325,10 @@ impl SMManager {
"/usr/bin/steamos-polkit-helpers/steamos-trim-devices", "/usr/bin/steamos-polkit-helpers/steamos-trim-devices",
&[""], &[""],
) )
.await { .await
Ok(value) => { value }, {
Err(_) => { false } Ok(value) => value,
Err(_) => false,
} }
} }
@ -339,9 +340,10 @@ impl SMManager {
"/usr/bin/steamos-polkit-helpers/steamos-format-sdcard", "/usr/bin/steamos-polkit-helpers/steamos-format-sdcard",
&[""], &[""],
) )
.await { .await
Ok(value) => { value }, {
Err(_) => { false } Ok(value) => value,
Err(_) => false,
} }
} }
@ -475,9 +477,7 @@ impl SMManager {
} }
} }
async fn get_als_integration_time_file_descriptor( async fn get_als_integration_time_file_descriptor(&self) -> Result<Fd, zbus::fdo::Error> {
&self,
) -> Result<Fd, zbus::fdo::Error> {
// Get the file descriptor for the als integration time sysfs path // Get the file descriptor for the als integration time sysfs path
// /sys/devices/platform/AMDI0010:00/i2c-0/i2c-PRP0001:01/iio:device0/in_illuminance_integration_time // /sys/devices/platform/AMDI0010:00/i2c-0/i2c-PRP0001:01/iio:device0/in_illuminance_integration_time
// Return -1 on error // Return -1 on error
@ -520,33 +520,36 @@ impl SMManager {
self.wifi_debug_mode = WifiDebugMode::Off; self.wifi_debug_mode = WifiDebugMode::Off;
} else { } else {
// restart_iwd failed // restart_iwd failed
println!("restart_iwd failed somehow, check log above"); println!(
"restart_iwd failed somehow, check log above"
);
return false; return false;
} }
}, }
Err(message) => { Err(message) => {
println!("restart_iwd got an error {message}"); println!("restart_iwd got an error {message}");
return false; return false;
} }
} }
}, }
Err(message) => { Err(message) => {
println!("setup_iwd_config false got an error somehow {message}"); println!(
"setup_iwd_config false got an error somehow {message}"
);
return false; return false;
} }
} }
} else { } else {
println!("stop_tracing command failed somehow, bailing"); println!("stop_tracing command failed somehow, bailing");
return false; return false;
} }
}, }
Err(message) => { Err(message) => {
println!("stop_tracing command had an error {message}"); println!("stop_tracing command had an error {message}");
return false; return false;
} }
} }
}, }
Ok(WifiDebugMode::On) => { Ok(WifiDebugMode::On) => {
// If mode is 1 enable wifi debug mode // If mode is 1 enable wifi debug mode
if buffer_size < MIN_BUFFER_SIZE { if buffer_size < MIN_BUFFER_SIZE {
@ -570,7 +573,7 @@ impl SMManager {
println!("start_tracing failed somehow"); println!("start_tracing failed somehow");
return false; return false;
} }
}, }
Err(message) => { Err(message) => {
println!("start_tracing got an error {message}"); println!("start_tracing got an error {message}");
return false; return false;
@ -580,24 +583,24 @@ impl SMManager {
println!("restart_iwd failed somehow"); println!("restart_iwd failed somehow");
return false; return false;
} }
}, }
Err(message) => { Err(message) => {
println!("restart_iwd got an error {message}"); println!("restart_iwd got an error {message}");
return false; return false;
} }
} }
}, }
Err(message) => { Err(message) => {
println!("setup_iwd_config true got an error somehow {message}"); println!("setup_iwd_config true got an error somehow {message}");
return false; return false;
} }
} }
}, }
Err(_) => { Err(_) => {
// Invalid mode requested, more coming later, but add this catch-all for now // Invalid mode requested, more coming later, but add this catch-all for now
println!("Invalid wifi debug mode {mode} requested"); println!("Invalid wifi debug mode {mode} requested");
return false; return false;
}, }
} }
true true