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 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 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 diff --git a/scripts/install_quickemu b/scripts/install_quickemu index 582a2a1..84fe732 100644 --- a/scripts/install_quickemu +++ b/scripts/install_quickemu @@ -9,8 +9,8 @@ import sys def clone_repo(): print("📦 Cloning quickemu...") - print("> git clone --filter=blob:none https://github.com/wimpysworld/quickemu /tmp/quickemu") - os.system("git clone --filter=blob:none https://github.com/wimpysworld/quickemu /tmp/quickemu") + print("> git clone --filter=blob:none https://github.com/quickemu-project/quickemu /tmp/quickemu") + os.system("git clone --filter=blob:none https://github.com/quickemu-project/quickemu /tmp/quickemu") print("> mkdir -p ~/.local/bin") os.system("mkdir -p ~/.local/bin") diff --git a/winapps-cli/src/main.rs b/winapps-cli/src/main.rs index 98e3d63..d77149f 100644 --- a/winapps-cli/src/main.rs +++ b/winapps-cli/src/main.rs @@ -1,5 +1,7 @@ use clap::Command; +use winapps::freerdp::freerdp_back::Freerdp; use winapps::quickemu::{create_vm, run_vm}; +use winapps::RemoteClient; fn cli() -> Command { Command::new("winapps-cli") @@ -17,14 +19,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(("create-vm", _)) => { println!("Creating windows 10 vm.."); diff --git a/winapps/src/freerdp.rs b/winapps/src/freerdp.rs new file mode 100644 index 0000000..8da682a --- /dev/null +++ b/winapps/src/freerdp.rs @@ -0,0 +1,25 @@ +pub mod freerdp_back { + use std::process::{Command, Stdio}; + + use crate::{Config, RemoteClient}; + + pub struct Freerdp {} + + impl RemoteClient for Freerdp { + 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 run_app(&self, _config: Config, _app: &str) { + todo!() + } + } +} diff --git a/winapps/src/lib.rs b/winapps/src/lib.rs index 9ed98cc..6be8f55 100644 --- a/winapps/src/lib.rs +++ b/winapps/src/lib.rs @@ -1,14 +1,22 @@ pub mod quickemu; use derive_new::new; -use home::home_dir; use serde::{Deserialize, Serialize}; use std::io::Write; use std::{ + env, fs::{self, File}, path::Path, }; +pub mod freerdp; + +pub trait RemoteClient { + fn check_depends(&self, config: Config); + + fn run_app(&self, config: Config, app: &str); +} + #[derive(new, Debug, Deserialize, Serialize)] pub struct Config { #[new(value = "HostConfig::new()")] @@ -35,19 +43,9 @@ 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/"); + 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(); diff --git a/winapps/src/quickemu.rs b/winapps/src/quickemu.rs index e5a534a..770235c 100644 --- a/winapps/src/quickemu.rs +++ b/winapps/src/quickemu.rs @@ -1,11 +1,19 @@ use home::home_dir; +use std::env; use std::path::PathBuf; use std::process::exit; use std::process::Command; -pub(crate) fn get_data_dir() -> PathBuf { +pub fn get_data_dir() -> PathBuf { let home = home_dir().expect("Could not find the home path!"); - let data_dir = home.join(".local/share/winapps"); + + let data_dir = match env::var("XDG_DATA_HOME") { + Ok(dir) => PathBuf::from(dir).join("winapps"), + Err(_) => { + println!("Couldn't read XDG_DATA_HOME, falling back to ~/.local/share"); + home.join(".local/share/winapps") + } + }; if !data_dir.exists() { let dir = data_dir.clone(); @@ -48,8 +56,7 @@ pub fn run_vm() { let output = match Command::new("quickemu") .current_dir(data_dir) - .arg("--vm") - .arg("windows-10-22H2.conf") + .args(["--vm", "windows-10-22H2.conf", "--display", "none"]) .spawn() .unwrap() .wait_with_output()