From b7951cbcc2474be3532c590f116ebababba56adb Mon Sep 17 00:00:00 2001 From: Penelope Gwen Date: Sun, 21 Sep 2025 01:27:23 -0700 Subject: [PATCH] finish setting up launch functionality --- src/lib/launch.rs | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/lib/launch.rs b/src/lib/launch.rs index 51505a8..521ea19 100644 --- a/src/lib/launch.rs +++ b/src/lib/launch.rs @@ -1,19 +1,32 @@ use std::collections::HashMap; -use crate::{config::Programs, ErrorMessage}; +use crate::{config::{Profile, Programs}, profile::active_profile, ErrorMessage}; -pub fn profile_launch(programs_config: HashMap, program_arg: &String) -> Result { +pub fn append_arguments(mut command: String, args: Vec) -> String { + for a in args { + command = format!("{} {}",command,a); + } + command +} + +pub fn profile_launch(profiles: Vec, programs_config: HashMap, program_arg: &String) -> Result { match programs_config.iter().find(|x|x.0.eq(program_arg)) { Some(p) => { - println!("{:?}",p); let mut swaymsg_command = format!("exec {}", p.1.command); - for a in &p.1.arguments { - swaymsg_command = format!("{} {}",swaymsg_command,a); - } - Ok(swaymsg_command) + swaymsg_command = append_arguments(swaymsg_command, p.1.arguments.clone()); + match active_profile(profiles) { + Ok(profile) => { + println!("{:#?}",profile); + if let Some(profile_args) = profile.program_args.unwrap_or_default().iter().find(|x|x.0.eq(p.0)) { + swaymsg_command = append_arguments(swaymsg_command, profile_args.1.to_owned()); + } + Ok(swaymsg_command) + }, + Err(e) => Err(e), + } }, None => { - Err(ErrorMessage { message: Some(String::from("no matching program found")), code: Some(3) }) + Err(ErrorMessage { message: Some(String::from("No matching program found")), code: Some(3) }) }, } } \ No newline at end of file