fix: get steamvr bin dir by parsing libraryfolders.vdf
Some checks are pending
/ cargo-fmtcheck (push) Waiting to run
/ cargo-clippy (push) Waiting to run
/ cargo-test (push) Waiting to run
/ appimage (push) Waiting to run

fixes #171
This commit is contained in:
Gabriele Musco 2025-01-02 11:42:43 +01:00
commit e5a59ebf62
2 changed files with 69 additions and 49 deletions

View file

@ -1,4 +1,6 @@
use crate::{constants::CMD_NAME, xdg::XDG}; use anyhow::bail;
use crate::{constants::CMD_NAME, util::steam_library_folder::SteamLibraryFolder, xdg::XDG};
use std::{ use std::{
env, env,
fs::create_dir_all, fs::create_dir_all,
@ -83,9 +85,24 @@ pub fn get_exec_prefix() -> PathBuf {
.into() .into()
} }
pub fn get_steamvr_bin_dir_path() -> PathBuf { const STEAMVR_STEAM_APPID: u32 = 250820;
XDG.get_data_home()
.join("Steam/steamapps/common/SteamVR/bin/linux64") fn get_steamvr_base_dir() -> anyhow::Result<PathBuf> {
SteamLibraryFolder::get_folders()?
.into_iter()
.find(|(_, lf)| lf.apps.contains_key(&STEAMVR_STEAM_APPID))
.map(|(_, lf)| PathBuf::from(lf.path))
.ok_or(anyhow::Error::msg(
"Could not find SteamVR in Steam libraryfolders.vdf",
))
}
pub fn get_steamvr_bin_dir_path() -> anyhow::Result<PathBuf> {
let res = get_steamvr_base_dir()?.join("bin/linux64");
if !res.is_dir() {
bail!("SteamVR bin dir `{}` does not exist", res.to_string_lossy());
}
Ok(res)
} }
pub fn get_plugins_dir() -> PathBuf { pub fn get_plugins_dir() -> PathBuf {

View file

@ -10,7 +10,6 @@ use relm4::{
}; };
use std::{ use std::{
collections::{HashMap, VecDeque}, collections::{HashMap, VecDeque},
path::Path,
thread::sleep, thread::sleep,
time::Duration, time::Duration,
}; };
@ -145,51 +144,55 @@ impl SimpleComponent for SteamVrCalibrationBox {
} }
Self::Input::RunCalibration => { Self::Input::RunCalibration => {
self.set_calibration_result(None); self.set_calibration_result(None);
let steamvr_bin_dir = get_steamvr_bin_dir_path().to_string_lossy().to_string(); match get_steamvr_bin_dir_path() {
if !Path::new(&steamvr_bin_dir).is_dir() { Err(e) => {
self.set_calibration_success(false); error!("could not get SteamVR bin dir: {e}");
self.set_calibration_result(Some("SteamVR not found".into())); self.set_calibration_success(false);
return; self.set_calibration_result(Some("SteamVR not found".into()));
} }
let mut env: HashMap<String, String> = HashMap::new(); Ok(bin_dir_p) => {
env.insert("LD_LIBRARY_PATH".into(), steamvr_bin_dir.clone()); let steamvr_bin_dir = bin_dir_p.to_string_lossy().to_string();
let vrcmd = format!("{steamvr_bin_dir}/vrcmd"); let mut env: HashMap<String, String> = HashMap::new();
let server_worker = { env.insert("LD_LIBRARY_PATH".into(), steamvr_bin_dir.clone());
let mut jobs: VecDeque<WorkerJob> = VecDeque::new(); let vrcmd = format!("{steamvr_bin_dir}/vrcmd");
jobs.push_back(WorkerJob::new_cmd( let server_worker = {
Some(env.clone()), let mut jobs: VecDeque<WorkerJob> = VecDeque::new();
vrcmd.clone(), jobs.push_back(WorkerJob::new_cmd(
Some(vec!["--pollposes".into()]), Some(env.clone()),
)); vrcmd.clone(),
JobWorker::new(jobs, sender.input_sender(), |msg| match msg { Some(vec!["--pollposes".into()]),
JobWorkerOut::Log(_) => Self::Input::NoOp, ));
JobWorkerOut::Exit(code) => Self::Input::OnServerWorkerExit(code), JobWorker::new(jobs, sender.input_sender(), |msg| match msg {
}) JobWorkerOut::Log(_) => Self::Input::NoOp,
}; JobWorkerOut::Exit(code) => Self::Input::OnServerWorkerExit(code),
let cal_worker = { })
let mut jobs: VecDeque<WorkerJob> = VecDeque::new(); };
jobs.push_back(WorkerJob::new_func(Box::new(move || { let cal_worker = {
sleep(Duration::from_secs(2)); let mut jobs: VecDeque<WorkerJob> = VecDeque::new();
FuncWorkerOut { jobs.push_back(WorkerJob::new_func(Box::new(move || {
success: true, sleep(Duration::from_secs(2));
out: vec![], FuncWorkerOut {
} success: true,
}))); out: vec![],
jobs.push_back(WorkerJob::new_cmd( }
Some(env), })));
vrcmd, jobs.push_back(WorkerJob::new_cmd(
Some(vec!["--resetroomsetup".into()]), Some(env),
)); vrcmd,
JobWorker::new(jobs, sender.input_sender(), |msg| match msg { Some(vec!["--resetroomsetup".into()]),
JobWorkerOut::Log(_) => Self::Input::NoOp, ));
JobWorkerOut::Exit(code) => Self::Input::OnCalWorkerExit(code), JobWorker::new(jobs, sender.input_sender(), |msg| match msg {
}) JobWorkerOut::Log(_) => Self::Input::NoOp,
}; JobWorkerOut::Exit(code) => Self::Input::OnCalWorkerExit(code),
})
};
server_worker.start(); server_worker.start();
cal_worker.start(); cal_worker.start();
self.server_worker = Some(server_worker); self.server_worker = Some(server_worker);
self.calibration_worker = Some(cal_worker); self.calibration_worker = Some(cal_worker);
}
};
} }
Self::Input::OnServerWorkerExit(code) => { Self::Input::OnServerWorkerExit(code) => {
if code != 0 { if code != 0 {