mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-07-24 09:51:43 +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::{
|
||||
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<std::fs::File> {
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::{cell::RefCell, borrow::BorrowMut};
|
||||
use std::cell::RefCell;
|
||||
|
||||
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::prelude::*;
|
||||
use relm4::{ComponentParts, SimpleComponent};
|
||||
|
||||
use crate::constants::{APP_NAME, REPO_URL, SINGLE_DEVELOPER, VERSION, get_developers};
|
||||
|
||||
pub struct AboutDialog {}
|
||||
|
||||
impl SimpleComponent for AboutDialog {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue