Bundle WayVR Dashboard into wlx, find wayvr-dashboard executable in AppImage (if exists) (#208) (#210)

Co-authored-by: Aleksander <aleksander@oo8.dev>
This commit is contained in:
galister
2025-05-10 10:03:40 +02:00
committed by GitHub
parent a221734e23
commit eef80eae3a
13 changed files with 147 additions and 36 deletions

View File

@@ -556,6 +556,7 @@ impl Display {
exec_path: &str,
args: &[&str],
env: &[(&str, &str)],
working_dir: Option<&str>,
) -> anyhow::Result<SpawnProcessResult> {
log::info!("Spawning subprocess with exec path \"{exec_path}\"");
@@ -564,6 +565,9 @@ impl Display {
let mut cmd = std::process::Command::new(exec_path);
self.configure_env(&mut cmd, auth_key.as_str());
cmd.args(args);
if let Some(working_dir) = working_dir {
cmd.current_dir(working_dir);
}
for e in env {
cmd.env(e.0, e.1);

View File

@@ -684,6 +684,7 @@ impl WayVRState {
exec_path: &str,
args: &[&str],
env: &[(&str, &str)],
working_dir: Option<&str>,
userdata: HashMap<String, String>,
) -> anyhow::Result<process::ProcessHandle> {
let display = self
@@ -691,7 +692,7 @@ impl WayVRState {
.get_mut(&display_handle)
.ok_or_else(|| anyhow::anyhow!(STR_INVALID_HANDLE_DISP))?;
let res = display.spawn_process(exec_path, args, env)?;
let res = display.spawn_process(exec_path, args, env, working_dir)?;
let handle = self
.processes
@@ -702,6 +703,7 @@ impl WayVRState {
exec_path: String::from(exec_path),
userdata,
args: args.iter().map(|x| String::from(*x)).collect(),
working_dir: working_dir.map(String::from),
env: env
.iter()
.map(|(a, b)| (String::from(*a), String::from(*b)))

View File

@@ -16,6 +16,7 @@ pub struct WayVRProcess {
pub exec_path: String,
pub args: Vec<String>,
pub env: Vec<(String, String)>,
pub working_dir: Option<String>,
pub userdata: HashMap<String, String>,
}

View File

@@ -365,6 +365,7 @@ impl Connection {
&packet_params.exec,
&args_vec,
&env_vec,
None,
packet_params.userdata,
);

View File

@@ -19,7 +19,7 @@ use crate::{
config::load_config_with_conf_d,
config_io,
gui::modular::button::WayVRAction,
overlays::wayvr::WayVRData,
overlays::wayvr::{executable_exists_in_path, WayVRData},
};
// Flat version of RelativeTo
@@ -120,6 +120,7 @@ fn def_blit_method() -> String {
#[derive(Clone, Deserialize, Serialize)]
pub struct WayVRDashboard {
pub exec: String,
pub working_dir: Option<String>,
pub args: Option<String>,
pub env: Option<Vec<String>>,
}
@@ -234,6 +235,21 @@ impl WayVRConfig {
}
}
fn get_default_dashboard_exec() -> (
String, /* exec path */
Option<String>, /* working directory */
) {
if let Ok(appdir) = std::env::var("APPDIR") {
// Running in AppImage
let embedded_path = format!("{appdir}/usr/bin/wayvr-dashboard");
if executable_exists_in_path(&embedded_path) {
log::info!("Using WayVR Dashboard from AppDir: {embedded_path}");
return (embedded_path, Some(format!("{appdir}/usr")));
}
}
(String::from("wayvr-dashboard"), None)
}
pub fn load_wayvr() -> WayVRConfig {
let config_root_path = config_io::ConfigRoot::WayVR.ensure_dir();
log::info!("WayVR Config root path: {}", config_root_path.display());
@@ -242,5 +258,19 @@ pub fn load_wayvr() -> WayVRConfig {
config_io::ConfigRoot::WayVR.get_conf_d_path().display()
);
load_config_with_conf_d::<WayVRConfig>("wayvr.yaml", config_io::ConfigRoot::WayVR)
let mut conf =
load_config_with_conf_d::<WayVRConfig>("wayvr.yaml", config_io::ConfigRoot::WayVR);
if conf.dashboard.is_none() {
let (exec, working_dir) = get_default_dashboard_exec();
conf.dashboard = Some(WayVRDashboard {
args: None,
env: None,
exec,
working_dir,
});
}
conf
}

View File

@@ -249,7 +249,7 @@ fn get_or_create_display_by_name(
Ok(disp_handle)
}
fn executable_exists_in_path(command: &str) -> bool {
pub fn executable_exists_in_path(command: &str) -> bool {
let Ok(path) = std::env::var("PATH") else {
return false; // very unlikely to happen
};
@@ -270,14 +270,9 @@ fn toggle_dashboard<O>(
where
O: Default,
{
let conf_dash = app.session.wayvr_config.dashboard.clone().map_or_else(
|| config_wayvr::WayVRDashboard {
exec: String::from("wayvr-dashboard"),
args: None,
env: None,
},
|conf| conf,
);
let Some(conf_dash) = app.session.wayvr_config.dashboard.clone() else {
anyhow::bail!("Dashboard is not configured");
};
if !wayvr.dashboard_executed && !executable_exists_in_path(&conf_dash.exec) {
anyhow::bail!("Executable \"{}\" not found", &conf_dash.exec);
@@ -317,10 +312,6 @@ where
overlay.state.z_order = Z_ORDER_DASHBOARD;
overlay.state.reset(app, true);
let Some(conf_dash) = &app.session.wayvr_config.dashboard else {
unreachable!(); /* safe, not possible to trigger */
};
overlays.add(overlay);
let args_vec = &conf_dash
@@ -342,6 +333,7 @@ where
&conf_dash.exec,
args_vec,
env_vec,
conf_dash.working_dir.as_deref(),
userdata,
)?;
@@ -879,6 +871,7 @@ where
&app_entry.exec,
args_vec,
env_vec,
None,
HashMap::default(),
)?;