From 02eb266e8fab572bb7a3007fe2b4b46c92c975f5 Mon Sep 17 00:00:00 2001 From: Gabriele Musco Date: Thu, 15 Jun 2023 21:16:52 +0200 Subject: [PATCH] chore: code cleanup --- src/file_utils.rs | 34 +++++++++++++++------------------- src/profile.rs | 14 +++++++++----- src/runner_pipeline.rs | 2 +- src/ui/about_dialog.rs | 3 +-- src/ui/app.rs | 11 +++++++---- 5 files changed, 33 insertions(+), 31 deletions(-) diff --git a/src/file_utils.rs b/src/file_utils.rs index 14a5328..95840de 100644 --- a/src/file_utils.rs +++ b/src/file_utils.rs @@ -1,14 +1,12 @@ +use crate::{constants::CMD_NAME, runner::Runner}; +use expect_dialog::ExpectDialog; use std::{ env, - fs::{self, create_dir_all, OpenOptions, remove_file}, + fs::{self, create_dir_all, OpenOptions}, io::BufWriter, path::Path, }; -use expect_dialog::ExpectDialog; - -use crate::{constants::CMD_NAME, runner::Runner}; - pub fn get_writer(path_s: &String) -> BufWriter { let path = Path::new(path_s); match path.parent() { @@ -35,25 +33,23 @@ pub fn get_home_dir() -> String { pub fn get_xdg_config_dir() -> String { match env::var("XDG_CONFIG_HOME") { Ok(conf_home) => conf_home, - Err(_) => format!( - "{home}/.config", - home = get_home_dir() - ), + Err(_) => format!("{home}/.config", home = get_home_dir()), } } pub fn get_xdg_data_dir() -> String { match env::var("XDG_DATA_HOME") { Ok(data_home) => data_home, - Err(_) => format!( - "{home}/.local/share", - home = get_home_dir() - ), + Err(_) => format!("{home}/.local/share", home = get_home_dir()), } } pub fn get_config_dir() -> String { - format!("{config}/{name}", config = get_xdg_config_dir(), name = CMD_NAME) + format!( + "{config}/{name}", + config = get_xdg_config_dir(), + name = CMD_NAME + ) } pub fn get_data_dir() -> String { @@ -74,11 +70,11 @@ pub fn set_file_radonly(path_s: &String, readonly: bool) { } pub fn setcap_cap_sys_nice_eip(file: String) { - let mut runner = Runner::new(None, "pkexec".into(), vec![ - "setcap".into(), - "CAP_SYS_NICE=eip".into(), - file - ]); + let mut runner = Runner::new( + None, + "pkexec".into(), + vec!["setcap".into(), "CAP_SYS_NICE=eip".into(), file], + ); runner.start(); runner.join(); } diff --git a/src/profile.rs b/src/profile.rs index c554907..0a5e448 100644 --- a/src/profile.rs +++ b/src/profile.rs @@ -1,9 +1,8 @@ +use crate::file_utils::get_writer; use expect_dialog::ExpectDialog; use serde::{Deserialize, Serialize}; use std::{collections::HashMap, fmt::Display, fs::File, io::BufReader}; -use crate::file_utils::get_writer; - #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Profile { pub name: String, @@ -29,8 +28,13 @@ impl Display for Profile { impl Profile { pub fn get_steam_launch_options(&self) -> String { let mut opts = vec![]; - opts.push(format!("XR_RUNTIME_JSON={prefix}/share/openxr/1/openxr_monado.json", prefix = self.prefix)); - opts.push(format!("PRESSURE_VESSEL_FILESYSTEMS_RW=$XDG_RUNTIME_DIR/monado_comp_ipc")); + opts.push(format!( + "XR_RUNTIME_JSON={prefix}/share/openxr/1/openxr_monado.json", + prefix = self.prefix + )); + opts.push(format!( + "PRESSURE_VESSEL_FILESYSTEMS_RW=$XDG_RUNTIME_DIR/monado_comp_ipc" + )); opts.push("%command%".into()); opts.join(" ") } @@ -94,7 +98,7 @@ mod tests { basalt_enabled: false, mercury_enabled: false, environment: env, - prefix: String::from("/home/user/rex2prefix") + prefix: String::from("/home/user/rex2prefix"), }; let fpath = String::from("./target/testout/testprofile.json"); dump_profile(p, &fpath); diff --git a/src/runner_pipeline.rs b/src/runner_pipeline.rs index 39540e2..9c55a09 100644 --- a/src/runner_pipeline.rs +++ b/src/runner_pipeline.rs @@ -1,4 +1,4 @@ -use std::{cell::RefCell, borrow::BorrowMut}; +use std::cell::RefCell; use crate::runner::{Runner, RunnerStatus}; diff --git a/src/ui/about_dialog.rs b/src/ui/about_dialog.rs index 1b0aac0..a3a4983 100644 --- a/src/ui/about_dialog.rs +++ b/src/ui/about_dialog.rs @@ -1,9 +1,8 @@ +use crate::constants::{get_developers, APP_NAME, REPO_URL, SINGLE_DEVELOPER, VERSION}; use relm4::gtk::traits::GtkWindowExt; use relm4::prelude::*; use relm4::{ComponentParts, SimpleComponent}; -use crate::constants::{APP_NAME, REPO_URL, SINGLE_DEVELOPER, VERSION, get_developers}; - pub struct AboutDialog {} impl SimpleComponent for AboutDialog { diff --git a/src/ui/app.rs b/src/ui/app.rs index fc4e1b1..2f1bbfa 100644 --- a/src/ui/app.rs +++ b/src/ui/app.rs @@ -9,8 +9,12 @@ use crate::config::{get_config, save_config, Config}; use crate::constants::APP_NAME; use crate::dependencies::libsurvive_deps::get_missing_libsurvive_deps; use crate::dependencies::monado_deps::get_missing_monado_deps; -use crate::file_builders::active_runtime_json::{set_current_active_runtime_to_profile, set_current_active_runtime_to_steam}; -use crate::file_builders::openvrpaths_vrpath::{set_current_openvrpaths_to_profile, set_current_openvrpaths_to_steam}; +use crate::file_builders::active_runtime_json::{ + set_current_active_runtime_to_profile, set_current_active_runtime_to_steam, +}; +use crate::file_builders::openvrpaths_vrpath::{ + set_current_openvrpaths_to_profile, set_current_openvrpaths_to_steam, +}; use crate::profile::Profile; use crate::profiles::valve_index::valve_index_profile; use crate::runner::{Runner, RunnerStatus}; @@ -262,8 +266,7 @@ impl SimpleComponent for App { let profile = self.get_selected_profile(); set_current_active_runtime_to_profile(profile.clone()); set_current_openvrpaths_to_profile(profile.clone()); - } - else { + } else { set_current_active_runtime_to_steam(); set_current_openvrpaths_to_steam(); }