From 65cdddbb98d3711c4a4b3f21db0d740f0021dc13 Mon Sep 17 00:00:00 2001 From: Gabriele Musco Date: Sun, 1 Sep 2024 19:28:44 +0200 Subject: [PATCH] chore: move ipc file path function to XRServiceType --- src/paths.rs | 11 +---------- src/profile.rs | 14 ++++++++++++-- src/ui/app.rs | 4 ++-- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/paths.rs b/src/paths.rs index 5308b36..06b7575 100644 --- a/src/paths.rs +++ b/src/paths.rs @@ -1,4 +1,4 @@ -use crate::{constants::CMD_NAME, profile::XRServiceType, xdg::XDG}; +use crate::{constants::CMD_NAME, xdg::XDG}; use std::{ env, fs::create_dir_all, @@ -83,15 +83,6 @@ pub fn get_exec_prefix() -> PathBuf { .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 { XDG.get_data_home() .join("Steam/steamapps/common/SteamVR/bin/linux64") diff --git a/src/profile.rs b/src/profile.rs index 77e88f6..127549d 100644 --- a/src/profile.rs +++ b/src/profile.rs @@ -1,6 +1,7 @@ use crate::{ 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 serde::{Deserialize, Serialize}; @@ -40,6 +41,15 @@ impl XRServiceType { 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 { @@ -354,7 +364,7 @@ impl Profile { self.xr_runtime_json_env_var(), format!( "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(), ), ] } diff --git a/src/ui/app.rs b/src/ui/app.rs index e0e0494..46e77b4 100644 --- a/src/ui/app.rs +++ b/src/ui/app.rs @@ -41,7 +41,7 @@ use crate::{ is_appimage::IS_APPIMAGE, linux_distro::LinuxDistro, openxr_prober::is_openxr_ready, - paths::{get_data_dir, get_ipc_file_path}, + paths::get_data_dir, profile::{Profile, XRServiceType}, stateless_action, steam_linux_runtime_injector::{ @@ -175,7 +175,7 @@ impl App { self.debug_view.sender().emit(DebugViewMsg::ClearLog); self.xr_devices = vec![]; if prof.can_start() { - remove_file(get_ipc_file_path(&prof.xrservice_type)) + remove_file(prof.xrservice_type.ipc_file_path()) .is_err() .then(|| println!("Failed to remove xrservice IPC file")); let worker = JobWorker::xrservice_worker_wrap_from_profile(