diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 302a2f9..d81c417 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -53,13 +53,13 @@ debug = false strip = true lto = true codegen-units = 1 +opt-level = 3 [profile.docker] inherits = "release" debug = false strip = true lto = "thin" -codegen-units = 16 -opt-level = 2 +codegen-units = 8 debug-assertions = false overflow-checks = false diff --git a/backend/src/api/general.rs b/backend/src/api/general.rs index feda6af..806347a 100644 --- a/backend/src/api/general.rs +++ b/backend/src/api/general.rs @@ -111,14 +111,17 @@ pub fn load_variant( ) -> impl Fn(super::ApiParameterType) -> super::ApiParameterType { let sender = Mutex::new(sender); // Sender is not Sync; this is required for safety let setter = move |variant: u64, variant_name: Option| { - log::debug!("load_variant(variant: {}, variant_name: {:?})", variant, variant_name); + log::debug!( + "load_variant(variant: {}, variant_name: {:?})", + variant, + variant_name + ); sender .lock() .unwrap() .send(ApiMessage::LoadVariant( variant, - variant_name - .unwrap_or_else(|| "".to_owned()), + variant_name.unwrap_or_else(|| "".to_owned()), )) .expect("load_variant send failed") }; diff --git a/backend/src/api/web.rs b/backend/src/api/web.rs index 1001e49..965be44 100644 --- a/backend/src/api/web.rs +++ b/backend/src/api/web.rs @@ -9,11 +9,15 @@ const BASE_URL_FALLBACK: &'static str = "https://powertools.ngni.us"; static BASE_URL: RwLock> = RwLock::new(None); pub fn set_base_url(base_url: String) { - *BASE_URL.write().expect("Failed to acquire write lock for store base url") = Some(base_url); + *BASE_URL + .write() + .expect("Failed to acquire write lock for store base url") = Some(base_url); } fn get_base_url() -> String { - BASE_URL.read().expect("Failed to acquire read lock for store base url") + BASE_URL + .read() + .expect("Failed to acquire read lock for store base url") .clone() .unwrap_or_else(|| BASE_URL_FALLBACK.to_owned()) } diff --git a/backend/src/cli/args.rs b/backend/src/cli/args.rs index 9edebad..3c10a59 100644 --- a/backend/src/cli/args.rs +++ b/backend/src/cli/args.rs @@ -26,10 +26,7 @@ impl Args { } pub fn is_default(&self) -> bool { - self.port.is_none() - && self.log.is_none() - && !self.verbose - && self.op.is_none() + self.port.is_none() && self.log.is_none() && !self.verbose && self.op.is_none() } } diff --git a/backend/src/cli/clean.rs b/backend/src/cli/clean.rs index 7afe215..590e61a 100644 --- a/backend/src/cli/clean.rs +++ b/backend/src/cli/clean.rs @@ -12,7 +12,9 @@ pub fn clean_up() -> Result<(), ()> { } } -fn clean_up_io(directories: impl Iterator>) -> std::io::Result<()> { +fn clean_up_io( + directories: impl Iterator>, +) -> std::io::Result<()> { let results = directories.map(|dir| std::fs::remove_dir_all(dir)); for res in results { res?; diff --git a/backend/src/cli/dump_sys.rs b/backend/src/cli/dump_sys.rs index 03e4c0c..c626581 100644 --- a/backend/src/cli/dump_sys.rs +++ b/backend/src/cli/dump_sys.rs @@ -1,8 +1,8 @@ +use std::io::Write; use std::path::{Path, PathBuf}; use std::process::Command; -use std::thread::{self, JoinHandle}; use std::sync::mpsc::{channel, Sender}; -use std::io::Write; +use std::thread::{self, JoinHandle}; pub fn dump_sys_info() -> Result<(), ()> { let (tx, rx) = channel(); @@ -16,9 +16,7 @@ pub fn dump_sys_info() -> Result<(), ()> { join_handles.push(read_file(file, tx.clone())); } - let useful_commands = vec![ - "dmidecode", - ]; + let useful_commands = vec!["dmidecode"]; for cmd in useful_commands.into_iter() { join_handles.push(execute_command(cmd, tx.clone())); } @@ -29,38 +27,48 @@ pub fn dump_sys_info() -> Result<(), ()> { } } - let mut dump_file = std::fs::File::create("powertools_sys_dump.txt").expect("Failed to create dump file"); + let mut dump_file = + std::fs::File::create("powertools_sys_dump.txt").expect("Failed to create dump file"); for response in rx.into_iter() { - dump_file.write( - &format!("{} v{} ###### {} ######\n{}\n", - crate::consts::PACKAGE_NAME, - crate::consts::PACKAGE_VERSION, - response.0, - response.1.unwrap_or("[None]".to_owned()) - ).into_bytes() - ).expect("Failed to write to dump file"); + dump_file + .write( + &format!( + "{} v{} ###### {} ######\n{}\n", + crate::consts::PACKAGE_NAME, + crate::consts::PACKAGE_VERSION, + response.0, + response.1.unwrap_or("[None]".to_owned()) + ) + .into_bytes(), + ) + .expect("Failed to write to dump file"); } Ok(()) } -fn read_file(file: impl AsRef + Send + 'static, tx: Sender<(String, Option)>) -> JoinHandle<()> { +fn read_file( + file: impl AsRef + Send + 'static, + tx: Sender<(String, Option)>, +) -> JoinHandle<()> { thread::spawn(move || { let file = file.as_ref(); - tx.send( - (file.display().to_string(), - std::fs::read_to_string(file).ok()) - ).expect("Failed to send file contents"); + tx.send(( + file.display().to_string(), + std::fs::read_to_string(file).ok(), + )) + .expect("Failed to send file contents"); }) } fn execute_command(command: &'static str, tx: Sender<(String, Option)>) -> JoinHandle<()> { thread::spawn(move || { - tx.send( - (command.to_owned(), Command::new(command) + tx.send(( + command.to_owned(), + Command::new(command) .output() .map(|out| String::from_utf8_lossy(&out.stdout).into_owned()) - .ok() - )).expect("Failed to send command output"); - } - ) + .ok(), + )) + .expect("Failed to send command output"); + }) } diff --git a/backend/src/main.rs b/backend/src/main.rs index f9116c7..b15fefb 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -50,7 +50,11 @@ fn main() -> Result<(), ()> { }, #[cfg(not(debug_assertions))] { - if args.verbose { LevelFilter::Debug } else { LevelFilter::Info } + if args.verbose { + LevelFilter::Debug + } else { + LevelFilter::Info + } }, Default::default(), std::fs::File::create(&log_filepath).expect("Failed to create log file"), diff --git a/backend/src/persist/file.rs b/backend/src/persist/file.rs index 0999517..9720b1e 100644 --- a/backend/src/persist/file.rs +++ b/backend/src/persist/file.rs @@ -71,7 +71,13 @@ impl FileJson { if setting.name.is_empty() { setting.name = format!("Variant {}", setting.variant); } - log::debug!("Inserting setting variant `{}` ({}) for app `{}` ({})", setting.name, setting.variant, file.name, app_id); + log::debug!( + "Inserting setting variant `{}` ({}) for app `{}` ({})", + setting.name, + setting.variant, + file.name, + app_id + ); file.variants.insert(setting.variant, setting.clone()); (file, setting) } else { @@ -83,15 +89,24 @@ impl FileJson { if setting.name.is_empty() { setting.name = format!("Variant {}", setting.variant); } - log::debug!("Creating new setting variant `{}` ({}) for app `{}` ({})", setting.name, setting.variant, app_name, app_id); + log::debug!( + "Creating new setting variant `{}` ({}) for app `{}` ({})", + setting.name, + setting.variant, + app_name, + app_id + ); let mut setting_variants = HashMap::with_capacity(1); setting_variants.insert(setting.variant, setting.clone()); - (Self { - version: 0, - app_id: app_id, - name: app_name, - variants: setting_variants, - }, setting) + ( + Self { + version: 0, + app_id: app_id, + name: app_name, + variants: setting_variants, + }, + setting, + ) }; file.save(path)?; diff --git a/backend/src/settings/general.rs b/backend/src/settings/general.rs index b873b0a..2a75eae 100644 --- a/backend/src/settings/general.rs +++ b/backend/src/settings/general.rs @@ -135,7 +135,8 @@ impl TGeneral for General { setting: SettingVariant::General, }) .map(|file| { - file.0.variants + file.0 + .variants .into_iter() .map(|(id, conf)| crate::api::VariantInfo { id: id.to_string(), @@ -147,7 +148,11 @@ impl TGeneral for General { } fn get_variant_info(&self) -> crate::api::VariantInfo { - log::debug!("Current variant `{}` ({})", self.variant_name, self.variant_id); + log::debug!( + "Current variant `{}` ({})", + self.variant_name, + self.variant_id + ); crate::api::VariantInfo { id: self.variant_id.to_string(), name: self.variant_name.clone(), @@ -260,7 +265,10 @@ impl Settings { let mut valid_ids: Vec<&u64> = settings_file.variants.keys().collect(); valid_ids.sort(); if let Some(id) = valid_ids.get(0) { - Ok(settings_file.variants.get(id).expect("variant id key magically disappeared")) + Ok(settings_file + .variants + .get(id) + .expect("variant id key magically disappeared")) } else { Err(SettingError { msg: format!( @@ -293,7 +301,11 @@ impl Settings { let json_path = crate::utility::settings_dir().join(&filename); if json_path.exists() { if variant == u64::MAX { - log::debug!("Creating new variant `{}` in existing settings file {}", variant_name, json_path.display()); + log::debug!( + "Creating new variant `{}` in existing settings file {}", + variant_name, + json_path.display() + ); self.create_and_load_variant(&json_path, app_id, variant_name)?; } else { let file_json = FileJson::open(&json_path).map_err(|e| SettingError { @@ -336,7 +348,11 @@ impl Settings { } *self.general.persistent() = false; if variant == u64::MAX { - log::debug!("Creating new variant `{}` in new settings file {}", variant_name, json_path.display()); + log::debug!( + "Creating new variant `{}` in new settings file {}", + variant_name, + json_path.display() + ); self.create_and_load_variant(&json_path, app_id, variant_name)?; } } @@ -345,7 +361,12 @@ impl Settings { Ok(*self.general.persistent()) } - fn create_and_load_variant(&mut self, json_path: &PathBuf, app_id: u64, variant_name: String) -> Result<(), SettingError> { + fn create_and_load_variant( + &mut self, + json_path: &PathBuf, + app_id: u64, + variant_name: String, + ) -> Result<(), SettingError> { *self.general.persistent() = true; self.general.variant_id(u64::MAX); self.general.variant_name(variant_name.clone()); diff --git a/backend/src/settings/steam_deck/gpu.rs b/backend/src/settings/steam_deck/gpu.rs index beb0a47..4912713 100644 --- a/backend/src/settings/steam_deck/gpu.rs +++ b/backend/src/settings/steam_deck/gpu.rs @@ -196,9 +196,20 @@ impl Gpu { let is_lcd = matches!(self.variant, super::Model::LCD); let is_lock_feature_enabled = self.limits.extras.quirks.contains("pp_dpm_fclk-static"); - if (is_oled && self.limits.extras.quirks.contains("pp_dpm_fclk-reversed-on-OLED")) - || (is_lcd && self.limits.extras.quirks.contains("pp_dpm_fclk-reversed-on-LCD")) - || self.limits.extras.quirks.contains("pp_dpm_fclk-reversed") { + if (is_oled + && self + .limits + .extras + .quirks + .contains("pp_dpm_fclk-reversed-on-OLED")) + || (is_lcd + && self + .limits + .extras + .quirks + .contains("pp_dpm_fclk-reversed-on-LCD")) + || self.limits.extras.quirks.contains("pp_dpm_fclk-reversed") + { let options_count = self .sysfs_card .read_value(GPU_MEMORY_DOWNCLOCK_ATTRIBUTE.to_owned()) @@ -208,12 +219,13 @@ impl Gpu { if is_lock_feature_enabled { format!("{}\n", modifier - max_val) } else { - if max_val == 0 as u64 { + if max_val == 0 as u64 { format!("{}\n", modifier) } else { use std::fmt::Write; let mut payload = format!("{}", modifier - max_val); - for i in (0..max_val).rev(/* rev() isn't necessary but it creates a nicer (ascending) order */) { + for i in (0..max_val).rev(/* rev() isn't necessary but it creates a nicer (ascending) order */) + { write!(payload, " {}", modifier - i) .expect("Failed to write to memory payload (should be infallible!?)"); }