diff --git a/winapps-cli/src/main.rs b/winapps-cli/src/main.rs index d880054..3887292 100644 --- a/winapps-cli/src/main.rs +++ b/winapps-cli/src/main.rs @@ -1,4 +1,4 @@ -use clap::Command; +use clap::{arg, Command}; use winapps::freerdp::freerdp_back::Freerdp; use winapps::quickemu::{create_vm, kill_vm, start_vm}; use winapps::RemoteClient; @@ -11,6 +11,11 @@ fn cli() -> Command { .allow_external_subcommands(true) .subcommand(Command::new("check").about("Checks remote connection")) .subcommand(Command::new("connect").about("Connects to remote")) + .subcommand( + Command::new("run") + .about("Connects to app on remote") + .arg(arg!( "App to open")), + ) .subcommand( Command::new("vm") .about("Manage a windows 10 vm using quickemu") @@ -27,17 +32,24 @@ fn main() { let cli = cli(); let matches = cli.clone().get_matches(); - let config = winapps::load_config(None); let client: &dyn RemoteClient = &Freerdp {}; + let config = winapps::load_config(None); match matches.subcommand() { Some(("check", _)) => { println!("Checking remote connection"); + client.check_depends(config); } Some(("connect", _)) => { println!("Connecting to remote"); - client.run_app(config, "explorer"); + + client.run_app(config, None); + } + Some(("run", sub_matches)) => { + println!("Connecting to app on remote"); + + client.run_app(config, sub_matches.get_one::("APP")); } Some(("vm", command)) => { diff --git a/winapps/src/freerdp.rs b/winapps/src/freerdp.rs index 8da682a..cf7baa4 100644 --- a/winapps/src/freerdp.rs +++ b/winapps/src/freerdp.rs @@ -6,20 +6,57 @@ pub mod freerdp_back { pub struct Freerdp {} impl RemoteClient for Freerdp { - fn check_depends(&self, _config: Config) { + fn check_depends(&self, config: Config) { let mut xfreerdp = Command::new("xfreerdp"); xfreerdp.stdout(Stdio::null()); + xfreerdp.stderr(Stdio::null()); xfreerdp.args(["-h"]); xfreerdp .spawn() .expect("Freerdp execution failed! It needs to be installed!"); println!("Freerdp found!"); - println!("Checks success!"); + println!("All dependencies found!"); + println!("Running explorer as test!"); + println!("Check yourself if it appears correctly!"); + + self.run_app(config, Some(&"explorer.exe".to_string())); + + println!("Test finished!"); } - fn run_app(&self, _config: Config, _app: &str) { - todo!() + fn run_app(&self, config: Config, app: Option<&String>) { + let mut xfreerdp = Command::new("xfreerdp"); + xfreerdp.stdout(Stdio::null()); + xfreerdp.stderr(Stdio::null()); + match app { + Some(exe) => { + xfreerdp.args([ + &format!("/app:{}", exe), + &format!("/d:{}", &config.rdp.domain), + &format!("/u:{}", &config.rdp.username), + &format!("/p:{}", &config.rdp.password), + &format!("/v:{}", &config.rdp.host), + "/dynamic-resolution", + "+auto-reconnect", + "+clipboard", + "+home-drive", + ]); + } + None => { + xfreerdp.args([ + &format!("/d:{}", &config.rdp.domain), + &format!("/u:{}", &config.rdp.username), + &format!("/p:{}", &config.rdp.password), + &format!("/v:{}", &config.rdp.host), + "/dynamic-resolution", + "+auto-reconnect", + "+clipboard", + "+home-drive", + ]); + } + } + xfreerdp.spawn().expect("Freerdp execution failed!"); } } } diff --git a/winapps/src/lib.rs b/winapps/src/lib.rs index 41347d6..8c5a265 100644 --- a/winapps/src/lib.rs +++ b/winapps/src/lib.rs @@ -16,7 +16,7 @@ pub mod freerdp; pub trait RemoteClient { fn check_depends(&self, config: Config); - fn run_app(&self, config: Config, app: &str); + fn run_app(&self, config: Config, app: Option<&String>); } #[derive(new, Debug, Deserialize, Serialize)] @@ -45,13 +45,13 @@ pub struct HostConfig { #[derive(new, Debug, Deserialize, Serialize)] pub struct RemoteConfig { - #[new(value = "\"RDPWindows\".to_string()")] + #[new(value = "\"127.0.0.1\".to_string()")] host: String, #[new(value = "\"WORKGROUP\".to_string()")] domain: String, - #[new(value = "\"RDPUser\".to_string()")] + #[new(value = "\"Quickemu\".to_string()")] username: String, - #[new(value = "\"RDPPass\".to_string()")] + #[new(value = "\"quickemu\".to_string()")] password: String, }