feat: add a debug option to copy profile env vars (#101)

This commit is contained in:
Gabriele Musco 2024-07-20 11:23:32 +02:00
parent 6cf5e40b96
commit 193505a067
3 changed files with 44 additions and 22 deletions

View file

@ -288,33 +288,42 @@ impl Default for Profile {
}
impl Profile {
pub fn xr_runtime_json_env_var(&self) -> String {
format!(
"XR_RUNTIME_JSON=\"{prefix}/share/openxr/1/openxr_{runtime}.json\"",
prefix = match self.prefix.as_str() {
SYSTEM_PREFIX => BWRAP_SYSTEM_PREFIX,
other => other,
},
runtime = match self.xrservice_type {
XRServiceType::Monado => "monado",
XRServiceType::Wivrn => "wivrn",
}
)
}
/// always adds the xr runtime json var
pub fn env_vars_full(&self) -> Vec<String> {
vec![
// format!(
// "VR_OVERRIDE={opencomp}/build",
// opencomp = self.opencomposite_path,
// ),
self.xr_runtime_json_env_var(),
format!(
"PRESSURE_VESSEL_FILESYSTEMS_RW=\"{path}\"",
path = get_ipc_file_path(&self.xrservice_type),
),
]
}
pub fn get_env_vars(&self) -> Vec<String> {
if self.can_be_built {
return vec![
"PRESSURE_VESSEL_FILESYSTEMS_RW=\"$XDG_RUNTIME_DIR/wivrn_comp_ipc:$XDG_RUNTIME_DIR/monado_comp_ipc\"".into(),
];
}
vec![
// format!(
// "VR_OVERRIDE={opencomp}/build",
// opencomp = self.opencomposite_path,
// ),
format!(
"XR_RUNTIME_JSON=\"{prefix}/share/openxr/1/openxr_{runtime}.json\"",
prefix = match self.prefix.as_str() {
SYSTEM_PREFIX => BWRAP_SYSTEM_PREFIX,
other => other,
},
runtime = match self.xrservice_type {
XRServiceType::Monado => "monado",
XRServiceType::Wivrn => "wivrn",
}
),
format!(
"PRESSURE_VESSEL_FILESYSTEMS_RW=\"{path}\"",
path = get_ipc_file_path(&self.xrservice_type),
),
]
self.env_vars_full()
}
pub fn get_steam_launch_options(&self) -> String {

View file

@ -130,6 +130,7 @@ pub enum Msg {
Quit,
DebugOpenPrefix,
DebugOpenData,
DebugCopyEnvVars,
OpenWivrnConfig,
HandleCommandLine(CmdLineOpts),
}
@ -684,6 +685,9 @@ impl SimpleComponent for App {
self.get_selected_profile().prefix
));
}
Msg::DebugCopyEnvVars => {
copy_text(&self.get_selected_profile().env_vars_full().join(" "));
}
Msg::OpenWivrnConfig => {
let editor = WivrnConfEditor::builder()
.launch(WivrnConfEditorInit {
@ -845,6 +849,13 @@ impl SimpleComponent for App {
sender.input(Msg::DebugOpenPrefix);
})
);
stateless_action!(
actions,
DebugCopyEnvVarsAction,
clone!(@strong sender => move |_| {
sender.input(Msg::DebugCopyEnvVars);
})
);
actions.add_action(RelmAction::<DebugViewToggleAction>::new_stateful(
&model.enable_debug_view,
clone!(@strong sender => move |_, state| {
@ -891,3 +902,4 @@ new_stateful_action!(pub DebugViewToggleAction, AppActionGroup, "debugviewtoggle
new_stateless_action!(pub DebugOpenDataAction, AppActionGroup, "debugopendata");
new_stateless_action!(pub DebugOpenPrefixAction, AppActionGroup, "debugopenprefix");
new_stateless_action!(pub DebugCopyEnvVarsAction, AppActionGroup, "debugcopyenvvars");

View file

@ -1,7 +1,7 @@
use super::term_widget::TermWidget;
use crate::log_level::LogLevel;
use crate::log_parser::MonadoLog;
use crate::ui::app::{DebugOpenDataAction, DebugOpenPrefixAction};
use crate::ui::app::{DebugCopyEnvVarsAction, DebugOpenDataAction, DebugOpenPrefixAction};
use crate::ui::util::copy_text;
use gtk::glib::clone;
use gtk::prelude::*;
@ -59,6 +59,7 @@ impl SimpleComponent for DebugView {
section! {
"Open _Data Folder" => DebugOpenDataAction,
"Open _Prefix Folder" => DebugOpenPrefixAction,
"Copy Profile _Environment Variables" => DebugCopyEnvVarsAction,
},
}
}