diff --git a/src/stardust_config.rs b/src/stardust_config.rs index 224fa3b..4d7d73c 100644 --- a/src/stardust_config.rs +++ b/src/stardust_config.rs @@ -1,8 +1,17 @@ -use std::{fs::File, io::BufReader}; +use std::{ + fs::File, + io::{BufReader, Write}, + path::Path, +}; -use serde::{Deserialize, Serialize}; +use serde::{ser::Error, Deserialize, Serialize}; -use crate::{constants::CMD_NAME, file_utils::get_writer, paths::get_config_dir}; +use crate::{ + constants::CMD_NAME, + file_builders::monado_autorun::{get_monado_autorun_config, MonadoAutorun}, + file_utils::get_writer, + paths::{get_config_dir, get_stardust_prefix}, +}; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct StardustExternalClient { @@ -62,6 +71,50 @@ impl StardustConfig { } pub fn save(&self) -> Result<(), serde_json::Error> { + // monado autorun + { + let mut monado_config = get_monado_autorun_config(); + let exec = get_stardust_prefix() + "/bin/stardust-xr-server"; + // clear out all the stardust stuff in the autorun + monado_config.autoruns = monado_config + .autoruns + .iter() + .filter(|c| !c.exec.ends_with("stardust-xr-server")) + .cloned() + .collect(); + + // and if we have it enabled and can use it, add it back with latest config + if self.autostart && Path::new(&exec).is_file() { + monado_config.autoruns.push(MonadoAutorun { + exec, + args: { + let mut args = vec![]; + if self.disable_controller { + args.push("--disable-controller".into()); + } + if self.start_as_overlay { + args.push("-o".into()); + args.push(self.overlay_priority.to_string()); + } + + args + }, + }) + } + } + + // stardust startup script + { + let startup_script_path = get_stardust_prefix() + "/startup_script"; + let _ = std::fs::remove_file(&startup_script_path); + let mut startup_script = + std::fs::File::create(startup_script_path).map_err(serde_json::Error::custom)?; + writeln!(startup_script, "#!/bin/sh").map_err(serde_json::Error::custom)?; + // if self.flatland_enabled + // writeln!(startup_script,).map_err(serde_json::Error::custom)?; + } + + // then write the envision stardust config let writer = get_writer(&Self::file_path()); serde_json::to_writer_pretty(writer, self) }