Skip to content

Commit

Permalink
Finish connect and app command
Browse files Browse the repository at this point in the history
  • Loading branch information
LDprg committed Oct 7, 2023
1 parent d80db16 commit dbc5c9a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 17 deletions.
15 changes: 13 additions & 2 deletions winapps-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub(crate) use clap::Command;
use clap::{arg, Command};
use winapps::freerdp::freerdp_back::Freerdp;
use winapps::RemoteClient;

Expand All @@ -10,6 +10,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("app")
.about("Connects to app on remote")
.arg(arg!(<APP> "App to open")),
)
}

fn main() {
Expand All @@ -29,7 +34,13 @@ fn main() {
println!("Connecting to remote");

let config = winapps::load_config(None);
client.run_app(config, "explorer.exe");
client.run_app(config, None);
}
Some(("app", sub_matches)) => {
println!("Connecting to app on remote");

let config = winapps::load_config(None);
client.run_app(config, sub_matches.get_one::<String>("APP"));
}
Some((_, _)) => {
cli.about("Command not found, try existing ones!")
Expand Down
44 changes: 30 additions & 14 deletions winapps/src/freerdp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,41 @@ pub mod freerdp_back {
println!("All dependencies found!");
println!("Running explorer as test!");

self.run_app(config, "explorer.exe");
self.run_app(config, Some(&"explorer.exe".to_string()));

println!("Test finished!");
}

fn run_app(&self, config: Config, app: &str) {
fn run_app(&self, config: Config, app: Option<&String>) {
let mut xfreerdp = Command::new("xfreerdp");
xfreerdp.args([
"/app:".to_owned() + app,
"/d:".to_owned() + &config.rdp.domain,
"/u:".to_owned() + &config.rdp.username,
"/p:".to_owned() + &config.rdp.password,
"/v:".to_owned() + &config.rdp.host,
"/dynamic-resolution".to_owned(),
"+auto-reconnect".to_owned(),
"+clipboard".to_owned(),
"+home-drive".to_owned(),
"-wallpaper".to_owned(),
]);
match app {
Some(exe) => {
xfreerdp.args([
"/app:".to_owned() + exe,
"-wallpaper".to_owned(),
"/d:".to_owned() + &config.rdp.domain,
"/u:".to_owned() + &config.rdp.username,
"/p:".to_owned() + &config.rdp.password,
"/v:".to_owned() + &config.rdp.host,
"/dynamic-resolution".to_owned(),
"+auto-reconnect".to_owned(),
"+clipboard".to_owned(),
"+home-drive".to_owned(),
]);
}
None => {
xfreerdp.args([
"/d:".to_owned() + &config.rdp.domain,
"/u:".to_owned() + &config.rdp.username,
"/p:".to_owned() + &config.rdp.password,
"/v:".to_owned() + &config.rdp.host,
"/dynamic-resolution".to_owned(),
"+auto-reconnect".to_owned(),
"+clipboard".to_owned(),
"+home-drive".to_owned(),
]);
}
}
xfreerdp.spawn().expect("Freerdp execution failed!");
}
}
Expand Down
2 changes: 1 addition & 1 deletion winapps/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,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)]
Expand Down

0 comments on commit dbc5c9a

Please sign in to comment.