fix: merge with upstream/rewrite

This commit is contained in:
Oskar Manhart
2023-09-12 15:17:10 +02:00
8 changed files with 64 additions and 40 deletions

25
winapps/src/freerdp.rs Normal file
View File

@@ -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!()
}
}
}

View File

@@ -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();

View File

@@ -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()