diff --git a/src/main.rs b/src/main.rs index ab1de2d..43679c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,6 +54,10 @@ struct CliArgs { #[clap(id = "PRIORITY", short = 'o', long = "overlay", action)] overlay_priority: Option, + /// Debug the clients started by the server + #[clap(short = 'd', long = "debug", action)] + debug_launched_clients: bool, + /// Run a script when ready for clients to connect. If this is not set the script at $HOME/.config/stardust/startup will be ran if it exists. #[clap(id = "PATH", short = 'e', long = "execute-startup-script", action)] startup_script: Option, diff --git a/src/session.rs b/src/session.rs index 29e52bb..8fef44d 100644 --- a/src/session.rs +++ b/src/session.rs @@ -37,17 +37,22 @@ pub async fn save_session(project_dirs: &ProjectDirs) { pub fn launch_start(cli_args: &CliArgs, project_dirs: &ProjectDirs) -> Vec { match (&cli_args.restore, &cli_args.startup_script) { - (Some(session_id), _) => { - restore_session(&project_dirs.state_dir().unwrap().join(session_id)) - } - (None, Some(startup_script)) => { - run_script(&startup_script.clone().canonicalize().unwrap_or_default()) - } - (None, None) => run_script(&project_dirs.config_dir().join("startup")), + (Some(session_id), _) => restore_session( + &project_dirs.state_dir().unwrap().join(session_id), + cli_args.debug_launched_clients, + ), + (None, Some(startup_script)) => run_script( + &startup_script.clone().canonicalize().unwrap_or_default(), + cli_args.debug_launched_clients, + ), + (None, None) => run_script( + &project_dirs.config_dir().join("startup"), + cli_args.debug_launched_clients, + ), } } -pub fn restore_session(session_dir: &Path) -> Vec { +pub fn restore_session(session_dir: &Path, debug_launched_clients: bool) -> Vec { let Ok(clients) = session_dir.read_dir() else { return Vec::new(); }; @@ -55,22 +60,24 @@ pub fn restore_session(session_dir: &Path) -> Vec { .filter_map(Result::ok) .filter_map(|c| ClientStateParsed::from_file(&c.path())) .filter_map(ClientStateParsed::launch_command) - .filter_map(run_client) + .filter_map(|c| run_client(c, debug_launched_clients)) .collect() } -pub fn run_script(script_path: &Path) -> Vec { +pub fn run_script(script_path: &Path, debug_launched_clients: bool) -> Vec { let _ = std::fs::set_permissions(script_path, std::fs::Permissions::from_mode(0o755)); let startup_command = Command::new(script_path); - run_client(startup_command) + run_client(startup_command, debug_launched_clients) .map(|c| vec![c]) .unwrap_or_default() } -pub fn run_client(mut command: Command) -> Option { +pub fn run_client(mut command: Command, debug_launched_clients: bool) -> Option { command.stdin(Stdio::null()); - command.stdout(Stdio::null()); - command.stderr(Stdio::null()); + if !debug_launched_clients { + command.stdout(Stdio::null()); + command.stderr(Stdio::null()); + } for (var, value) in connection_env() { command.env(var, value); }