chore: move ipc file path function to XRServiceType

This commit is contained in:
Gabriele Musco 2024-09-01 19:28:44 +02:00
commit 65cdddbb98
3 changed files with 15 additions and 14 deletions

View file

@ -1,4 +1,4 @@
use crate::{constants::CMD_NAME, profile::XRServiceType, xdg::XDG}; use crate::{constants::CMD_NAME, xdg::XDG};
use std::{ use std::{
env, env,
fs::create_dir_all, fs::create_dir_all,
@ -83,15 +83,6 @@ pub fn get_exec_prefix() -> PathBuf {
.into() .into()
} }
pub fn get_ipc_file_path(xrservice_type: &XRServiceType) -> PathBuf {
XDG.get_runtime_directory()
.expect("XDG runtime directory is not available")
.join(match xrservice_type {
XRServiceType::Monado => "monado_comp_ipc",
XRServiceType::Wivrn => "wivrn_comp_ipc",
})
}
pub fn get_steamvr_bin_dir_path() -> PathBuf { pub fn get_steamvr_bin_dir_path() -> PathBuf {
XDG.get_data_home() XDG.get_data_home()
.join("Steam/steamapps/common/SteamVR/bin/linux64") .join("Steam/steamapps/common/SteamVR/bin/linux64")

View file

@ -1,6 +1,7 @@
use crate::{ use crate::{
file_utils::get_writer, file_utils::get_writer,
paths::{get_data_dir, get_ipc_file_path, BWRAP_SYSTEM_PREFIX, SYSTEM_PREFIX}, paths::{get_data_dir, BWRAP_SYSTEM_PREFIX, SYSTEM_PREFIX},
xdg::XDG,
}; };
use nix::NixPath; use nix::NixPath;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -40,6 +41,15 @@ impl XRServiceType {
Self::Wivrn => "wivrn/libmonado.so", Self::Wivrn => "wivrn/libmonado.so",
} }
} }
pub fn ipc_file_path(&self) -> PathBuf {
XDG.get_runtime_directory()
.expect("XDG runtime directory is not available")
.join(match self {
XRServiceType::Monado => "monado_comp_ipc",
XRServiceType::Wivrn => "wivrn_comp_ipc",
})
}
} }
impl From<&str> for XRServiceType { impl From<&str> for XRServiceType {
@ -354,7 +364,7 @@ impl Profile {
self.xr_runtime_json_env_var(), self.xr_runtime_json_env_var(),
format!( format!(
"PRESSURE_VESSEL_FILESYSTEMS_RW=\"{path}\"", "PRESSURE_VESSEL_FILESYSTEMS_RW=\"{path}\"",
path = get_ipc_file_path(&self.xrservice_type).to_string_lossy(), path = self.xrservice_type.ipc_file_path().to_string_lossy(),
), ),
] ]
} }

View file

@ -41,7 +41,7 @@ use crate::{
is_appimage::IS_APPIMAGE, is_appimage::IS_APPIMAGE,
linux_distro::LinuxDistro, linux_distro::LinuxDistro,
openxr_prober::is_openxr_ready, openxr_prober::is_openxr_ready,
paths::{get_data_dir, get_ipc_file_path}, paths::get_data_dir,
profile::{Profile, XRServiceType}, profile::{Profile, XRServiceType},
stateless_action, stateless_action,
steam_linux_runtime_injector::{ steam_linux_runtime_injector::{
@ -175,7 +175,7 @@ impl App {
self.debug_view.sender().emit(DebugViewMsg::ClearLog); self.debug_view.sender().emit(DebugViewMsg::ClearLog);
self.xr_devices = vec![]; self.xr_devices = vec![];
if prof.can_start() { if prof.can_start() {
remove_file(get_ipc_file_path(&prof.xrservice_type)) remove_file(prof.xrservice_type.ipc_file_path())
.is_err() .is_err()
.then(|| println!("Failed to remove xrservice IPC file")); .then(|| println!("Failed to remove xrservice IPC file"));
let worker = JobWorker::xrservice_worker_wrap_from_profile( let worker = JobWorker::xrservice_worker_wrap_from_profile(