finish setting up launch functionality
This commit is contained in:
parent
8324b8f62f
commit
b7951cbcc2
1 changed files with 21 additions and 8 deletions
|
@ -1,19 +1,32 @@
|
||||||
use std::collections::HashMap;
|
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<String, Programs>, program_arg: &String) -> Result<String,ErrorMessage> {
|
pub fn append_arguments(mut command: String, args: Vec<String>) -> String {
|
||||||
|
for a in args {
|
||||||
|
command = format!("{} {}",command,a);
|
||||||
|
}
|
||||||
|
command
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn profile_launch(profiles: Vec<Profile>, programs_config: HashMap<String, Programs>, program_arg: &String) -> Result<String,ErrorMessage> {
|
||||||
match programs_config.iter().find(|x|x.0.eq(program_arg)) {
|
match programs_config.iter().find(|x|x.0.eq(program_arg)) {
|
||||||
Some(p) => {
|
Some(p) => {
|
||||||
println!("{:?}",p);
|
|
||||||
let mut swaymsg_command = format!("exec {}", p.1.command);
|
let mut swaymsg_command = format!("exec {}", p.1.command);
|
||||||
for a in &p.1.arguments {
|
swaymsg_command = append_arguments(swaymsg_command, p.1.arguments.clone());
|
||||||
swaymsg_command = format!("{} {}",swaymsg_command,a);
|
match active_profile(profiles) {
|
||||||
}
|
Ok(profile) => {
|
||||||
Ok(swaymsg_command)
|
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 => {
|
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) })
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue