mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-08-01 13:48:47 +00:00
chore: code cleanup
This commit is contained in:
parent
e81ca83f9e
commit
02eb266e8f
5 changed files with 33 additions and 31 deletions
|
@ -1,14 +1,12 @@
|
||||||
|
use crate::{constants::CMD_NAME, runner::Runner};
|
||||||
|
use expect_dialog::ExpectDialog;
|
||||||
use std::{
|
use std::{
|
||||||
env,
|
env,
|
||||||
fs::{self, create_dir_all, OpenOptions, remove_file},
|
fs::{self, create_dir_all, OpenOptions},
|
||||||
io::BufWriter,
|
io::BufWriter,
|
||||||
path::Path,
|
path::Path,
|
||||||
};
|
};
|
||||||
|
|
||||||
use expect_dialog::ExpectDialog;
|
|
||||||
|
|
||||||
use crate::{constants::CMD_NAME, runner::Runner};
|
|
||||||
|
|
||||||
pub fn get_writer(path_s: &String) -> BufWriter<std::fs::File> {
|
pub fn get_writer(path_s: &String) -> BufWriter<std::fs::File> {
|
||||||
let path = Path::new(path_s);
|
let path = Path::new(path_s);
|
||||||
match path.parent() {
|
match path.parent() {
|
||||||
|
@ -35,25 +33,23 @@ pub fn get_home_dir() -> String {
|
||||||
pub fn get_xdg_config_dir() -> String {
|
pub fn get_xdg_config_dir() -> String {
|
||||||
match env::var("XDG_CONFIG_HOME") {
|
match env::var("XDG_CONFIG_HOME") {
|
||||||
Ok(conf_home) => conf_home,
|
Ok(conf_home) => conf_home,
|
||||||
Err(_) => format!(
|
Err(_) => format!("{home}/.config", home = get_home_dir()),
|
||||||
"{home}/.config",
|
|
||||||
home = get_home_dir()
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_xdg_data_dir() -> String {
|
pub fn get_xdg_data_dir() -> String {
|
||||||
match env::var("XDG_DATA_HOME") {
|
match env::var("XDG_DATA_HOME") {
|
||||||
Ok(data_home) => data_home,
|
Ok(data_home) => data_home,
|
||||||
Err(_) => format!(
|
Err(_) => format!("{home}/.local/share", home = get_home_dir()),
|
||||||
"{home}/.local/share",
|
|
||||||
home = get_home_dir()
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_config_dir() -> String {
|
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 {
|
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) {
|
pub fn setcap_cap_sys_nice_eip(file: String) {
|
||||||
let mut runner = Runner::new(None, "pkexec".into(), vec![
|
let mut runner = Runner::new(
|
||||||
"setcap".into(),
|
None,
|
||||||
"CAP_SYS_NICE=eip".into(),
|
"pkexec".into(),
|
||||||
file
|
vec!["setcap".into(), "CAP_SYS_NICE=eip".into(), file],
|
||||||
]);
|
);
|
||||||
runner.start();
|
runner.start();
|
||||||
runner.join();
|
runner.join();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
|
use crate::file_utils::get_writer;
|
||||||
use expect_dialog::ExpectDialog;
|
use expect_dialog::ExpectDialog;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{collections::HashMap, fmt::Display, fs::File, io::BufReader};
|
use std::{collections::HashMap, fmt::Display, fs::File, io::BufReader};
|
||||||
|
|
||||||
use crate::file_utils::get_writer;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub struct Profile {
|
pub struct Profile {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
@ -29,8 +28,13 @@ impl Display for Profile {
|
||||||
impl Profile {
|
impl Profile {
|
||||||
pub fn get_steam_launch_options(&self) -> String {
|
pub fn get_steam_launch_options(&self) -> String {
|
||||||
let mut opts = vec![];
|
let mut opts = vec![];
|
||||||
opts.push(format!("XR_RUNTIME_JSON={prefix}/share/openxr/1/openxr_monado.json", prefix = self.prefix));
|
opts.push(format!(
|
||||||
opts.push(format!("PRESSURE_VESSEL_FILESYSTEMS_RW=$XDG_RUNTIME_DIR/monado_comp_ipc"));
|
"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.push("%command%".into());
|
||||||
opts.join(" ")
|
opts.join(" ")
|
||||||
}
|
}
|
||||||
|
@ -94,7 +98,7 @@ mod tests {
|
||||||
basalt_enabled: false,
|
basalt_enabled: false,
|
||||||
mercury_enabled: false,
|
mercury_enabled: false,
|
||||||
environment: env,
|
environment: env,
|
||||||
prefix: String::from("/home/user/rex2prefix")
|
prefix: String::from("/home/user/rex2prefix"),
|
||||||
};
|
};
|
||||||
let fpath = String::from("./target/testout/testprofile.json");
|
let fpath = String::from("./target/testout/testprofile.json");
|
||||||
dump_profile(p, &fpath);
|
dump_profile(p, &fpath);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{cell::RefCell, borrow::BorrowMut};
|
use std::cell::RefCell;
|
||||||
|
|
||||||
use crate::runner::{Runner, RunnerStatus};
|
use crate::runner::{Runner, RunnerStatus};
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
|
use crate::constants::{get_developers, APP_NAME, REPO_URL, SINGLE_DEVELOPER, VERSION};
|
||||||
use relm4::gtk::traits::GtkWindowExt;
|
use relm4::gtk::traits::GtkWindowExt;
|
||||||
use relm4::prelude::*;
|
use relm4::prelude::*;
|
||||||
use relm4::{ComponentParts, SimpleComponent};
|
use relm4::{ComponentParts, SimpleComponent};
|
||||||
|
|
||||||
use crate::constants::{APP_NAME, REPO_URL, SINGLE_DEVELOPER, VERSION, get_developers};
|
|
||||||
|
|
||||||
pub struct AboutDialog {}
|
pub struct AboutDialog {}
|
||||||
|
|
||||||
impl SimpleComponent for AboutDialog {
|
impl SimpleComponent for AboutDialog {
|
||||||
|
|
|
@ -9,8 +9,12 @@ use crate::config::{get_config, save_config, Config};
|
||||||
use crate::constants::APP_NAME;
|
use crate::constants::APP_NAME;
|
||||||
use crate::dependencies::libsurvive_deps::get_missing_libsurvive_deps;
|
use crate::dependencies::libsurvive_deps::get_missing_libsurvive_deps;
|
||||||
use crate::dependencies::monado_deps::get_missing_monado_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::active_runtime_json::{
|
||||||
use crate::file_builders::openvrpaths_vrpath::{set_current_openvrpaths_to_profile, set_current_openvrpaths_to_steam};
|
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::profile::Profile;
|
||||||
use crate::profiles::valve_index::valve_index_profile;
|
use crate::profiles::valve_index::valve_index_profile;
|
||||||
use crate::runner::{Runner, RunnerStatus};
|
use crate::runner::{Runner, RunnerStatus};
|
||||||
|
@ -262,8 +266,7 @@ impl SimpleComponent for App {
|
||||||
let profile = self.get_selected_profile();
|
let profile = self.get_selected_profile();
|
||||||
set_current_active_runtime_to_profile(profile.clone());
|
set_current_active_runtime_to_profile(profile.clone());
|
||||||
set_current_openvrpaths_to_profile(profile.clone());
|
set_current_openvrpaths_to_profile(profile.clone());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
set_current_active_runtime_to_steam();
|
set_current_active_runtime_to_steam();
|
||||||
set_current_openvrpaths_to_steam();
|
set_current_openvrpaths_to_steam();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue