From 0435e9f45e8f97137c739458419cc40c3aea8910 Mon Sep 17 00:00:00 2001 From: LDprg Date: Fri, 14 Jul 2023 17:31:23 +0200 Subject: [PATCH 1/8] fmt --- winapps-cli/src/main.rs | 2 +- winapps/src/lib.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/winapps-cli/src/main.rs b/winapps-cli/src/main.rs index fd58b79..61ca1ec 100644 --- a/winapps-cli/src/main.rs +++ b/winapps-cli/src/main.rs @@ -12,7 +12,7 @@ fn cli() -> Command { fn main() { let cli = cli(); - let matches = cli.clone( ).get_matches(); + let matches = cli.clone().get_matches(); match matches.subcommand() { Some(("check", _)) => { diff --git a/winapps/src/lib.rs b/winapps/src/lib.rs index 0440855..8e6937b 100644 --- a/winapps/src/lib.rs +++ b/winapps/src/lib.rs @@ -60,12 +60,14 @@ pub fn load_config(path: Option<&str>) -> Config { let mut config_file = File::create(&config_file).expect("Failed to create configuration file"); - let gen_config = toml::to_string(&config).expect("Failed to generate default configuration"); + let gen_config = + toml::to_string(&config).expect("Failed to generate default configuration"); write!(config_file, "{}", gen_config).expect("Failed to write configuration file"); } let config_file = fs::read_to_string(config_file).expect("Failed to read configuration file"); - let config: Config = toml::from_str(config_file.as_str()).expect("Failed to parse the configuration"); + let config: Config = + toml::from_str(config_file.as_str()).expect("Failed to parse the configuration"); config } From 2cb24fabe586ae7320123cd63c22a2a6c1c5cce3 Mon Sep 17 00:00:00 2001 From: LDprg Date: Thu, 20 Jul 2023 13:25:57 +0200 Subject: [PATCH 2/8] add freerdp crate --- winapps/src/freerdp.rs | 19 +++++++++++++++++++ winapps/src/lib.rs | 20 ++++++++++---------- 2 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 winapps/src/freerdp.rs diff --git a/winapps/src/freerdp.rs b/winapps/src/freerdp.rs new file mode 100644 index 0000000..ccc7888 --- /dev/null +++ b/winapps/src/freerdp.rs @@ -0,0 +1,19 @@ +pub mod freerdp { + use crate::RemoteClient; + + struct Freerdp {} + + impl RemoteClient for Freerdp { + fn check_depends(&self) { + todo!() + } + + fn load_config(&self, path: &str) { + todo!() + } + + fn run_app(&self, app: &str) { + todo!() + } + } +} \ No newline at end of file diff --git a/winapps/src/lib.rs b/winapps/src/lib.rs index 8e6937b..e178c9d 100644 --- a/winapps/src/lib.rs +++ b/winapps/src/lib.rs @@ -7,6 +7,16 @@ use std::{ path::Path, }; +mod freerdp; + +pub trait RemoteClient { + fn check_depends(&self); + + fn load_config(&self, path: &str); + + fn run_app(&self, app: &str); +} + #[derive(new, Debug, Deserialize, Serialize)] pub struct Config { #[new(value = "HostConfig::new()")] @@ -33,16 +43,6 @@ pub struct RemoteConfig { password: String, } -pub trait RemoteClient { - fn check_depends(&self) -> bool { - panic!("Dependency check not implemented!"); - } - - fn load_config(&self, path: &str); - - fn run_app(&self, app: &str); -} - pub fn load_config(path: Option<&str>) -> Config { let home = home_dir().expect("Could not find the home path!"); let default = &format!("{}{}", home.to_str().unwrap(), "/.config/winapps/"); From 4d380f2e1859fde169388f2c89bb571eeb06e977 Mon Sep 17 00:00:00 2001 From: Oskar Manhart <52569953+oskardotglobal@users.noreply.github.com> Date: Thu, 27 Jul 2023 11:54:02 +0200 Subject: [PATCH 3/8] fix: skip clippy and rust-check for ci pre-commit.ci has no network connection per design, so now pre-commit ci only enforces styling --- .pre-commit-config.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8a28bb1..23a7ce7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,6 @@ +ci: + skip: [clippy, cargo-check] + repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.4.0 From ce607143e6066f78d45976ba8f845149588b64e2 Mon Sep 17 00:00:00 2001 From: Oskar Manhart <52569953+oskardotglobal@users.noreply.github.com> Date: Thu, 27 Jul 2023 11:54:18 +0200 Subject: [PATCH 4/8] rm: remove rust-check.yml Other workflows already run the same checks, so it's unnecessary --- .github/workflows/rust-check.yml | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 .github/workflows/rust-check.yml diff --git a/.github/workflows/rust-check.yml b/.github/workflows/rust-check.yml deleted file mode 100644 index f3d3a03..0000000 --- a/.github/workflows/rust-check.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Rust Check - -on: - push: - branches: [ "rewrite" ] - pull_request: - branches: [ "rewrite" ] - -env: - CARGO_TERM_COLOR: always - -jobs: - format: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - uses: mirlahiji/rust-action@master - with: - args: cargo fmt -- --check && cargo clippy -- -Dwarnings && cargo test From 6c071a35c5e32d5c006dc5b24e6b615d5869f0ec Mon Sep 17 00:00:00 2001 From: Oskar Manhart <52569953+oskardotglobal@users.noreply.github.com> Date: Thu, 27 Jul 2023 11:54:43 +0200 Subject: [PATCH 5/8] fix: enable env colors for rust-clippy.yml --- .github/workflows/rust-clippy.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/rust-clippy.yml b/.github/workflows/rust-clippy.yml index 33a01d1..b77be5c 100644 --- a/.github/workflows/rust-clippy.yml +++ b/.github/workflows/rust-clippy.yml @@ -18,6 +18,9 @@ on: schedule: - cron: '23 2 * * 5' +env: + CARGO_TERM_COLOR: always + jobs: rust-clippy-analyze: name: Run rust-clippy analyzing From 6cd338b85be988c9b2b3ac4919d902a76f98b92a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 30 Jul 2023 10:05:30 +0000 Subject: [PATCH 6/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- winapps/src/freerdp.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winapps/src/freerdp.rs b/winapps/src/freerdp.rs index ccc7888..2e34700 100644 --- a/winapps/src/freerdp.rs +++ b/winapps/src/freerdp.rs @@ -16,4 +16,4 @@ pub mod freerdp { todo!() } } -} \ No newline at end of file +} From d8bffd817d112137b0a54c92c8078ee3e3e60912 Mon Sep 17 00:00:00 2001 From: LDprg Date: Sun, 30 Jul 2023 12:13:19 +0200 Subject: [PATCH 7/8] fix clippy and add precommit --- winapps/src/freerdp.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/winapps/src/freerdp.rs b/winapps/src/freerdp.rs index 2e34700..8ad0c5f 100644 --- a/winapps/src/freerdp.rs +++ b/winapps/src/freerdp.rs @@ -1,4 +1,4 @@ -pub mod freerdp { +pub mod freerdp_back { use crate::RemoteClient; struct Freerdp {} @@ -8,11 +8,11 @@ pub mod freerdp { todo!() } - fn load_config(&self, path: &str) { + fn load_config(&self, _path: &str) { todo!() } - fn run_app(&self, app: &str) { + fn run_app(&self, _app: &str) { todo!() } } From cd5c0f146cf010c9bf58e2960030bd6669a2d672 Mon Sep 17 00:00:00 2001 From: LDprg Date: Sun, 10 Sep 2023 20:07:03 +0200 Subject: [PATCH 8/8] Add freerdp detection --- winapps-cli/src/main.rs | 10 +++++++++- winapps/Cargo.toml | 1 - winapps/src/freerdp.rs | 23 ++++++++++++++--------- winapps/src/lib.rs | 14 ++++++-------- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/winapps-cli/src/main.rs b/winapps-cli/src/main.rs index a7af7dd..b82f71d 100644 --- a/winapps-cli/src/main.rs +++ b/winapps-cli/src/main.rs @@ -1,4 +1,6 @@ use clap::Command; +use winapps::RemoteClient; +use winapps::freerdp::freerdp_back::Freerdp; fn cli() -> Command { Command::new("winapps-cli") @@ -14,14 +16,20 @@ fn main() { let cli = cli(); let matches = cli.clone().get_matches(); + let client: &dyn RemoteClient = &Freerdp{}; + match matches.subcommand() { Some(("check", _)) => { println!("Checking remote connection"); - let _config = winapps::load_config(None); + let config = winapps::load_config(None); + client.check_depends(config); } Some(("connect", _)) => { println!("Connecting to remote"); + + let config = winapps::load_config(None); + client.run_app(config, "explorer"); } Some((_, _)) => { cli.about("Command not found, try existing ones!") diff --git a/winapps/Cargo.toml b/winapps/Cargo.toml index abd213a..629eb36 100644 --- a/winapps/Cargo.toml +++ b/winapps/Cargo.toml @@ -7,6 +7,5 @@ edition = "2021" [dependencies] derive-new = "0.5.9" -home = "0.5.5" serde = { version = "1.0.171", features = ["derive"] } toml = "0.7.6" diff --git a/winapps/src/freerdp.rs b/winapps/src/freerdp.rs index 8ad0c5f..1150320 100644 --- a/winapps/src/freerdp.rs +++ b/winapps/src/freerdp.rs @@ -1,18 +1,23 @@ pub mod freerdp_back { - use crate::RemoteClient; + use std::process::{Command, Stdio}; - struct Freerdp {} + use crate::{RemoteClient, Config}; + + pub struct Freerdp {} impl RemoteClient for Freerdp { - fn check_depends(&self) { - todo!() + 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!"); + println!("Freerdp found!"); + + println!("Checks success!"); } - fn load_config(&self, _path: &str) { - todo!() - } - - fn run_app(&self, _app: &str) { + fn run_app(&self, config: Config, _app: &str) { todo!() } } diff --git a/winapps/src/lib.rs b/winapps/src/lib.rs index e178c9d..9d17961 100644 --- a/winapps/src/lib.rs +++ b/winapps/src/lib.rs @@ -1,20 +1,18 @@ use derive_new::new; -use home::home_dir; use serde::{Deserialize, Serialize}; use std::io::Write; use std::{ + env, fs::{self, File}, path::Path, }; -mod freerdp; +pub mod freerdp; pub trait RemoteClient { - fn check_depends(&self); + fn check_depends(&self, config: Config); - fn load_config(&self, path: &str); - - fn run_app(&self, app: &str); + fn run_app(&self, config: Config, app: &str); } #[derive(new, Debug, Deserialize, Serialize)] @@ -44,8 +42,8 @@ pub struct RemoteConfig { } pub fn load_config(path: Option<&str>) -> Config { - let home = home_dir().expect("Could not find the home path!"); - let default = &format!("{}{}", home.to_str().unwrap(), "/.config/winapps/"); + let config = env::var("XDG_CONFIG_HOME").expect("Could not find the home path!"); + let default = &format!("{}{}", config, "/winapps/"); let path = Path::new(path.unwrap_or(default)); let config = Config::new();