Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add freerdp backend #42

Merged
merged 11 commits into from
Oct 9, 2023
Merged
18 changes: 15 additions & 3 deletions winapps-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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> "App to open")),
Fixed Show fixed Hide fixed
)
.subcommand(
Command::new("vm")
.about("Manage a windows 10 vm using quickemu")
Expand All @@ -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::<String>("APP"));
}

Some(("vm", command)) => {
Expand Down
45 changes: 41 additions & 4 deletions winapps/src/freerdp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
}
}
8 changes: 4 additions & 4 deletions winapps/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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,
}

Expand Down