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
19 changes: 15 additions & 4 deletions winapps-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::Command;
use winapps::RemoteClient;
use clap::{arg, Command};
use winapps::freerdp::freerdp_back::Freerdp;
use winapps::RemoteClient;

fn cli() -> Command {
Command::new("winapps-cli")
Expand All @@ -10,13 +10,18 @@ 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")),
Fixed Show fixed Hide fixed
)
}

fn main() {
let cli = cli();
let matches = cli.clone().get_matches();

let client: &dyn RemoteClient = &Freerdp{};
let client: &dyn RemoteClient = &Freerdp {};

match matches.subcommand() {
Some(("check", _)) => {
Expand All @@ -29,7 +34,13 @@ fn main() {
println!("Connecting to remote");

let config = winapps::load_config(None);
client.run_app(config, "explorer");
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
52 changes: 44 additions & 8 deletions winapps/src/freerdp.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,60 @@
pub mod freerdp_back {
use std::process::{Command, Stdio};

use crate::{RemoteClient, Config};
use crate::{Config, RemoteClient};

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.args(["-h"]);
xfreerdp.spawn().expect("Freerdp execution failed! It needs to be installed!");
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!");

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");
match app {
Some(exe) => {
xfreerdp.args([
&format!("/app:{}", exe),
"-wallpaper",
LDprg marked this conversation as resolved.
Show resolved Hide resolved
&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 @@ -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 All @@ -31,13 +31,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